CREATE TABLE users (
 id BIGINT AUTO_INCREMENT PRIMARY KEY,
 nickname VARCHAR(80) NOT NULL UNIQUE,
 nickname_key VARCHAR(80) NOT NULL UNIQUE,
 email VARCHAR(320) NOT NULL,
 email_key VARCHAR(320) NOT NULL UNIQUE,
 password_hash TEXT NOT NULL,
 created_at VARCHAR(64) NOT NULL DEFAULT (CURRENT_TIMESTAMP),
 updated_at VARCHAR(64) NOT NULL DEFAULT (CURRENT_TIMESTAMP)
) ENGINE=InnoDB;
CREATE TABLE user_sessions (
 token VARCHAR(128) PRIMARY KEY,
 user_id BIGINT NOT NULL,
 expires_at VARCHAR(64) NOT NULL,
 created_at VARCHAR(64) NOT NULL DEFAULT (CURRENT_TIMESTAMP),
 CONSTRAINT fk_user_sessions_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
 INDEX idx_user_sessions_user (user_id)
) ENGINE=InnoDB;
CREATE TABLE password_reset_tokens (
 token VARCHAR(128) PRIMARY KEY,
 user_id BIGINT NOT NULL,
 expires_at VARCHAR(64) NOT NULL,
 used_at VARCHAR(64),
 created_at VARCHAR(64) NOT NULL DEFAULT (CURRENT_TIMESTAMP),
 CONSTRAINT fk_password_reset_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
 INDEX idx_password_reset_user (user_id)
) ENGINE=InnoDB;
