Add python script for applying migrations
This commit is contained in:
16
migrations/003_create_login_history.sql
Normal file
16
migrations/003_create_login_history.sql
Normal 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);
|
||||
Reference in New Issue
Block a user