Ticket #22170: initial-migrations-contrib.diff
File initial-migrations-contrib.diff, 21.3 KB (added by , 11 years ago) |
---|
-
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 2 from django.db import models, migrations 3 from django.conf import settings 4 5 6 class 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 2 from django.db import models, migrations 3 import django.utils.timezone 4 import django.core.validators 5 6 7 class 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 2 from django.db import models, migrations 3 from django.conf import settings 4 5 6 class 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 2 from django.db import models, migrations 3 4 5 class 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 2 from django.db import models, migrations 3 4 5 class 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 2 from django.db import models, migrations 3 4 5 class 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 2 from django.db import models, migrations 3 import django.contrib.sites.models 4 5 6 class 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): 46 46 Returns a set of (app, name) of applied migrations. 47 47 """ 48 48 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")) 50 50 51 51 def record_applied(self, app, name): 52 52 """ 53 53 Records that a migration was applied. 54 54 """ 55 55 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) 57 57 58 58 def record_unapplied(self, app, name): 59 59 """ 60 60 Records that a migration was unapplied. 61 61 """ 62 62 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() 64 64 65 65 @classmethod 66 66 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): 111 111 # We use 'sessions' here as the second app as it's always present 112 112 # in INSTALLED_APPS, so we can happily assign it test migrations. 113 113 executor = MigrationExecutor(connection) 114 plan = executor.migration_plan([("migrations", "0002_second"), ("sessions", "000 1_initial")])114 plan = executor.migration_plan([("migrations", "0002_second"), ("sessions", "0002_invented")]) 115 115 self.assertEqual( 116 116 plan, 117 117 [ 118 118 (executor.loader.graph.nodes["migrations", "0001_initial"], False), 119 119 (executor.loader.graph.nodes["migrations", "0002_second"], False), 120 (executor.loader.graph.nodes["sessions", "000 1_initial"], False),120 (executor.loader.graph.nodes["sessions", "0002_invented"], False), 121 121 ], 122 122 ) 123 123 # 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): 17 17 Tests marking migrations as applied/unapplied. 18 18 """ 19 19 recorder = MigrationRecorder(connection) 20 already_appled = ["sessions", "redirects", "auth", "admin", "comments", "sites", "flatpages"] 20 21 self.assertEqual( 21 recorder.applied_migrations(),22 set((x, y) for x, y in recorder.applied_migrations() if x not in already_appled), 22 23 set(), 23 24 ) 24 25 recorder.record_applied("myapp", "0432_ponies") 25 26 self.assertEqual( 26 recorder.applied_migrations(),27 set((x, y) for x, y in recorder.applied_migrations() if x not in already_appled), 27 28 set([("myapp", "0432_ponies")]), 28 29 ) 29 30 recorder.record_unapplied("myapp", "0432_ponies") 30 31 self.assertEqual( 31 recorder.applied_migrations(),32 set((x, y) for x, y in recorder.applied_migrations() if x not in already_appled), 32 33 set(), 33 34 ) 34 35 … … class LoaderTests(TestCase): 39 40 in memory. 40 41 """ 41 42 43 available_apps = ["migrations", "django.contrib.auth", "django.contrib.contenttypes"] 44 42 45 @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"}) 43 46 def test_load(self): 44 47 """ … … class LoaderTests(TestCase): 80 83 self.assertEqual( 81 84 migration_loader.graph.forwards_plan(("migrations", "0001_initial")), 82 85 [ 83 ("auth", "__first__"), 86 ("contenttypes", "__first__"), 87 ("auth", "0001_initial"), 84 88 ("migrations", "0001_initial"), 85 89 ], 86 90 ) … … class LoaderTests(TestCase): 126 130 "Tests loading a squashed migration" 127 131 migration_loader = MigrationLoader(connection) 128 132 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 130 135 self.assertEqual( 131 136 len(migration_loader.graph.nodes), 132 1,137 3, 133 138 ) 134 139 # However, fake-apply one migration and it should now use the old two 135 140 recorder.record_applied("migrations", "0001_initial") 136 141 migration_loader.build_graph() 137 142 self.assertEqual( 138 143 len(migration_loader.graph.nodes), 139 2,144 4, 140 145 ) 141 146 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
- + 1 from django.db import migrations, models 2 3 4 class 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 ]