a6cc41666e
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
17 lines
772 B
SQL
17 lines
772 B
SQL
CREATE TABLE IF NOT EXISTS user_sessions (
|
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
public_id CHAR(32) NOT NULL UNIQUE,
|
|
user_id INT NOT NULL,
|
|
ip VARCHAR(45) NULL,
|
|
user_agent VARCHAR(512) NULL,
|
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
last_seen_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
expires_at DATETIME NOT NULL,
|
|
revoked_at DATETIME NULL,
|
|
revoked_by INT NULL,
|
|
revoke_reason VARCHAR(32) NULL,
|
|
INDEX idx_user_sessions_user (user_id, revoked_at, expires_at),
|
|
CONSTRAINT fk_user_sessions_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
CONSTRAINT fk_user_sessions_revoked_by FOREIGN KEY (revoked_by) REFERENCES users(id) ON DELETE SET NULL
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|