2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 16:51:54 +00:00

Speed up migrations and init

This commit is contained in:
Philip Sargent 2020-07-22 23:43:07 +01:00
parent 3e3cae507c
commit 721341604c

View File

@ -85,19 +85,21 @@ def reinit_db():
else: else:
print(" - No database file found: " + currentdbname + " ..continuing, will create it.\n") print(" - No database file found: " + currentdbname + " ..continuing, will create it.\n")
else: else:
cursor = django.db.connection.cursor() with transaction.atomic():
cursor.execute("DROP DATABASE %s" % currentdbname) cursor = django.db.connection.cursor()
cursor.execute("CREATE DATABASE %s" % currentdbname) cursor.execute("DROP DATABASE %s" % currentdbname)
cursor.execute("ALTER DATABASE %s CHARACTER SET=utf8" % currentdbname) cursor.execute("CREATE DATABASE %s" % currentdbname)
cursor.execute("USE %s" % currentdbname) cursor.execute("ALTER DATABASE %s CHARACTER SET=utf8" % currentdbname)
cursor.execute("USE %s" % currentdbname)
print(" - Migrating: " + django.db.connections.databases['default']['NAME']) print(" - Migrating: " + django.db.connections.databases['default']['NAME'])
management.call_command('makemigrations','core', interactive=False) with transaction.atomic():
management.call_command('makemigrations','flatpages', interactive=False) management.call_command('makemigrations','core', interactive=False)
management.call_command('migrate', interactive=False) management.call_command('makemigrations','flatpages', interactive=False)
management.call_command('migrate','core', interactive=False) management.call_command('migrate', interactive=False)
management.call_command('migrate','flatpages', interactive=False) management.call_command('migrate','core', interactive=False)
management.call_command('migrate','flatpages', interactive=False)
print(" - done migration on: " + settings.DATABASES['default']['NAME']) print(" - done migration on: " + settings.DATABASES['default']['NAME'])
print("users in db already: ",len(User.objects.all())) print("users in db already: ",len(User.objects.all()))