Checkpoint sql work.

This commit is contained in:
2025-11-16 21:54:28 -08:00
parent c8a6830a80
commit e36acfbde2
7 changed files with 401 additions and 1 deletions

37
schema.sql Normal file
View File

@@ -0,0 +1,37 @@
-- MCIAS SQLite schema (initial)
PRAGMA foreign_keys = ON;
CREATE TABLE IF NOT EXISTS users (
id TEXT PRIMARY KEY,
username TEXT NOT NULL UNIQUE,
type TEXT NOT NULL CHECK (type IN ('human','system')),
pwd_hash TEXT NOT NULL,
totp_secret TEXT,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS roles (
name TEXT PRIMARY KEY
);
CREATE TABLE IF NOT EXISTS user_roles (
user_id TEXT NOT NULL,
role TEXT NOT NULL,
PRIMARY KEY (user_id, role),
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (role) REFERENCES roles(name) ON DELETE CASCADE
);
-- Service account token registry (one token per service account)
CREATE TABLE IF NOT EXISTS service_tokens (
service TEXT PRIMARY KEY,
token TEXT NOT NULL,
issued_at INTEGER NOT NULL,
revoked_at INTEGER
);
-- Migration version tracking
CREATE TABLE IF NOT EXISTS schema_migrations (
version INTEGER PRIMARY KEY
);