Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't import plugin models in main migrations #25

Merged
merged 1 commit into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def build_media_pattern(base_folder, file_extension):

setup(
name = "django-wiki",
version="0.0.11",
version="0.0.12",
author = "Benjamin Bach",
author_email = "[email protected]",
description = ("A wiki system written for the Django framework."),
Expand Down
22 changes: 22 additions & 0 deletions wiki/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import absolute_import, unicode_literals

from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _


class NotifcationsConfig(AppConfig):
name = 'wiki.plugins.notifications'
verbose_name = _("Wiki notifications")
label = 'wiki_notifications'


class ImagesConfig(AppConfig):
name = 'wiki.plugins.images'
verbose_name = _("Wiki images")
label = 'wiki_images'


class AttachmentsConfig(AppConfig):
name = 'wiki.plugins.attachments'
verbose_name = _("Wiki attachments")
label = 'wiki_attachments'
6 changes: 2 additions & 4 deletions wiki/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

from django.db import models, migrations
import mptt.fields
import wiki.plugins.images.models
import wiki.plugins.attachments.models
from django.conf import settings


Expand Down Expand Up @@ -107,7 +105,7 @@ class Migration(migrations.Migration):
('created', models.DateTimeField(auto_now_add=True)),
('deleted', models.BooleanField(default=False, verbose_name='deleted')),
('locked', models.BooleanField(default=False, verbose_name='locked')),
('file', models.FileField(upload_to=wiki.plugins.attachments.models.upload_path, verbose_name='file')),
('file', models.FileField(upload_to='wiki/uploads/', verbose_name='file')),
('description', models.TextField(blank=True)),
],
options={
Expand Down Expand Up @@ -182,7 +180,7 @@ class Migration(migrations.Migration):
name='ImageRevision',
fields=[
('revisionpluginrevision_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='wiki.RevisionPluginRevision')),
('image', models.ImageField(upload_to=wiki.plugins.images.models.upload_path, width_field=b'width', height_field=b'height', max_length=2000, blank=True, null=True)),
('image', models.ImageField(upload_to='wiki/uploads/', width_field=b'width', height_field=b'height', max_length=2000, blank=True, null=True)),
('width', models.SmallIntegerField(null=True, blank=True)),
('height', models.SmallIntegerField(null=True, blank=True)),
],
Expand Down
55 changes: 55 additions & 0 deletions wiki/migrations/0005_remove_attachments_and_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2017-09-07 19:03
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('wiki', '0004_increase_slug_size'),
]

operations = [
migrations.RemoveField(
model_name='attachment',
name='current_revision',
),
migrations.RemoveField(
model_name='attachment',
name='reusableplugin_ptr',
),
migrations.RemoveField(
model_name='attachmentrevision',
name='attachment',
),
migrations.RemoveField(
model_name='attachmentrevision',
name='previous_revision',
),
migrations.RemoveField(
model_name='attachmentrevision',
name='user',
),
migrations.RemoveField(
model_name='image',
name='revisionplugin_ptr',
),
migrations.RemoveField(
model_name='imagerevision',
name='revisionpluginrevision_ptr',
),
migrations.DeleteModel(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious - do Django's automatically-generated migrations remove each field like this before deleting models?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these were just the foreign keys, removed separately to avoid referential integrity problems when dropping the tables. As I noted in my other reply, this is a fairly tangled pair of models.

name='Attachment',
),
migrations.DeleteModel(
name='AttachmentRevision',
),
migrations.DeleteModel(
name='Image',
),
migrations.DeleteModel(
name='ImageRevision',
),
]
2 changes: 2 additions & 0 deletions wiki/plugins/attachments/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from __future__ import unicode_literals
default_app_config = 'wiki.apps.AttachmentsConfig'
78 changes: 78 additions & 0 deletions wiki/plugins/attachments/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import wiki.plugins.attachments.models
from django.conf import settings


class Migration(migrations.Migration):

dependencies = [
('wiki', '0004_increase_slug_size'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='AttachmentRevision',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('revision_number', models.IntegerField(verbose_name='revision number', editable=False)),
('user_message', models.TextField(blank=True)),
('automatic_log', models.TextField(editable=False, blank=True)),
('ip_address', models.GenericIPAddressField(verbose_name='IP address', null=True, editable=False, blank=True)),
('modified', models.DateTimeField(auto_now=True)),
('created', models.DateTimeField(auto_now_add=True)),
('deleted', models.BooleanField(default=False, verbose_name='deleted')),
('locked', models.BooleanField(default=False, verbose_name='locked')),
('file', models.FileField(upload_to=wiki.plugins.attachments.models.upload_path, verbose_name='file')),
('description', models.TextField(blank=True)),
],
options={
'ordering': ('created',),
'get_latest_by': 'revision_number',
'verbose_name': 'attachment revision',
'verbose_name_plural': 'attachment revisions',
'db_table': 'wiki_attachments_attachmentrevision',
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Attachment',
fields=[
('reusableplugin_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='wiki.ReusablePlugin')),
('original_filename', models.CharField(max_length=256, null=True, verbose_name='original filename', blank=True)),
],
options={
'verbose_name': 'attachment',
'verbose_name_plural': 'attachments',
'db_table': 'wiki_attachments_attachment',
},
bases=('wiki.reusableplugin',),
),
migrations.AddField(
model_name='attachmentrevision',
name='attachment',
field=models.ForeignKey(to='wiki_attachments.Attachment'),
preserve_default=True,
),
migrations.AddField(
model_name='attachmentrevision',
name='previous_revision',
field=models.ForeignKey(blank=True, to='wiki_attachments.AttachmentRevision', null=True),
preserve_default=True,
),
migrations.AddField(
model_name='attachmentrevision',
name='user',
field=models.ForeignKey(verbose_name='user', blank=True, to=settings.AUTH_USER_MODEL, null=True),
preserve_default=True,
),
migrations.AddField(
model_name='attachment',
name='current_revision',
field=models.OneToOneField(related_name='current_set', null=True, to='wiki_attachments.AttachmentRevision', blank=True, help_text='The revision of this attachment currently in use (on all articles using the attachment)', verbose_name='current revision'),
preserve_default=True,
),
]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the separateAddFields after the CreateModels? Is this just several migrations from upstream squashed together?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what was in our original 001_initial migration for the wiki app, copied over verbatim. This was a particularly tricky case because AttachmentRevision has a foreign key to itself, plus it and Attachment have foreign keys to each other. I think Django just erred on the side of caution and added each of the foreign keys individually after creating the tables.

2 changes: 2 additions & 0 deletions wiki/plugins/attachments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def can_delete(self, user):
class Meta:
verbose_name = _(u'attachment')
verbose_name_plural = _(u'attachments')
db_table = 'wiki_attachments_attachment'

def __unicode__(self):
return "%s: %s" % (self.article.current_revision.title, self.original_filename)
Expand Down Expand Up @@ -85,6 +86,7 @@ class Meta:
verbose_name_plural = _(u'attachment revisions')
ordering = ('created',)
get_latest_by = 'revision_number'
db_table = 'wiki_attachments_attachmentrevision'

def get_filename(self):
"""Used to retrieve the filename of a revision.
Expand Down
2 changes: 2 additions & 0 deletions wiki/plugins/images/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from __future__ import unicode_literals
default_app_config = 'wiki.apps.ImagesConfig'
43 changes: 43 additions & 0 deletions wiki/plugins/images/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import wiki.plugins.images.models


class Migration(migrations.Migration):

dependencies = [
('wiki', '0004_increase_slug_size'),
]

operations = [
migrations.CreateModel(
name='Image',
fields=[
('revisionplugin_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='wiki.RevisionPlugin')),
],
options={
'verbose_name': 'image',
'verbose_name_plural': 'images',
'db_table': 'wiki_images_image',
},
bases=('wiki.revisionplugin',),
),
migrations.CreateModel(
name='ImageRevision',
fields=[
('revisionpluginrevision_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='wiki.RevisionPluginRevision')),
('image', models.ImageField(upload_to=wiki.plugins.images.models.upload_path, width_field=b'width', height_field=b'height', max_length=2000, blank=True, null=True)),
('width', models.SmallIntegerField(null=True, blank=True)),
('height', models.SmallIntegerField(null=True, blank=True)),
],
options={
'ordering': ('-created',),
'verbose_name': 'image revision',
'verbose_name_plural': 'image revisions',
'db_table': 'wiki_images_imagerevision',
},
bases=('wiki.revisionpluginrevision',),
),
]
2 changes: 2 additions & 0 deletions wiki/plugins/images/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def can_delete(self, user):
class Meta:
verbose_name = _(u'image')
verbose_name_plural = _(u'images')
db_table = 'wiki_images_image'

def __unicode__(self):
title = (_(u'Image: %s') % self.current_revision.imagerevision.get_filename()) if self.current_revision else _(u'Current revision not set!!')
Expand Down Expand Up @@ -90,6 +91,7 @@ def inherit_predecessor(self, image, skip_image_file=False):
class Meta:
verbose_name = _(u'image revision')
verbose_name_plural = _(u'image revisions')
db_table = 'wiki_images_imagerevision'
ordering = ('-created',)

def __unicode__(self):
Expand Down
3 changes: 3 additions & 0 deletions wiki/plugins/notifications/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
from __future__ import unicode_literals
default_app_config = 'wiki.apps.NotifcationsConfig'

# Key for django_notify
ARTICLE_EDIT = "article_edit"
26 changes: 26 additions & 0 deletions wiki/plugins/notifications/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('wiki', '0004_increase_slug_size'),
('django_notify', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='ArticleSubscription',
fields=[
('subscription_ptr', models.OneToOneField(parent_link=True, auto_created=True, to='django_notify.Subscription')),
('articleplugin_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='wiki.ArticlePlugin')),
],
options={
'db_table': 'wiki_notifications_articlesubscription',
},
bases=('wiki.articleplugin', 'django_notify.subscription'),
),
]
2 changes: 2 additions & 0 deletions wiki/plugins/notifications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def __unicode__(self):
'article': self.article.current_revision.title,
'type': self.notification_type.label})

class Meta:
db_table = 'wiki_notifications_articlesubscription'

def default_url(article, urlpath=None):
try:
Expand Down