06/03 Optimize app
This commit is contained in:
@@ -24,6 +24,20 @@ COLUMNS = [
|
||||
"DATETIME NULL DEFAULT NULL"),
|
||||
]
|
||||
|
||||
CREATE_TABLES = [
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS audit_logs (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
timestamp DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
action VARCHAR(64) NOT NULL,
|
||||
description VARCHAR(255),
|
||||
ip_address VARCHAR(45),
|
||||
INDEX ix_audit_logs_timestamp (timestamp),
|
||||
INDEX ix_audit_logs_action (action)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
||||
"""
|
||||
]
|
||||
|
||||
with app.app_context():
|
||||
with db.engine.connect() as conn:
|
||||
for table, column, definition in COLUMNS:
|
||||
@@ -42,4 +56,9 @@ with app.app_context():
|
||||
conn.commit()
|
||||
print(f" Added {table}.{column}.")
|
||||
|
||||
for sql in CREATE_TABLES:
|
||||
conn.execute(db.text(sql))
|
||||
conn.commit()
|
||||
print(" Created audit_logs table (or already exists).")
|
||||
|
||||
print("Done.")
|
||||
|
||||
Reference in New Issue
Block a user