Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Rename allow_syncdb to allow_migrate

  • Loading branch information...
commit 12e9804d163777af17cc2a3dfdfff49e5f750ebd 1 parent 68e0a16
Andrew Godwin authored July 30, 2013
2  django/contrib/auth/management/__init__.py
@@ -64,7 +64,7 @@ def create_permissions(app, created_models, verbosity, db=DEFAULT_DB_ALIAS, **kw
64 64
     except UnavailableApp:
65 65
         return
66 66
 
67  
-    if not router.allow_syncdb(db, auth_app.Permission):
  67
+    if not router.allow_migrate(db, auth_app.Permission):
68 68
         return
69 69
 
70 70
     from django.contrib.contenttypes.models import ContentType
2  django/contrib/contenttypes/management.py
@@ -16,7 +16,7 @@ def update_contenttypes(app, created_models, verbosity=2, db=DEFAULT_DB_ALIAS, *
16 16
     except UnavailableApp:
17 17
         return
18 18
 
19  
-    if not router.allow_syncdb(db, ContentType):
  19
+    if not router.allow_migrate(db, ContentType):
20 20
         return
21 21
 
22 22
     ContentType.objects.clear_cache()
2  django/contrib/gis/tests/layermap/tests.py
@@ -311,7 +311,7 @@ def db_for_write(self, model, **hints):
311 311
     def allow_relation(self, obj1, obj2, **hints):
312 312
         return None
313 313
 
314  
-    def allow_syncdb(self, db, model):
  314
+    def allow_migrate(self, db, model):
315 315
         return True
316 316
 
317 317
 
2  django/contrib/sites/management.py
@@ -11,7 +11,7 @@
11 11
 
12 12
 def create_default_site(app, created_models, verbosity, db, **kwargs):
13 13
     # Only create the default sites in databases where Django created the table
14  
-    if Site in created_models and router.allow_syncdb(db, Site) :
  14
+    if Site in created_models and router.allow_migrate(db, Site) :
15 15
         # The default settings set SITE_ID = 1, and some tests in Django's test
16 16
         # suite rely on this value. However, if database sequences are reused
17 17
         # (e.g. in the test suite after flush/syncdb), it isn't guaranteed that
2  django/core/management/commands/createcachetable.py
@@ -24,7 +24,7 @@ class Command(LabelCommand):
24 24
     def handle_label(self, tablename, **options):
25 25
         db = options.get('database')
26 26
         cache = BaseDatabaseCache(tablename, {})
27  
-        if not router.allow_syncdb(db, cache.cache_model_class):
  27
+        if not router.allow_migrate(db, cache.cache_model_class):
28 28
             return
29 29
         connection = connections[db]
30 30
         fields = (
2  django/core/management/commands/dumpdata.py
@@ -117,7 +117,7 @@ def get_objects():
117 117
             for model in sort_dependencies(app_list.items()):
118 118
                 if model in excluded_models:
119 119
                     continue
120  
-                if not model._meta.proxy and router.allow_syncdb(using, model):
  120
+                if not model._meta.proxy and router.allow_migrate(using, model):
121 121
                     if use_base_manager:
122 122
                         objects = model._base_manager
123 123
                     else:
2  django/core/management/commands/flush.py
@@ -96,6 +96,6 @@ def emit_post_migrate(verbosity, interactive, database):
96 96
         for app in models.get_apps():
97 97
             all_models.extend([
98 98
                 m for m in models.get_models(app, include_auto_created=True)
99  
-                if router.allow_syncdb(database, m)
  99
+                if router.allow_migrate(database, m)
100 100
             ])
101 101
         emit_post_migrate_signal(set(all_models), verbosity, interactive, database)
2  django/core/management/commands/loaddata.py
@@ -133,7 +133,7 @@ def load_label(self, fixture_label):
133 133
 
134 134
                 for obj in objects:
135 135
                     objects_in_fixture += 1
136  
-                    if router.allow_syncdb(self.using, obj.object.__class__):
  136
+                    if router.allow_migrate(self.using, obj.object.__class__):
137 137
                         loaded_objects_in_fixture += 1
138 138
                         self.models.add(obj.object.__class__)
139 139
                         try:
2  django/core/management/commands/migrate.py
@@ -149,7 +149,7 @@ def sync_apps(self, connection, apps):
149 149
             (app.__name__.split('.')[-2],
150 150
                 [
151 151
                     m for m in models.get_models(app, include_auto_created=True)
152  
-                    if router.allow_syncdb(connection.alias, m)
  152
+                    if router.allow_migrate(connection.alias, m)
153 153
                 ])
154 154
             for app in models.get_apps() if app.__name__.split('.')[-2] in apps
155 155
         ]
6  django/db/backends/__init__.py
@@ -1243,7 +1243,7 @@ def django_table_names(self, only_existing=False):
1243 1243
             for model in models.get_models(app):
1244 1244
                 if not model._meta.managed:
1245 1245
                     continue
1246  
-                if not router.allow_syncdb(self.connection.alias, model):
  1246
+                if not router.allow_migrate(self.connection.alias, model):
1247 1247
                     continue
1248 1248
                 tables.add(model._meta.db_table)
1249 1249
                 tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many])
@@ -1263,7 +1263,7 @@ def installed_models(self, tables):
1263 1263
         all_models = []
1264 1264
         for app in models.get_apps():
1265 1265
             for model in models.get_models(app):
1266  
-                if router.allow_syncdb(self.connection.alias, model):
  1266
+                if router.allow_migrate(self.connection.alias, model):
1267 1267
                     all_models.append(model)
1268 1268
         tables = list(map(self.table_name_converter, tables))
1269 1269
         return set([
@@ -1284,7 +1284,7 @@ def sequence_list(self):
1284 1284
                     continue
1285 1285
                 if model._meta.swapped:
1286 1286
                     continue
1287  
-                if not router.allow_syncdb(self.connection.alias, model):
  1287
+                if not router.allow_migrate(self.connection.alias, model):
1288 1288
                     continue
1289 1289
                 for f in model._meta.local_fields:
1290 1290
                     if isinstance(f, models.AutoField):
7  django/db/utils.py
@@ -262,10 +262,13 @@ def allow_relation(self, obj1, obj2, **hints):
262 262
                     return allow
263 263
         return obj1._state.db == obj2._state.db
264 264
 
265  
-    def allow_syncdb(self, db, model):
  265
+    def allow_migrate(self, db, model):
266 266
         for router in self.routers:
267 267
             try:
268  
-                method = router.allow_syncdb
  268
+                try:
  269
+                    method = router.allow_migrate
  270
+                except AttributeError:
  271
+                    method = router.allow_syncdb
269 272
             except AttributeError:
270 273
                 # If the router doesn't have a method, skip to the next one.
271 274
                 pass
5  docs/internals/deprecation.txt
@@ -414,12 +414,17 @@ these changes.
414 414
 
415 415
 * ``django.utils.unittest`` will be removed.
416 416
 
  417
+* The ``syncdb`` command will be removed.
  418
+
417 419
 * ``django.db.models.signals.pre_syncdb`` and
418 420
   ``django.db.models.signals.post_syncdb`` will be removed, and
419 421
   ``django.db.models.signals.pre_migrate`` and
420 422
   ``django.db.models.signals.post_migrate`` will lose their
421 423
   ``create_models`` and ``created_models`` arguments.
422 424
 
  425
+* ``allow_syncdb`` on database routers will no longer automatically become
  426
+  ``allow_migrate``.
  427
+
423 428
 2.0
424 429
 ---
425 430
 
5  docs/releases/1.7.txt
@@ -52,7 +52,10 @@ but a few of the key features are:
52 52
   :data:`~django.db.models.signals.post_migrate` respectively. The
53 53
   ``create_models``/``created_models`` argument has also been deprecated.
54 54
 
55  
-* Routers something something.
  55
+* The ``allow_syncdb`` method on database routers is now called ``allow_migrate``,
  56
+  but still performs the same function. Routers with ``allow_syncdb`` methods
  57
+  will still work, but that method name is deprecated and you should change
  58
+  it as soon as possible (nothing more than renaming is required).
56 59
 
57 60
 Admin shortcuts support time zones
58 61
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4  docs/topics/cache.txt
@@ -215,8 +215,8 @@ operations to ``cache_slave``, and all write operations to
215 215
                 return 'cache_master'
216 216
             return None
217 217
 
218  
-        def allow_syncdb(self, db, model):
219  
-            "Only synchronize the cache model on master"
  218
+        def allow_migrate(self, db, model):
  219
+            "Only install the cache model on master"
220 220
             if model._meta.app_label in ('django_cache',):
221 221
                 return db == 'cache_master'
222 222
             return None
15  docs/topics/db/multi-db.txt
@@ -155,14 +155,17 @@ A database Router is a class that provides up to four methods:
155 155
     used by foreign key and many to many operations to determine if a
156 156
     relation should be allowed between two objects.
157 157
 
158  
-.. method:: allow_syncdb(db, model)
  158
+.. method:: allow_migrate(db, model)
159 159
 
160  
-    Determine if the ``model`` should be synchronized onto the
  160
+    Determine if the ``model`` should have tables/indexes created in the
161 161
     database with alias ``db``. Return True if the model should be
162  
-    synchronized, False if it should not be synchronized, or None if
  162
+    migrated, False if it should not be migrated, or None if
163 163
     the router has no opinion. This method can be used to determine
164 164
     the availability of a model on a given database.
165 165
 
  166
+    Note that if this returns ``True`` for an app with migrations but
  167
+    ``False`` for an app those migrations depend on, Django will error.
  168
+
166 169
 A router doesn't have to provide *all* these methods -- it may omit one
167 170
 or more of them. If one of the methods is omitted, Django will skip
168 171
 that router when performing the relevant check.
@@ -288,7 +291,7 @@ send queries for the ``auth`` app to ``auth_db``::
288 291
                return True
289 292
             return None
290 293
 
291  
-        def allow_syncdb(self, db, model):
  294
+        def allow_migrate(self, db, model):
292 295
             """
293 296
             Make sure the auth app only appears in the 'auth_db'
294 297
             database.
@@ -328,7 +331,7 @@ from::
328 331
                 return True
329 332
             return None
330 333
 
331  
-        def allow_syncdb(self, db, model):
  334
+        def allow_migrate(self, db, model):
332 335
             """
333 336
             All non-auth models end up in this pool.
334 337
             """
@@ -347,7 +350,7 @@ be queried in the order the are listed in the
347 350
 result, decisions concerning the models in ``auth`` are processed
348 351
 before any other decision is made. If the :setting:`DATABASE_ROUTERS`
349 352
 setting listed the two routers in the other order,
350  
-``MasterSlaveRouter.allow_syncdb()`` would be processed first. The
  353
+``MasterSlaveRouter.allow_migrate()`` would be processed first. The
351 354
 catch-all nature of the MasterSlaveRouter implementation would mean
352 355
 that all models would be available on all databases.
353 356
 
2  tests/cache/tests.py
@@ -895,7 +895,7 @@ def db_for_write(self, model, **hints):
895 895
         if model._meta.app_label == 'django_cache':
896 896
             return 'other'
897 897
 
898  
-    def allow_syncdb(self, db, model):
  898
+    def allow_migrate(self, db, model):
899 899
         if model._meta.app_label == 'django_cache':
900 900
             return db == 'other'
901 901
 
46  tests/multiple_database/tests.py
@@ -933,7 +933,7 @@ def db_for_write(self, model, **hints):
933 933
     def allow_relation(self, obj1, obj2, **hints):
934 934
         return obj1._state.db in ('default', 'other') and obj2._state.db in ('default', 'other')
935 935
 
936  
-    def allow_syncdb(self, db, model):
  936
+    def allow_migrate(self, db, model):
937 937
         return True
938 938
 
939 939
 class AuthRouter(object):
@@ -960,7 +960,7 @@ def allow_relation(self, obj1, obj2, **hints):
960 960
             return True
961 961
         return None
962 962
 
963  
-    def allow_syncdb(self, db, model):
  963
+    def allow_migrate(self, db, model):
964 964
         "Make sure the auth app only appears on the 'other' db"
965 965
         if db == 'other':
966 966
             return model._meta.app_label == 'auth'
@@ -1022,30 +1022,30 @@ def test_db_selection(self):
1022 1022
     def test_syncdb_selection(self):
1023 1023
         "Synchronization behavior is predictable"
1024 1024
 
1025  
-        self.assertTrue(router.allow_syncdb('default', User))
1026  
-        self.assertTrue(router.allow_syncdb('default', Book))
  1025
+        self.assertTrue(router.allow_migrate('default', User))
  1026
+        self.assertTrue(router.allow_migrate('default', Book))
1027 1027
 
1028  
-        self.assertTrue(router.allow_syncdb('other', User))
1029  
-        self.assertTrue(router.allow_syncdb('other', Book))
  1028
+        self.assertTrue(router.allow_migrate('other', User))
  1029
+        self.assertTrue(router.allow_migrate('other', Book))
1030 1030
 
1031 1031
         # Add the auth router to the chain.
1032 1032
         # TestRouter is a universal synchronizer, so it should have no effect.
1033 1033
         router.routers = [TestRouter(), AuthRouter()]
1034 1034
 
1035  
-        self.assertTrue(router.allow_syncdb('default', User))
1036  
-        self.assertTrue(router.allow_syncdb('default', Book))
  1035
+        self.assertTrue(router.allow_migrate('default', User))
  1036
+        self.assertTrue(router.allow_migrate('default', Book))
1037 1037
 
1038  
-        self.assertTrue(router.allow_syncdb('other', User))
1039  
-        self.assertTrue(router.allow_syncdb('other', Book))
  1038
+        self.assertTrue(router.allow_migrate('other', User))
  1039
+        self.assertTrue(router.allow_migrate('other', Book))
1040 1040
 
1041 1041
         # Now check what happens if the router order is the other way around
1042 1042
         router.routers = [AuthRouter(), TestRouter()]
1043 1043
 
1044  
-        self.assertFalse(router.allow_syncdb('default', User))
1045  
-        self.assertTrue(router.allow_syncdb('default', Book))
  1044
+        self.assertFalse(router.allow_migrate('default', User))
  1045
+        self.assertTrue(router.allow_migrate('default', Book))
1046 1046
 
1047  
-        self.assertTrue(router.allow_syncdb('other', User))
1048  
-        self.assertFalse(router.allow_syncdb('other', Book))
  1047
+        self.assertTrue(router.allow_migrate('other', User))
  1048
+        self.assertFalse(router.allow_migrate('other', Book))
1049 1049
 
1050 1050
     def test_partial_router(self):
1051 1051
         "A router can choose to implement a subset of methods"
@@ -1062,8 +1062,8 @@ def test_partial_router(self):
1062 1062
 
1063 1063
         self.assertTrue(router.allow_relation(dive, dive))
1064 1064
 
1065  
-        self.assertTrue(router.allow_syncdb('default', User))
1066  
-        self.assertTrue(router.allow_syncdb('default', Book))
  1065
+        self.assertTrue(router.allow_migrate('default', User))
  1066
+        self.assertTrue(router.allow_migrate('default', Book))
1067 1067
 
1068 1068
         router.routers = [WriteRouter(), AuthRouter(), TestRouter()]
1069 1069
 
@@ -1075,8 +1075,8 @@ def test_partial_router(self):
1075 1075
 
1076 1076
         self.assertTrue(router.allow_relation(dive, dive))
1077 1077
 
1078  
-        self.assertFalse(router.allow_syncdb('default', User))
1079  
-        self.assertTrue(router.allow_syncdb('default', Book))
  1078
+        self.assertFalse(router.allow_migrate('default', User))
  1079
+        self.assertTrue(router.allow_migrate('default', Book))
1080 1080
 
1081 1081
 
1082 1082
     def test_database_routing(self):
@@ -1607,12 +1607,12 @@ def test_auth_manager(self):
1607 1607
         self.assertEqual(User.objects.using('other').count(), 1)
1608 1608
 
1609 1609
     def test_dumpdata(self):
1610  
-        "Check that dumpdata honors allow_syncdb restrictions on the router"
  1610
+        "Check that dumpdata honors allow_migrate restrictions on the router"
1611 1611
         User.objects.create_user('alice', 'alice@example.com')
1612 1612
         User.objects.db_manager('default').create_user('bob', 'bob@example.com')
1613 1613
 
1614 1614
         # Check that dumping the default database doesn't try to include auth
1615  
-        # because allow_syncdb prohibits auth on default
  1615
+        # because allow_migrate prohibits auth on default
1616 1616
         new_io = StringIO()
1617 1617
         management.call_command('dumpdata', 'auth', format='json', database='default', stdout=new_io)
1618 1618
         command_output = new_io.getvalue().strip()
@@ -1625,10 +1625,10 @@ def test_dumpdata(self):
1625 1625
         self.assertTrue('"email": "alice@example.com"' in command_output)
1626 1626
 
1627 1627
 class AntiPetRouter(object):
1628  
-    # A router that only expresses an opinion on syncdb,
  1628
+    # A router that only expresses an opinion on migrate,
1629 1629
     # passing pets to the 'other' database
1630 1630
 
1631  
-    def allow_syncdb(self, db, model):
  1631
+    def allow_migrate(self, db, model):
1632 1632
         "Make sure the auth app only appears on the 'other' db"
1633 1633
         if db == 'other':
1634 1634
             return model._meta.object_name == 'Pet'
@@ -1917,7 +1917,7 @@ def test_foreignkey_collection(self):
1917 1917
 
1918 1918
 
1919 1919
 class SyncOnlyDefaultDatabaseRouter(object):
1920  
-    def allow_syncdb(self, db, model):
  1920
+    def allow_migrate(self, db, model):
1921 1921
         return db == DEFAULT_DB_ALIAS
1922 1922
 
1923 1923
 

0 notes on commit 12e9804

Please sign in to comment.
Something went wrong with that request. Please try again.