1 from forum.modules import get_modules_script
3 get_modules_script('management')
5 from django.db.models.signals import post_syncdb
8 def post_syncdb_callback(sender, **kwargs):
9 # Import the needed libraries to use the database and detect the
10 # DB engine/sever type being currently employed.
11 from django.db import connection, connections
13 verbosity = int(kwargs["verbosity"])
15 # Get the DB engine being used for persistence for this app.
16 current_db_engine = connections.databases[connection.alias]['ENGINE']
18 # Make sure the updates are only executed for a MySQL DB.
19 if current_db_engine.find("mysql") > 0:
20 # Ok, mysql was found in the engine description. Go ahead
21 # and attempt to execute the alter table statements.
22 cursor = connection.cursor()
24 # Pair the table names with the columns that need to be updated.
25 updatable_table_columns = {
27 "auth_user": "username"
30 # Update each column in turn.
31 for table_name, column_name in updatable_table_columns.iteritems():
32 alter_table_statement = "ALTER TABLE %(table_name)s MODIFY %(column_name)s varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL;" % {
33 "table_name": table_name, "column_name": column_name}
34 log_status(verbosity,"Updating MySQL column with this statement: " + alter_table_statement)
35 cursor.execute(alter_table_statement)
37 def log_status(verbosity, message):
39 print "[DEBUG] " + str(message)
41 # Link the callback to the post_syncdb signal.
42 post_syncdb.connect(post_syncdb_callback, sender=forum.models)