04/22 Upgraded code commit
This commit is contained in:
@@ -245,6 +245,15 @@ def initialize_database():
|
||||
INDEX idx_username_time (username, attempted_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
""",
|
||||
"""
|
||||
CREATE TABLE IF NOT EXISTS website_users (
|
||||
website_id INT NOT NULL,
|
||||
user_id INT NOT NULL,
|
||||
PRIMARY KEY (website_id, user_id),
|
||||
FOREIGN KEY (website_id) REFERENCES websites(id) ON DELETE CASCADE,
|
||||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
""",
|
||||
]
|
||||
|
||||
conn = None
|
||||
@@ -294,6 +303,24 @@ def initialize_database():
|
||||
conn.commit()
|
||||
logger.info("Migration: added failed_attempts and locked_until columns to users table.")
|
||||
|
||||
# Add visibility column to websites if it doesn't exist
|
||||
cursor.execute(
|
||||
"""
|
||||
SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = 'websites'
|
||||
AND COLUMN_NAME = 'visibility'
|
||||
"""
|
||||
)
|
||||
(has_vis,) = cursor.fetchone()
|
||||
if not has_vis:
|
||||
cursor.execute(
|
||||
"ALTER TABLE websites ADD COLUMN visibility "
|
||||
"ENUM('all','assigned') NOT NULL DEFAULT 'all' AFTER check_type"
|
||||
)
|
||||
conn.commit()
|
||||
logger.info("Migration: added visibility column to websites table.")
|
||||
|
||||
# Seed default admin if users table is empty
|
||||
cursor.execute("SELECT COUNT(*) FROM users")
|
||||
(count,) = cursor.fetchone()
|
||||
|
||||
Reference in New Issue
Block a user