Commits

and...@69d324d9-c39d-4fdc-8679-7745eae9e2c8  committed 313896d

Working MySQLness! And proper ./manage.py test integration

  • Participants
  • Parent commits b801cb8

Comments (0)

Files changed (3)

File db/generic.py

         cursor = connection.cursor()
         if self.debug:
             print "   = %s" % sql, params
-        return cursor.execute(sql, params)
+        cursor.execute(sql, params)
+        return cursor.fetchall()
 
 
     def get_column_value(self, column, name):
         
         qn = connection.ops.quote_name
         
-        params = (qn(table_name), qn(old), qn(new))
-        self.execute('ALTER TABLE %s CHANGE COLUMN %s %s;' % params)
+        rows = [x for x in self.execute('DESCRIBE %s' % (qn(table_name),)) if x[0] == old]
+        
+        if not rows:
+            raise ValueError("No column '%s' in '%s'." % (old, table_name))
+        
+        params = (
+            qn(table_name),
+            qn(old),
+            qn(new),
+            "%s %s %s %s %s" % (
+                rows[0][1],
+                rows[0][2] == "YES" and "NULL" or "NOT NULL",
+                rows[0][3] == "PRI" and "PRIMARY KEY" or "",
+                rows[0][4] and "DEFAULT %s" % rows[0][4] or "",
+                rows[0][5] or "",
+            ),
+        )
+        self.execute('ALTER TABLE %s CHANGE COLUMN %s %s %s;' % params)
 
 
     def rename_table(self, old_table_name, table_name):

File management/commands/syncdb.py

 from django.conf import settings
 from django.db import models
 from django.db.models.loading import cache
+from django.core import management
 import sys
 
 def get_app_name(app):
             help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'),
         make_option('--noinput', action='store_false', dest='interactive', default=True,
             help='Tells Django to NOT prompt the user for input of any kind.'),
+        make_option('--migrate', action='store_true', dest='migrate', default=False,
+            help='Tells South to also perform migrations after the sync. Default for during testing, and other internal calls.'),
     )
     help = "Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created, except those which use migrations."
 
                 # This is a migrated app, leave it
                 apps_migrated.append(app_name)
         # Run syncdb on only the ones needed
+        print "Syncing..."
         old_installed, settings.INSTALLED_APPS = settings.INSTALLED_APPS, apps_needing_sync
         old_app_store, cache.app_store = cache.app_store, SortedDict([
             (k, v) for (k, v) in cache.app_store.items()
         syncdb.Command().execute(**options)
         settings.INSTALLED_APPS = old_installed
         cache.app_store = old_app_store
+        # Migrate if needed
+        if options.get('migrate', True):
+            print "Migrating..."
+            management.call_command('migrate')
         # Be obvious about what we did
         print "\nSynced:\n > %s" % "\n > ".join(apps_needing_sync)
-        print "\nNot synced (use migrations):\n - %s" % "\n - ".join(apps_migrated)
-        print "(use ./manage.py migrate to migrate these)"
+        
+        if options.get('migrate', True):
+            print "\nMigrated:\n - %s" % "\n - ".join(apps_migrated)
+        else:
+            print "\nNot synced (use migrations):\n - %s" % "\n - ".join(apps_migrated)
+            print "(use ./manage.py migrate to migrate these)"