mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-18 10:47:08 +00:00
use AI to redo MariaDB reinit
This commit is contained in:
@@ -119,39 +119,19 @@ 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:
|
||||||
print(f" - Attempting to nuke : {currentdbname}\n")
|
print(f" - Attempting to drop all tables in: {currentdbname}\n")
|
||||||
# this is now completely failing to nuke MariaDB adequately, and it crashes when creating Area objects with a no null parent message
|
with django.db.connection.cursor() as cursor:
|
||||||
# when null parents are explciitly allowed in the model.
|
print(f" - - Using {cursor}")
|
||||||
cursor = django.db.connection.cursor()
|
# Disable foreign key checks so we can drop tables in any order
|
||||||
print(f" - - Using {cursor}")
|
cursor.execute("SET FOREIGN_KEY_CHECKS = 0;")
|
||||||
try:
|
# Get all table names
|
||||||
cursor.execute(f"DROP DATABASE {currentdbname}")
|
cursor.execute("SHOW TABLES;")
|
||||||
except:
|
tables = [row[0] for row in cursor.fetchall()]
|
||||||
print(f" - - Exception when attempting to: DROP DATABASE {currentdbname} with {cursor}")
|
for table in tables:
|
||||||
pass
|
print(f" - Dropping table: {table}")
|
||||||
try:
|
cursor.execute(f"DROP TABLE IF EXISTS `{table}`;")
|
||||||
cursor.execute(f"CREATE DATABASE {currentdbname}")
|
cursor.execute("SET FOREIGN_KEY_CHECKS = 1;")
|
||||||
except:
|
print(f" - All tables dropped in: {currentdbname}\n")
|
||||||
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(" - Migrating: " + django.db.connections.databases["default"]["NAME"])
|
print(" - Migrating: " + django.db.connections.databases["default"]["NAME"])
|
||||||
|
|
||||||
if django.db.connections.databases["default"]["ENGINE"] == "django.db.backends.sqlite3":
|
if django.db.connections.databases["default"]["ENGINE"] == "django.db.backends.sqlite3":
|
||||||
|
|||||||
Reference in New Issue
Block a user