Add python script for applying migrations

This commit is contained in:
Peter Stockings
2025-12-02 16:30:34 +11:00
parent 416f6d423d
commit d983854c7c
2 changed files with 71 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
-- Create login_history table to track user logins
CREATE TABLE IF NOT EXISTS login_history (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
login_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
ip_address VARCHAR(45), -- IPv6 max length is 45 characters
user_agent TEXT,
success BOOLEAN NOT NULL DEFAULT TRUE,
failure_reason VARCHAR(255)
);
-- Create index on user_id for faster queries
CREATE INDEX IF NOT EXISTS idx_login_history_user_id ON login_history(user_id);
-- Create index on login_time for sorting
CREATE INDEX IF NOT EXISTS idx_login_history_login_time ON login_history(login_time DESC);