Commits

Andrew Godwin  committed 2273d71

Fix #371 (--database not actually taking)

  • Participants
  • Parent commits 8ee701c

Comments (0)

Files changed (3)

File south/migration/__init__.py

     if database != DEFAULT_DB_ALIAS:
         applied = applied.using(database)
         south.db.db = south.db.dbs[database]
+        # We now have to make sure the migrations are all reloaded, as they'll
+        # have imported the old value of south.db.db.
+        Migrations.invalidate_all_modules()
     applied = check_migration_histories(applied, delete_ghosts)
     
     # Guess the target_name

File south/migration/base.py

             for migration in migrations:
                 migration.calculate_dependencies()
     
+    @staticmethod
+    def invalidate_all_modules():
+        "Goes through all the migrations, and invalidates all cached modules."
+        for migrations in all_migrations():
+            for migration in migrations:
+                migration.invalidate_module()
+    
     def next_filename(self, name):
         "Returns the fully-formatted filename of what a new migration 'name' would be"
         highest_number = 0
         if previous:
             self.dependencies.add(previous)
             previous.dependents.add(self)
+    
+    def invalidate_module(self):
+        """
+        Removes the cached version of this migration's module import, so we
+        have to re-import it. Used when south.db.db changes.
+        """
+        reload(self.migration())
+        self.migration._invalidate()
 
     def forwards(self):
         return self.migration_instance().forwards

File south/utils.py

     return getattr(model._meta, "auto_created", False)
 
 def memoize(function):
+    "Standard memoization decorator."
     name = function.__name__
     _name = '_' + name
+    
     def method(self):
         if not hasattr(self, _name):
             value = function(self)
             setattr(self, _name, value)
         return getattr(self, _name)
+    
+    def invalidate():
+        if hasattr(method, _name):
+            delattr(method, _name)
+        
     method.__name__ = function.__name__
     method.__doc__ = function.__doc__
+    method._invalidate = invalidate
     return method