MariaDB 10.6 does not support functional indexes. Replace the LOWER(email) functional index with a plain unique index on email; case-insensitive uniqueness is enforced at the application layer. Paperclip-Agent: DevOps Engineer (urlKey devops-engineer; id 5d084b36-f38f-42a5-a92a-520005afda4f) Paperclip-Issue: BIT-277 Paperclip-Run: 7cc9257b-0d1a-475b-9133-8d0aa78d0f08 Co-Authored-By: Paperclip <[email protected]>
22 lines
1.1 KiB
SQL
22 lines
1.1 KiB
SQL
-- Migration 001: admin_users table (MariaDB / MySQL 8+)
|
|
-- Stores admin panel users with role-based access control.
|
|
-- Passwords are hashed with bcrypt (cost 12) — never store plaintext.
|
|
--
|
|
-- Roles: superadmin | admin | viewer (see api/src/types/auth.ts)
|
|
|
|
CREATE TABLE IF NOT EXISTS admin_users (
|
|
id CHAR(36) NOT NULL DEFAULT (UUID()) PRIMARY KEY,
|
|
email VARCHAR(320) NOT NULL,
|
|
password_hash VARCHAR(60) NOT NULL,
|
|
role VARCHAR(20) NOT NULL DEFAULT 'viewer'
|
|
CHECK (role IN ('superadmin', 'admin', 'viewer')),
|
|
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
|
created_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
|
|
updated_at DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6)
|
|
);
|
|
|
|
-- MariaDB <10.8 does not support functional indexes; enforce case-insensitive uniqueness
|
|
-- via a regular unique index on the column (app layer normalises email to lowercase on write).
|
|
CREATE UNIQUE INDEX IF NOT EXISTS admin_users_email_idx
|
|
ON admin_users (email);
|