Files
errors.bitreport.pt/db/migrations/001_admin_users.sql
T
1sonhadorandPaperclip 4604606033 feat(errors): migrate error-reporting stack from PostgreSQL to MariaDB (BIT-255)
Replace Postgres with MariaDB 11 in docker-compose; convert all
database/error_reporting and db/migrations SQL to InnoDB-friendly syntax
(DATETIME(6), AUTO_INCREMENT, ON DUPLICATE KEY). Run admin portal DDL in the
same migrate one-shot as error_reporting.

Switch ingest-api, collector-worker, and api from pg to mysql2 (pools,
parameterized queries, transactions). Align ingest writes with
er_incident_occurrences and include project_id on idempotency inserts.

Add scripts/run-mysql-migrations.sh for host-side applies; update LXC
run-migrate/verify, deployment docs, and .env.example (mysql://, ER_MYSQL_*).

Verified: npm run build + npm test in ingest-api and collector-worker;
npm run build in api. Full docker compose not run here (no local daemon).

Co-Authored-By: Paperclip <[email protected]>
2026-03-22 19:29:11 +00:00

20 lines
922 B
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)
);
CREATE UNIQUE INDEX IF NOT EXISTS admin_users_email_idx
ON admin_users ((LOWER(email)));