Ticket #22170: initial-migrations-contrib.diff

File initial-migrations-contrib.diff, 21.3 KB (added by Andrew Godwin, 11 years ago)

First diff of initial migrations for contrib apps. Lots of test errors (but not in migrations)

  • new file django/contrib/admin/migrations/0001_initial.py

    diff --git a/django/contrib/admin/migrations/0001_initial.py b/django/contrib/admin/migrations/0001_initial.py
    new file mode 100644
    index 0000000..665eb5f
    - +  
     1# encoding: utf8
     2from django.db import models, migrations
     3from django.conf import settings
     4
     5
     6class Migration(migrations.Migration):
     7
     8    dependencies = [
     9        ('contenttypes', '__first__'),
     10        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
     11    ]
     12
     13    operations = [
     14        migrations.CreateModel(
     15            name='LogEntry',
     16            fields=[
     17                (u'id', models.AutoField(verbose_name=u'ID', serialize=False, auto_created=True, primary_key=True)),
     18                ('action_time', models.DateTimeField(auto_now=True, verbose_name=u'action time')),
     19                ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, to_field=u'id')),
     20                ('content_type', models.ForeignKey(to_field=u'id', blank=True, to=u'contenttypes.ContentType', null=True)),
     21                ('object_id', models.TextField(null=True, verbose_name=u'object id', blank=True)),
     22                ('object_repr', models.CharField(max_length=200, verbose_name=u'object repr')),
     23                ('action_flag', models.PositiveSmallIntegerField(verbose_name=u'action flag')),
     24                ('change_message', models.TextField(verbose_name=u'change message', blank=True)),
     25            ],
     26            options={
     27                u'ordering': (u'-action_time',),
     28                u'db_table': u'django_admin_log',
     29                u'verbose_name': u'log entry',
     30                u'verbose_name_plural': u'log entries',
     31            },
     32            bases=(models.Model,),
     33        ),
     34    ]
  • new file django/contrib/auth/migrations/0001_initial.py

    diff --git a/django/contrib/admin/migrations/__init__.py b/django/contrib/admin/migrations/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/django/contrib/auth/migrations/0001_initial.py b/django/contrib/auth/migrations/0001_initial.py
    new file mode 100644
    index 0000000..085ebd1
    - +  
     1# encoding: utf8
     2from django.db import models, migrations
     3import django.utils.timezone
     4import django.core.validators
     5
     6
     7class Migration(migrations.Migration):
     8
     9    dependencies = [
     10        ('contenttypes', '__first__'),
     11    ]
     12
     13    operations = [
     14        migrations.CreateModel(
     15            name='Permission',
     16            fields=[
     17                (u'id', models.AutoField(verbose_name=u'ID', serialize=False, auto_created=True, primary_key=True)),
     18                ('name', models.CharField(max_length=50, verbose_name=u'name')),
     19                ('content_type', models.ForeignKey(to=u'contenttypes.ContentType', to_field=u'id')),
     20                ('codename', models.CharField(max_length=100, verbose_name=u'codename')),
     21            ],
     22            options={
     23                u'ordering': (u'content_type__app_label', u'content_type__model', u'codename'),
     24                u'unique_together': set([(u'content_type', u'codename')]),
     25                u'verbose_name': u'permission',
     26                u'verbose_name_plural': u'permissions',
     27            },
     28            bases=(models.Model,),
     29        ),
     30        migrations.CreateModel(
     31            name='Group',
     32            fields=[
     33                (u'id', models.AutoField(verbose_name=u'ID', serialize=False, auto_created=True, primary_key=True)),
     34                ('name', models.CharField(unique=True, max_length=80, verbose_name=u'name')),
     35                ('permissions', models.ManyToManyField(to=u'auth.Permission', verbose_name=u'permissions', blank=True)),
     36            ],
     37            options={
     38                u'verbose_name': u'group',
     39                u'verbose_name_plural': u'groups',
     40            },
     41            bases=(models.Model,),
     42        ),
     43        migrations.CreateModel(
     44            name='User',
     45            fields=[
     46                (u'id', models.AutoField(verbose_name=u'ID', serialize=False, auto_created=True, primary_key=True)),
     47                ('password', models.CharField(max_length=128, verbose_name=u'password')),
     48                ('last_login', models.DateTimeField(default=django.utils.timezone.now, verbose_name=u'last login')),
     49                ('is_superuser', models.BooleanField(default=False, help_text=u'Designates that this user has all permissions without explicitly assigning them.', verbose_name=u'superuser status')),
     50                ('username', models.CharField(help_text=u'Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.', unique=True, max_length=30, verbose_name=u'username', validators=[django.core.validators.RegexValidator(u'^[\\w.@+-]+$', u'Enter a valid username.', u'invalid')])),
     51                ('first_name', models.CharField(max_length=30, verbose_name=u'first name', blank=True)),
     52                ('last_name', models.CharField(max_length=30, verbose_name=u'last name', blank=True)),
     53                ('email', models.EmailField(max_length=75, verbose_name=u'email address', blank=True)),
     54                ('is_staff', models.BooleanField(default=False, help_text=u'Designates whether the user can log into this admin site.', verbose_name=u'staff status')),
     55                ('is_active', models.BooleanField(default=True, help_text=u'Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name=u'active')),
     56                ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name=u'date joined')),
     57                ('groups', models.ManyToManyField(to=u'auth.Group', verbose_name=u'groups', blank=True)),
     58                ('user_permissions', models.ManyToManyField(to=u'auth.Permission', verbose_name=u'user permissions', blank=True)),
     59            ],
     60            options={
     61                u'abstract': False,
     62                u'verbose_name': u'user',
     63                u'swappable': u'AUTH_USER_MODEL',
     64                u'verbose_name_plural': u'users',
     65            },
     66            bases=(models.Model,),
     67        ),
     68    ]
  • new file django/contrib/comments/migrations/0001_initial.py

    diff --git a/django/contrib/auth/migrations/__init__.py b/django/contrib/auth/migrations/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/django/contrib/comments/migrations/0001_initial.py b/django/contrib/comments/migrations/0001_initial.py
    new file mode 100644
    index 0000000..1be00bf
    - +  
     1# encoding: utf8
     2from django.db import models, migrations
     3from django.conf import settings
     4
     5
     6class Migration(migrations.Migration):
     7
     8    dependencies = [
     9        ('contenttypes', '__first__'),
     10        ('sites', '0001_initial'),
     11        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
     12    ]
     13
     14    operations = [
     15        migrations.CreateModel(
     16            name='Comment',
     17            fields=[
     18                (u'id', models.AutoField(verbose_name=u'ID', serialize=False, auto_created=True, primary_key=True)),
     19                ('content_type', models.ForeignKey(to=u'contenttypes.ContentType', to_field=u'id', verbose_name=u'content type')),
     20                ('object_pk', models.TextField(verbose_name=u'object ID')),
     21                ('site', models.ForeignKey(to='sites.Site', to_field=u'id')),
     22                ('user', models.ForeignKey(verbose_name=u'user', to_field=u'id', blank=True, to=settings.AUTH_USER_MODEL, null=True)),
     23                ('user_name', models.CharField(max_length=50, verbose_name=u"user's name", blank=True)),
     24                ('user_email', models.EmailField(max_length=75, verbose_name=u"user's email address", blank=True)),
     25                ('user_url', models.URLField(verbose_name=u"user's URL", blank=True)),
     26                ('comment', models.TextField(max_length=3000, verbose_name=u'comment')),
     27                ('submit_date', models.DateTimeField(default=None, verbose_name=u'date/time submitted')),
     28                ('ip_address', models.GenericIPAddressField(unpack_ipv4=True, null=True, verbose_name=u'IP address', blank=True)),
     29                ('is_public', models.BooleanField(default=True, help_text=u'Uncheck this box to make the comment effectively disappear from the site.', verbose_name=u'is public')),
     30                ('is_removed', models.BooleanField(default=False, help_text=u'Check this box if the comment is inappropriate. A "This comment has been removed" message will be displayed instead.', verbose_name=u'is removed')),
     31            ],
     32            options={
     33                u'ordering': ('submit_date',),
     34                u'db_table': 'django_comments',
     35                u'verbose_name': u'comment',
     36                u'verbose_name_plural': u'comments',
     37                u'permissions': [('can_moderate', 'Can moderate comments')],
     38            },
     39            bases=(models.Model,),
     40        ),
     41        migrations.CreateModel(
     42            name='CommentFlag',
     43            fields=[
     44                (u'id', models.AutoField(verbose_name=u'ID', serialize=False, auto_created=True, primary_key=True)),
     45                ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL, to_field=u'id', verbose_name=u'user')),
     46                ('comment', models.ForeignKey(to=u'comments.Comment', to_field=u'id', verbose_name=u'comment')),
     47                ('flag', models.CharField(max_length=30, verbose_name=u'flag', db_index=True)),
     48                ('flag_date', models.DateTimeField(default=None, verbose_name=u'date')),
     49            ],
     50            options={
     51                u'unique_together': set([('user', 'comment', 'flag')]),
     52                u'db_table': 'django_comment_flags',
     53                u'verbose_name': u'comment flag',
     54                u'verbose_name_plural': u'comment flags',
     55            },
     56            bases=(models.Model,),
     57        ),
     58    ]
  • new file django/contrib/flatpages/migrations/0001_initial.py

    diff --git a/django/contrib/comments/migrations/__init__.py b/django/contrib/comments/migrations/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/django/contrib/flatpages/migrations/0001_initial.py b/django/contrib/flatpages/migrations/0001_initial.py
    new file mode 100644
    index 0000000..e33ccc2
    - +  
     1# encoding: utf8
     2from django.db import models, migrations
     3
     4
     5class Migration(migrations.Migration):
     6
     7    dependencies = [
     8        ('sites', '0001_initial'),
     9    ]
     10
     11    operations = [
     12        migrations.CreateModel(
     13            name='FlatPage',
     14            fields=[
     15                (u'id', models.AutoField(verbose_name=u'ID', serialize=False, auto_created=True, primary_key=True)),
     16                ('url', models.CharField(max_length=100, verbose_name=u'URL', db_index=True)),
     17                ('title', models.CharField(max_length=200, verbose_name=u'title')),
     18                ('content', models.TextField(verbose_name=u'content', blank=True)),
     19                ('enable_comments', models.BooleanField(default=False, verbose_name=u'enable comments')),
     20                ('template_name', models.CharField(help_text=u"Example: 'flatpages/contact_page.html'. If this isn't provided, the system will use 'flatpages/default.html'.", max_length=70, verbose_name=u'template name', blank=True)),
     21                ('registration_required', models.BooleanField(default=False, help_text=u'If this is checked, only logged-in users will be able to view the page.', verbose_name=u'registration required')),
     22                ('sites', models.ManyToManyField(to='sites.Site')),
     23            ],
     24            options={
     25                u'ordering': (u'url',),
     26                u'db_table': u'django_flatpage',
     27                u'verbose_name': u'flat page',
     28                u'verbose_name_plural': u'flat pages',
     29            },
     30            bases=(models.Model,),
     31        ),
     32    ]
  • new file django/contrib/redirects/migrations/0001_initial.py

    diff --git a/django/contrib/flatpages/migrations/__init__.py b/django/contrib/flatpages/migrations/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/django/contrib/redirects/migrations/0001_initial.py b/django/contrib/redirects/migrations/0001_initial.py
    new file mode 100644
    index 0000000..ad1876c
    - +  
     1# encoding: utf8
     2from django.db import models, migrations
     3
     4
     5class Migration(migrations.Migration):
     6
     7    dependencies = [
     8        ('sites', '0001_initial'),
     9    ]
     10
     11    operations = [
     12        migrations.CreateModel(
     13            name='Redirect',
     14            fields=[
     15                (u'id', models.AutoField(verbose_name=u'ID', serialize=False, auto_created=True, primary_key=True)),
     16                ('site', models.ForeignKey(to='sites.Site', to_field=u'id')),
     17                ('old_path', models.CharField(help_text=u"This should be an absolute path, excluding the domain name. Example: '/events/search/'.", max_length=200, verbose_name=u'redirect from', db_index=True)),
     18                ('new_path', models.CharField(help_text=u"This can be either an absolute path (as above) or a full URL starting with 'http://'.", max_length=200, verbose_name=u'redirect to', blank=True)),
     19            ],
     20            options={
     21                u'ordering': ('old_path',),
     22                u'unique_together': set([('site', 'old_path')]),
     23                u'db_table': 'django_redirect',
     24                u'verbose_name': u'redirect',
     25                u'verbose_name_plural': u'redirects',
     26            },
     27            bases=(models.Model,),
     28        ),
     29    ]
  • new file django/contrib/sessions/migrations/0001_initial.py

    diff --git a/django/contrib/redirects/migrations/__init__.py b/django/contrib/redirects/migrations/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/django/contrib/sessions/migrations/0001_initial.py b/django/contrib/sessions/migrations/0001_initial.py
    new file mode 100644
    index 0000000..5652692
    - +  
     1# encoding: utf8
     2from django.db import models, migrations
     3
     4
     5class Migration(migrations.Migration):
     6
     7    dependencies = [
     8    ]
     9
     10    operations = [
     11        migrations.CreateModel(
     12            name='Session',
     13            fields=[
     14                ('session_key', models.CharField(max_length=40, serialize=False, verbose_name=u'session key', primary_key=True)),
     15                ('session_data', models.TextField(verbose_name=u'session data')),
     16                ('expire_date', models.DateTimeField(verbose_name=u'expire date', db_index=True)),
     17            ],
     18            options={
     19                u'db_table': 'django_session',
     20                u'verbose_name': u'session',
     21                u'verbose_name_plural': u'sessions',
     22            },
     23            bases=(models.Model,),
     24        ),
     25    ]
  • new file django/contrib/sites/migrations/0001_initial.py

    diff --git a/django/contrib/sessions/migrations/__init__.py b/django/contrib/sessions/migrations/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/django/contrib/sites/migrations/0001_initial.py b/django/contrib/sites/migrations/0001_initial.py
    new file mode 100644
    index 0000000..3830c1f
    - +  
     1# encoding: utf8
     2from django.db import models, migrations
     3import django.contrib.sites.models
     4
     5
     6class Migration(migrations.Migration):
     7
     8    dependencies = [
     9    ]
     10
     11    operations = [
     12        migrations.CreateModel(
     13            name='Site',
     14            fields=[
     15                (u'id', models.AutoField(verbose_name=u'ID', serialize=False, auto_created=True, primary_key=True)),
     16                ('domain', models.CharField(max_length=100, verbose_name=u'domain name', validators=[django.contrib.sites.models._simple_domain_name_validator])),
     17                ('name', models.CharField(max_length=50, verbose_name=u'display name')),
     18            ],
     19            options={
     20                u'ordering': (u'domain',),
     21                u'db_table': u'django_site',
     22                u'verbose_name': u'site',
     23                u'verbose_name_plural': u'sites',
     24            },
     25            bases=(models.Model,),
     26        ),
     27    ]
  • django/db/migrations/recorder.py

    diff --git a/django/contrib/sites/migrations/__init__.py b/django/contrib/sites/migrations/__init__.py
    new file mode 100644
    index 0000000..e69de29
    diff --git a/django/db/migrations/recorder.py b/django/db/migrations/recorder.py
    index 15a3b49..268d0f6 100644
    a b class MigrationRecorder(object):  
    4646        Returns a set of (app, name) of applied migrations.
    4747        """
    4848        self.ensure_schema()
    49         return set(tuple(x) for x in self.Migration.objects.values_list("app", "name"))
     49        return set(tuple(x) for x in self.Migration.objects.using(self.connection.alias).values_list("app", "name"))
    5050
    5151    def record_applied(self, app, name):
    5252        """
    5353        Records that a migration was applied.
    5454        """
    5555        self.ensure_schema()
    56         self.Migration.objects.create(app=app, name=name)
     56        self.Migration.objects.using(self.connection.alias).create(app=app, name=name)
    5757
    5858    def record_unapplied(self, app, name):
    5959        """
    6060        Records that a migration was unapplied.
    6161        """
    6262        self.ensure_schema()
    63         self.Migration.objects.filter(app=app, name=name).delete()
     63        self.Migration.objects.using(self.connection.alias).filter(app=app, name=name).delete()
    6464
    6565    @classmethod
    6666    def flush(cls):
  • tests/migrations/test_executor.py

    diff --git a/tests/migrations/test_executor.py b/tests/migrations/test_executor.py
    index e8dcacd..6dcce3a 100644
    a b class ExecutorTests(MigrationTestBase):  
    111111        # We use 'sessions' here as the second app as it's always present
    112112        # in INSTALLED_APPS, so we can happily assign it test migrations.
    113113        executor = MigrationExecutor(connection)
    114         plan = executor.migration_plan([("migrations", "0002_second"), ("sessions", "0001_initial")])
     114        plan = executor.migration_plan([("migrations", "0002_second"), ("sessions", "0002_invented")])
    115115        self.assertEqual(
    116116            plan,
    117117            [
    118118                (executor.loader.graph.nodes["migrations", "0001_initial"], False),
    119119                (executor.loader.graph.nodes["migrations", "0002_second"], False),
    120                 (executor.loader.graph.nodes["sessions", "0001_initial"], False),
     120                (executor.loader.graph.nodes["sessions", "0002_invented"], False),
    121121            ],
    122122        )
    123123        # Fake-apply all migrations
  • tests/migrations/test_loader.py

    diff --git a/tests/migrations/test_loader.py b/tests/migrations/test_loader.py
    index f661a03..6a09cf2 100644
    a b class RecorderTests(TestCase):  
    1717        Tests marking migrations as applied/unapplied.
    1818        """
    1919        recorder = MigrationRecorder(connection)
     20        already_appled = ["sessions", "redirects", "auth", "admin", "comments", "sites", "flatpages"]
    2021        self.assertEqual(
    21             recorder.applied_migrations(),
     22            set((x, y) for x, y in recorder.applied_migrations() if x not in already_appled),
    2223            set(),
    2324        )
    2425        recorder.record_applied("myapp", "0432_ponies")
    2526        self.assertEqual(
    26             recorder.applied_migrations(),
     27            set((x, y) for x, y in recorder.applied_migrations() if x not in already_appled),
    2728            set([("myapp", "0432_ponies")]),
    2829        )
    2930        recorder.record_unapplied("myapp", "0432_ponies")
    3031        self.assertEqual(
    31             recorder.applied_migrations(),
     32            set((x, y) for x, y in recorder.applied_migrations() if x not in already_appled),
    3233            set(),
    3334        )
    3435
    class LoaderTests(TestCase):  
    3940    in memory.
    4041    """
    4142
     43    available_apps = ["migrations", "django.contrib.auth", "django.contrib.contenttypes"]
     44
    4245    @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
    4346    def test_load(self):
    4447        """
    class LoaderTests(TestCase):  
    8083        self.assertEqual(
    8184            migration_loader.graph.forwards_plan(("migrations", "0001_initial")),
    8285            [
    83                 ("auth", "__first__"),
     86                ("contenttypes", "__first__"),
     87                ("auth", "0001_initial"),
    8488                ("migrations", "0001_initial"),
    8589            ],
    8690        )
    class LoaderTests(TestCase):  
    126130        "Tests loading a squashed migration"
    127131        migration_loader = MigrationLoader(connection)
    128132        recorder = MigrationRecorder(connection)
    129         # Loading with nothing applied should just give us the one node
     133        # Loading with nothing applied should just give us the one node,
     134        # plus 2 from contrib apps
    130135        self.assertEqual(
    131136            len(migration_loader.graph.nodes),
    132             1,
     137            3,
    133138        )
    134139        # However, fake-apply one migration and it should now use the old two
    135140        recorder.record_applied("migrations", "0001_initial")
    136141        migration_loader.build_graph()
    137142        self.assertEqual(
    138143            len(migration_loader.graph.nodes),
    139             2,
     144            4,
    140145        )
    141146        recorder.flush()
  • new file tests/migrations/test_migrations_2/0002_invented.py

    diff --git a/tests/migrations/test_migrations_2/0002_invented.py b/tests/migrations/test_migrations_2/0002_invented.py
    new file mode 100644
    index 0000000..81b39d7
    - +  
     1from django.db import migrations, models
     2
     3
     4class Migration(migrations.Migration):
     5
     6    dependencies = [("sessions", "0001_initial")]
     7
     8    operations = [
     9
     10        migrations.CreateModel(
     11            "Huh",
     12            [
     13                ("id", models.AutoField(primary_key=True)),
     14            ],
     15        ),
     16
     17    ]
Back to Top