Browse Source

Rename allow_syncdb to allow_migrate

Andrew Godwin 11 years ago
parent
commit
12e9804d16

+ 1 - 1
django/contrib/auth/management/__init__.py

@@ -64,7 +64,7 @@ def create_permissions(app, created_models, verbosity, db=DEFAULT_DB_ALIAS, **kw
     except UnavailableApp:
     except UnavailableApp:
         return
         return
 
 
-    if not router.allow_syncdb(db, auth_app.Permission):
+    if not router.allow_migrate(db, auth_app.Permission):
         return
         return
 
 
     from django.contrib.contenttypes.models import ContentType
     from django.contrib.contenttypes.models import ContentType

+ 1 - 1
django/contrib/contenttypes/management.py

@@ -16,7 +16,7 @@ def update_contenttypes(app, created_models, verbosity=2, db=DEFAULT_DB_ALIAS, *
     except UnavailableApp:
     except UnavailableApp:
         return
         return
 
 
-    if not router.allow_syncdb(db, ContentType):
+    if not router.allow_migrate(db, ContentType):
         return
         return
 
 
     ContentType.objects.clear_cache()
     ContentType.objects.clear_cache()

+ 1 - 1
django/contrib/gis/tests/layermap/tests.py

@@ -311,7 +311,7 @@ class OtherRouter(object):
     def allow_relation(self, obj1, obj2, **hints):
     def allow_relation(self, obj1, obj2, **hints):
         return None
         return None
 
 
-    def allow_syncdb(self, db, model):
+    def allow_migrate(self, db, model):
         return True
         return True
 
 
 
 

+ 1 - 1
django/contrib/sites/management.py

@@ -11,7 +11,7 @@ from django.core.management.color import no_style
 
 
 def create_default_site(app, created_models, verbosity, db, **kwargs):
 def create_default_site(app, created_models, verbosity, db, **kwargs):
     # Only create the default sites in databases where Django created the table
     # Only create the default sites in databases where Django created the table
-    if Site in created_models and router.allow_syncdb(db, Site) :
+    if Site in created_models and router.allow_migrate(db, Site) :
         # The default settings set SITE_ID = 1, and some tests in Django's test
         # The default settings set SITE_ID = 1, and some tests in Django's test
         # suite rely on this value. However, if database sequences are reused
         # suite rely on this value. However, if database sequences are reused
         # (e.g. in the test suite after flush/syncdb), it isn't guaranteed that
         # (e.g. in the test suite after flush/syncdb), it isn't guaranteed that

+ 1 - 1
django/core/management/commands/createcachetable.py

@@ -24,7 +24,7 @@ class Command(LabelCommand):
     def handle_label(self, tablename, **options):
     def handle_label(self, tablename, **options):
         db = options.get('database')
         db = options.get('database')
         cache = BaseDatabaseCache(tablename, {})
         cache = BaseDatabaseCache(tablename, {})
-        if not router.allow_syncdb(db, cache.cache_model_class):
+        if not router.allow_migrate(db, cache.cache_model_class):
             return
             return
         connection = connections[db]
         connection = connections[db]
         fields = (
         fields = (

+ 1 - 1
django/core/management/commands/dumpdata.py

@@ -117,7 +117,7 @@ class Command(BaseCommand):
             for model in sort_dependencies(app_list.items()):
             for model in sort_dependencies(app_list.items()):
                 if model in excluded_models:
                 if model in excluded_models:
                     continue
                     continue
-                if not model._meta.proxy and router.allow_syncdb(using, model):
+                if not model._meta.proxy and router.allow_migrate(using, model):
                     if use_base_manager:
                     if use_base_manager:
                         objects = model._base_manager
                         objects = model._base_manager
                     else:
                     else:

+ 1 - 1
django/core/management/commands/flush.py

@@ -96,6 +96,6 @@ Are you sure you want to do this?
         for app in models.get_apps():
         for app in models.get_apps():
             all_models.extend([
             all_models.extend([
                 m for m in models.get_models(app, include_auto_created=True)
                 m for m in models.get_models(app, include_auto_created=True)
-                if router.allow_syncdb(database, m)
+                if router.allow_migrate(database, m)
             ])
             ])
         emit_post_migrate_signal(set(all_models), verbosity, interactive, database)
         emit_post_migrate_signal(set(all_models), verbosity, interactive, database)

+ 1 - 1
django/core/management/commands/loaddata.py

@@ -133,7 +133,7 @@ class Command(BaseCommand):
 
 
                 for obj in objects:
                 for obj in objects:
                     objects_in_fixture += 1
                     objects_in_fixture += 1
-                    if router.allow_syncdb(self.using, obj.object.__class__):
+                    if router.allow_migrate(self.using, obj.object.__class__):
                         loaded_objects_in_fixture += 1
                         loaded_objects_in_fixture += 1
                         self.models.add(obj.object.__class__)
                         self.models.add(obj.object.__class__)
                         try:
                         try:

+ 1 - 1
django/core/management/commands/migrate.py

@@ -149,7 +149,7 @@ class Command(BaseCommand):
             (app.__name__.split('.')[-2],
             (app.__name__.split('.')[-2],
                 [
                 [
                     m for m in models.get_models(app, include_auto_created=True)
                     m for m in models.get_models(app, include_auto_created=True)
-                    if router.allow_syncdb(connection.alias, m)
+                    if router.allow_migrate(connection.alias, m)
                 ])
                 ])
             for app in models.get_apps() if app.__name__.split('.')[-2] in apps
             for app in models.get_apps() if app.__name__.split('.')[-2] in apps
         ]
         ]

+ 3 - 3
django/db/backends/__init__.py

@@ -1243,7 +1243,7 @@ class BaseDatabaseIntrospection(object):
             for model in models.get_models(app):
             for model in models.get_models(app):
                 if not model._meta.managed:
                 if not model._meta.managed:
                     continue
                     continue
-                if not router.allow_syncdb(self.connection.alias, model):
+                if not router.allow_migrate(self.connection.alias, model):
                     continue
                     continue
                 tables.add(model._meta.db_table)
                 tables.add(model._meta.db_table)
                 tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many])
                 tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many])
@@ -1263,7 +1263,7 @@ class BaseDatabaseIntrospection(object):
         all_models = []
         all_models = []
         for app in models.get_apps():
         for app in models.get_apps():
             for model in models.get_models(app):
             for model in models.get_models(app):
-                if router.allow_syncdb(self.connection.alias, model):
+                if router.allow_migrate(self.connection.alias, model):
                     all_models.append(model)
                     all_models.append(model)
         tables = list(map(self.table_name_converter, tables))
         tables = list(map(self.table_name_converter, tables))
         return set([
         return set([
@@ -1284,7 +1284,7 @@ class BaseDatabaseIntrospection(object):
                     continue
                     continue
                 if model._meta.swapped:
                 if model._meta.swapped:
                     continue
                     continue
-                if not router.allow_syncdb(self.connection.alias, model):
+                if not router.allow_migrate(self.connection.alias, model):
                     continue
                     continue
                 for f in model._meta.local_fields:
                 for f in model._meta.local_fields:
                     if isinstance(f, models.AutoField):
                     if isinstance(f, models.AutoField):

+ 5 - 2
django/db/utils.py

@@ -262,10 +262,13 @@ class ConnectionRouter(object):
                     return allow
                     return allow
         return obj1._state.db == obj2._state.db
         return obj1._state.db == obj2._state.db
 
 
-    def allow_syncdb(self, db, model):
+    def allow_migrate(self, db, model):
         for router in self.routers:
         for router in self.routers:
             try:
             try:
-                method = router.allow_syncdb
+                try:
+                    method = router.allow_migrate
+                except AttributeError:
+                    method = router.allow_syncdb
             except AttributeError:
             except AttributeError:
                 # If the router doesn't have a method, skip to the next one.
                 # If the router doesn't have a method, skip to the next one.
                 pass
                 pass

+ 5 - 0
docs/internals/deprecation.txt

@@ -414,12 +414,17 @@ these changes.
 
 
 * ``django.utils.unittest`` will be removed.
 * ``django.utils.unittest`` will be removed.
 
 
+* The ``syncdb`` command will be removed.
+
 * ``django.db.models.signals.pre_syncdb`` and
 * ``django.db.models.signals.pre_syncdb`` and
   ``django.db.models.signals.post_syncdb`` will be removed, and
   ``django.db.models.signals.post_syncdb`` will be removed, and
   ``django.db.models.signals.pre_migrate`` and
   ``django.db.models.signals.pre_migrate`` and
   ``django.db.models.signals.post_migrate`` will lose their
   ``django.db.models.signals.post_migrate`` will lose their
   ``create_models`` and ``created_models`` arguments.
   ``create_models`` and ``created_models`` arguments.
 
 
+* ``allow_syncdb`` on database routers will no longer automatically become
+  ``allow_migrate``.
+
 2.0
 2.0
 ---
 ---
 
 

+ 4 - 1
docs/releases/1.7.txt

@@ -52,7 +52,10 @@ but a few of the key features are:
   :data:`~django.db.models.signals.post_migrate` respectively. The
   :data:`~django.db.models.signals.post_migrate` respectively. The
   ``create_models``/``created_models`` argument has also been deprecated.
   ``create_models``/``created_models`` argument has also been deprecated.
 
 
-* Routers something something.
+* The ``allow_syncdb`` method on database routers is now called ``allow_migrate``,
+  but still performs the same function. Routers with ``allow_syncdb`` methods
+  will still work, but that method name is deprecated and you should change
+  it as soon as possible (nothing more than renaming is required).
 
 
 Admin shortcuts support time zones
 Admin shortcuts support time zones
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 2 - 2
docs/topics/cache.txt

@@ -215,8 +215,8 @@ operations to ``cache_slave``, and all write operations to
                 return 'cache_master'
                 return 'cache_master'
             return None
             return None
 
 
-        def allow_syncdb(self, db, model):
-            "Only synchronize the cache model on master"
+        def allow_migrate(self, db, model):
+            "Only install the cache model on master"
             if model._meta.app_label in ('django_cache',):
             if model._meta.app_label in ('django_cache',):
                 return db == 'cache_master'
                 return db == 'cache_master'
             return None
             return None

+ 9 - 6
docs/topics/db/multi-db.txt

@@ -155,14 +155,17 @@ A database Router is a class that provides up to four methods:
     used by foreign key and many to many operations to determine if a
     used by foreign key and many to many operations to determine if a
     relation should be allowed between two objects.
     relation should be allowed between two objects.
 
 
-.. method:: allow_syncdb(db, model)
+.. method:: allow_migrate(db, model)
 
 
-    Determine if the ``model`` should be synchronized onto the
+    Determine if the ``model`` should have tables/indexes created in the
     database with alias ``db``. Return True if the model should be
     database with alias ``db``. Return True if the model should be
-    synchronized, False if it should not be synchronized, or None if
+    migrated, False if it should not be migrated, or None if
     the router has no opinion. This method can be used to determine
     the router has no opinion. This method can be used to determine
     the availability of a model on a given database.
     the availability of a model on a given database.
 
 
+    Note that if this returns ``True`` for an app with migrations but
+    ``False`` for an app those migrations depend on, Django will error.
+
 A router doesn't have to provide *all* these methods -- it may omit one
 A router doesn't have to provide *all* these methods -- it may omit one
 or more of them. If one of the methods is omitted, Django will skip
 or more of them. If one of the methods is omitted, Django will skip
 that router when performing the relevant check.
 that router when performing the relevant check.
@@ -288,7 +291,7 @@ send queries for the ``auth`` app to ``auth_db``::
                return True
                return True
             return None
             return None
 
 
-        def allow_syncdb(self, db, model):
+        def allow_migrate(self, db, model):
             """
             """
             Make sure the auth app only appears in the 'auth_db'
             Make sure the auth app only appears in the 'auth_db'
             database.
             database.
@@ -328,7 +331,7 @@ from::
                 return True
                 return True
             return None
             return None
 
 
-        def allow_syncdb(self, db, model):
+        def allow_migrate(self, db, model):
             """
             """
             All non-auth models end up in this pool.
             All non-auth models end up in this pool.
             """
             """
@@ -347,7 +350,7 @@ be queried in the order the are listed in the
 result, decisions concerning the models in ``auth`` are processed
 result, decisions concerning the models in ``auth`` are processed
 before any other decision is made. If the :setting:`DATABASE_ROUTERS`
 before any other decision is made. If the :setting:`DATABASE_ROUTERS`
 setting listed the two routers in the other order,
 setting listed the two routers in the other order,
-``MasterSlaveRouter.allow_syncdb()`` would be processed first. The
+``MasterSlaveRouter.allow_migrate()`` would be processed first. The
 catch-all nature of the MasterSlaveRouter implementation would mean
 catch-all nature of the MasterSlaveRouter implementation would mean
 that all models would be available on all databases.
 that all models would be available on all databases.
 
 

+ 1 - 1
tests/cache/tests.py

@@ -895,7 +895,7 @@ class DBCacheRouter(object):
         if model._meta.app_label == 'django_cache':
         if model._meta.app_label == 'django_cache':
             return 'other'
             return 'other'
 
 
-    def allow_syncdb(self, db, model):
+    def allow_migrate(self, db, model):
         if model._meta.app_label == 'django_cache':
         if model._meta.app_label == 'django_cache':
             return db == 'other'
             return db == 'other'
 
 

+ 23 - 23
tests/multiple_database/tests.py

@@ -933,7 +933,7 @@ class TestRouter(object):
     def allow_relation(self, obj1, obj2, **hints):
     def allow_relation(self, obj1, obj2, **hints):
         return obj1._state.db in ('default', 'other') and obj2._state.db in ('default', 'other')
         return obj1._state.db in ('default', 'other') and obj2._state.db in ('default', 'other')
 
 
-    def allow_syncdb(self, db, model):
+    def allow_migrate(self, db, model):
         return True
         return True
 
 
 class AuthRouter(object):
 class AuthRouter(object):
@@ -960,7 +960,7 @@ class AuthRouter(object):
             return True
             return True
         return None
         return None
 
 
-    def allow_syncdb(self, db, model):
+    def allow_migrate(self, db, model):
         "Make sure the auth app only appears on the 'other' db"
         "Make sure the auth app only appears on the 'other' db"
         if db == 'other':
         if db == 'other':
             return model._meta.app_label == 'auth'
             return model._meta.app_label == 'auth'
@@ -1022,30 +1022,30 @@ class RouterTestCase(TestCase):
     def test_syncdb_selection(self):
     def test_syncdb_selection(self):
         "Synchronization behavior is predictable"
         "Synchronization behavior is predictable"
 
 
-        self.assertTrue(router.allow_syncdb('default', User))
-        self.assertTrue(router.allow_syncdb('default', Book))
+        self.assertTrue(router.allow_migrate('default', User))
+        self.assertTrue(router.allow_migrate('default', Book))
 
 
-        self.assertTrue(router.allow_syncdb('other', User))
-        self.assertTrue(router.allow_syncdb('other', Book))
+        self.assertTrue(router.allow_migrate('other', User))
+        self.assertTrue(router.allow_migrate('other', Book))
 
 
         # Add the auth router to the chain.
         # Add the auth router to the chain.
         # TestRouter is a universal synchronizer, so it should have no effect.
         # TestRouter is a universal synchronizer, so it should have no effect.
         router.routers = [TestRouter(), AuthRouter()]
         router.routers = [TestRouter(), AuthRouter()]
 
 
-        self.assertTrue(router.allow_syncdb('default', User))
-        self.assertTrue(router.allow_syncdb('default', Book))
+        self.assertTrue(router.allow_migrate('default', User))
+        self.assertTrue(router.allow_migrate('default', Book))
 
 
-        self.assertTrue(router.allow_syncdb('other', User))
-        self.assertTrue(router.allow_syncdb('other', Book))
+        self.assertTrue(router.allow_migrate('other', User))
+        self.assertTrue(router.allow_migrate('other', Book))
 
 
         # Now check what happens if the router order is the other way around
         # Now check what happens if the router order is the other way around
         router.routers = [AuthRouter(), TestRouter()]
         router.routers = [AuthRouter(), TestRouter()]
 
 
-        self.assertFalse(router.allow_syncdb('default', User))
-        self.assertTrue(router.allow_syncdb('default', Book))
+        self.assertFalse(router.allow_migrate('default', User))
+        self.assertTrue(router.allow_migrate('default', Book))
 
 
-        self.assertTrue(router.allow_syncdb('other', User))
-        self.assertFalse(router.allow_syncdb('other', Book))
+        self.assertTrue(router.allow_migrate('other', User))
+        self.assertFalse(router.allow_migrate('other', Book))
 
 
     def test_partial_router(self):
     def test_partial_router(self):
         "A router can choose to implement a subset of methods"
         "A router can choose to implement a subset of methods"
@@ -1062,8 +1062,8 @@ class RouterTestCase(TestCase):
 
 
         self.assertTrue(router.allow_relation(dive, dive))
         self.assertTrue(router.allow_relation(dive, dive))
 
 
-        self.assertTrue(router.allow_syncdb('default', User))
-        self.assertTrue(router.allow_syncdb('default', Book))
+        self.assertTrue(router.allow_migrate('default', User))
+        self.assertTrue(router.allow_migrate('default', Book))
 
 
         router.routers = [WriteRouter(), AuthRouter(), TestRouter()]
         router.routers = [WriteRouter(), AuthRouter(), TestRouter()]
 
 
@@ -1075,8 +1075,8 @@ class RouterTestCase(TestCase):
 
 
         self.assertTrue(router.allow_relation(dive, dive))
         self.assertTrue(router.allow_relation(dive, dive))
 
 
-        self.assertFalse(router.allow_syncdb('default', User))
-        self.assertTrue(router.allow_syncdb('default', Book))
+        self.assertFalse(router.allow_migrate('default', User))
+        self.assertTrue(router.allow_migrate('default', Book))
 
 
 
 
     def test_database_routing(self):
     def test_database_routing(self):
@@ -1607,12 +1607,12 @@ class AuthTestCase(TestCase):
         self.assertEqual(User.objects.using('other').count(), 1)
         self.assertEqual(User.objects.using('other').count(), 1)
 
 
     def test_dumpdata(self):
     def test_dumpdata(self):
-        "Check that dumpdata honors allow_syncdb restrictions on the router"
+        "Check that dumpdata honors allow_migrate restrictions on the router"
         User.objects.create_user('alice', 'alice@example.com')
         User.objects.create_user('alice', 'alice@example.com')
         User.objects.db_manager('default').create_user('bob', 'bob@example.com')
         User.objects.db_manager('default').create_user('bob', 'bob@example.com')
 
 
         # Check that dumping the default database doesn't try to include auth
         # Check that dumping the default database doesn't try to include auth
-        # because allow_syncdb prohibits auth on default
+        # because allow_migrate prohibits auth on default
         new_io = StringIO()
         new_io = StringIO()
         management.call_command('dumpdata', 'auth', format='json', database='default', stdout=new_io)
         management.call_command('dumpdata', 'auth', format='json', database='default', stdout=new_io)
         command_output = new_io.getvalue().strip()
         command_output = new_io.getvalue().strip()
@@ -1625,10 +1625,10 @@ class AuthTestCase(TestCase):
         self.assertTrue('"email": "alice@example.com"' in command_output)
         self.assertTrue('"email": "alice@example.com"' in command_output)
 
 
 class AntiPetRouter(object):
 class AntiPetRouter(object):
-    # A router that only expresses an opinion on syncdb,
+    # A router that only expresses an opinion on migrate,
     # passing pets to the 'other' database
     # passing pets to the 'other' database
 
 
-    def allow_syncdb(self, db, model):
+    def allow_migrate(self, db, model):
         "Make sure the auth app only appears on the 'other' db"
         "Make sure the auth app only appears on the 'other' db"
         if db == 'other':
         if db == 'other':
             return model._meta.object_name == 'Pet'
             return model._meta.object_name == 'Pet'
@@ -1917,7 +1917,7 @@ class RouterModelArgumentTestCase(TestCase):
 
 
 
 
 class SyncOnlyDefaultDatabaseRouter(object):
 class SyncOnlyDefaultDatabaseRouter(object):
-    def allow_syncdb(self, db, model):
+    def allow_migrate(self, db, model):
         return db == DEFAULT_DB_ALIAS
         return db == DEFAULT_DB_ALIAS