Ticket #10236: change_syncdb_order.patch

File change_syncdb_order.patch, 3.6 KB (added by jbergstroem, 15 years ago)

Change the order of syncb actions

  • django/core/management/commands/syncdb.py

     
    100100        # The connection may have been closed by a syncdb handler.
    101101        cursor = connection.cursor()
    102102
     103        # Install SQL indicies for all newly created models
     104        for app in models.get_apps():
     105            app_name = app.__name__.split('.')[-2]
     106            for model in models.get_models(app):
     107                if model in created_models:
     108                    index_sql = connection.creation.sql_indexes_for_model(model, self.style)
     109                    if index_sql:
     110                        if verbosity >= 1:
     111                            print "Installing index for %s.%s model" % (app_name, model._meta.object_name)
     112                        try:
     113                            for sql in index_sql:
     114                                cursor.execute(sql)
     115                        except Exception, e:
     116                            sys.stderr.write("Failed to install index for %s.%s model: %s\n" % \
     117                                                (app_name, model._meta.object_name, e))
     118                            transaction.rollback_unless_managed()
     119                        else:
     120                            transaction.commit_unless_managed()
     121
    103122        # Install custom SQL for the app (but only if this
    104123        # is a model we've just created)
    105124        for app in models.get_apps():
     
    125144                    else:
    126145                        if verbosity >= 2:
    127146                            print "No custom SQL for %s.%s model" % (app_name, model._meta.object_name)
    128         # Install SQL indicies for all newly created models
    129         for app in models.get_apps():
    130             app_name = app.__name__.split('.')[-2]
    131             for model in models.get_models(app):
    132                 if model in created_models:
    133                     index_sql = connection.creation.sql_indexes_for_model(model, self.style)
    134                     if index_sql:
    135                         if verbosity >= 1:
    136                             print "Installing index for %s.%s model" % (app_name, model._meta.object_name)
    137                         try:
    138                             for sql in index_sql:
    139                                 cursor.execute(sql)
    140                         except Exception, e:
    141                             sys.stderr.write("Failed to install index for %s.%s model: %s\n" % \
    142                                                 (app_name, model._meta.object_name, e))
    143                             transaction.rollback_unless_managed()
    144                         else:
    145                             transaction.commit_unless_managed()
    146147
    147148        # Install the 'initial_data' fixture, using format discovery
    148149        from django.core.management import call_command
  • django/core/management/sql.py

     
    153153    return output
    154154
    155155def sql_all(app, style):
    156     "Returns a list of CREATE TABLE SQL, initial-data inserts, and CREATE INDEX SQL for the given module."
    157     return sql_create(app, style) + sql_custom(app, style) + sql_indexes(app, style)
     156    "Returns a list of CREATE TABLE SQL, CREATE INDEX SQL and custom SQL for the given module."
     157    return sql_create(app, style) + sql_indexes(app, style) + sql_custom(app, style)
    158158
    159159def custom_sql_for_model(model, style):
    160160    from django.db import models
Back to Top