Files
pnpaas-adm/app/database/migrations/001_account_activation.sql
T

21 lines
922 B
SQL

-- Run once against an existing PnPaaS database.
-- Existing active/suspended accounts remain unchanged.
ALTER TABLE users
MODIFY status ENUM('pending', 'active', 'suspended') NOT NULL DEFAULT 'pending';
CREATE TABLE IF NOT EXISTS account_activation_tokens (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
user_id BIGINT UNSIGNED NOT NULL,
token_hash CHAR(64) NOT NULL,
expires_at DATETIME NOT NULL,
used_at DATETIME NULL,
requested_ip VARCHAR(45) NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY uq_account_activation_token_hash (token_hash),
KEY idx_account_activation_user (user_id),
KEY idx_account_activation_expiry (expires_at),
CONSTRAINT fk_account_activation_user FOREIGN KEY (user_id) REFERENCES users (id)
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;