mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-16 22:57:14 +00:00
use AI to redo MariaDB reinit
This commit is contained in:
@@ -119,39 +119,19 @@ def reinit_db():
|
||||
else:
|
||||
print(" - No database file found: " + currentdbname + " ..continuing, will create it.\n")
|
||||
else:
|
||||
print(f" - Attempting to nuke : {currentdbname}\n")
|
||||
# this is now completely failing to nuke MariaDB adequately, and it crashes when creating Area objects with a no null parent message
|
||||
# when null parents are explciitly allowed in the model.
|
||||
cursor = django.db.connection.cursor()
|
||||
print(f" - - Using {cursor}")
|
||||
try:
|
||||
cursor.execute(f"DROP DATABASE {currentdbname}")
|
||||
except:
|
||||
print(f" - - Exception when attempting to: DROP DATABASE {currentdbname} with {cursor}")
|
||||
pass
|
||||
try:
|
||||
cursor.execute(f"CREATE DATABASE {currentdbname}")
|
||||
except:
|
||||
print(f" - - Exception when attempting to: CREATE DATABASE {currentdbname} with {cursor}")
|
||||
pass
|
||||
try:
|
||||
cursor.execute(f"ALTER DATABASE {currentdbname} CHARACTER SET=utf8")
|
||||
except:
|
||||
print(f" - - Exception when attempting to: ALTER DATABASE {currentdbname} CHARACTER SET=utf8")
|
||||
pass
|
||||
try:
|
||||
cursor.execute(f"USE {currentdbname}")
|
||||
except:
|
||||
print(f" - - Exception when attempting to: USE {currentdbname}")
|
||||
pass
|
||||
try:
|
||||
cmd = flush.Command()
|
||||
call_command(cmd, verbosity=0, interactive=False)
|
||||
except:
|
||||
print(f" - - Exception when attempting to: FLUSH")
|
||||
pass
|
||||
print(f" - Nuked : {currentdbname}\n")
|
||||
|
||||
print(f" - Attempting to drop all tables in: {currentdbname}\n")
|
||||
with django.db.connection.cursor() as cursor:
|
||||
print(f" - - Using {cursor}")
|
||||
# Disable foreign key checks so we can drop tables in any order
|
||||
cursor.execute("SET FOREIGN_KEY_CHECKS = 0;")
|
||||
# Get all table names
|
||||
cursor.execute("SHOW TABLES;")
|
||||
tables = [row[0] for row in cursor.fetchall()]
|
||||
for table in tables:
|
||||
print(f" - Dropping table: {table}")
|
||||
cursor.execute(f"DROP TABLE IF EXISTS `{table}`;")
|
||||
cursor.execute("SET FOREIGN_KEY_CHECKS = 1;")
|
||||
print(f" - All tables dropped in: {currentdbname}\n")
|
||||
print(" - Migrating: " + django.db.connections.databases["default"]["NAME"])
|
||||
|
||||
if django.db.connections.databases["default"]["ENGINE"] == "django.db.backends.sqlite3":
|
||||
|
||||
Reference in New Issue
Block a user