05/24 Fix bugs

This commit is contained in:
2026-05-24 17:27:45 -04:00
parent cd63d5a020
commit 136b0e5635
14 changed files with 158 additions and 68 deletions
+40 -1
View File
@@ -189,7 +189,8 @@ def initialize_database():
entity VARCHAR(100),
entity_id INT,
detail TEXT,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
logged_at DATETIME DEFAULT CURRENT_TIMESTAMP,
INDEX idx_activity_log_time (logged_at),
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
""",
@@ -347,6 +348,44 @@ def initialize_database():
conn.commit()
logger.info("Migration: added ip_address column to login_attempts table.")
# ── activity_log: rename created_at → logged_at ────────────────
# The desktop app uses logged_at; earlier web-only installs may have
# created the table with created_at. Rename it if that's the case.
cursor.execute(
"""
SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'activity_log'
AND COLUMN_NAME = 'created_at'
"""
)
(has_created_at,) = cursor.fetchone()
if has_created_at:
cursor.execute(
"ALTER TABLE activity_log "
"CHANGE COLUMN created_at logged_at DATETIME DEFAULT CURRENT_TIMESTAMP"
)
conn.commit()
logger.info("Migration: renamed activity_log.created_at to logged_at.")
# ── activity_log: add index on logged_at if missing ────────────
cursor.execute(
"""
SELECT COUNT(*) FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'activity_log'
AND INDEX_NAME = 'idx_activity_log_time'
"""
)
(has_idx,) = cursor.fetchone()
if not has_idx:
cursor.execute(
"ALTER TABLE activity_log "
"ADD INDEX idx_activity_log_time (logged_at)"
)
conn.commit()
logger.info("Migration: added idx_activity_log_time index to activity_log.")
# ── Seed app_settings from environment variables (first-run bootstrap) ─
# Uses INSERT IGNORE so values already saved via the Admin UI are never
# overwritten — .env only fills in keys that are completely absent.