feat: add Sense identity RBAC and audit (#22)

This commit is contained in:
QiuSW
2026-08-12 17:06:26 +08:00
parent 2c0e37eff7
commit b9416ebc08
24 changed files with 1438 additions and 11 deletions
@@ -0,0 +1,27 @@
CREATE TABLE IF NOT EXISTS sense_identity_users (
id TEXT PRIMARY KEY,
username TEXT NOT NULL UNIQUE,
display_name TEXT NOT NULL,
role TEXT NOT NULL,
enabled BOOLEAN NOT NULL DEFAULT TRUE,
password_hash TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL,
updated_at TIMESTAMPTZ NOT NULL
);
CREATE TABLE IF NOT EXISTS sense_identity_sessions (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL REFERENCES sense_identity_users(id),
expires_at TIMESTAMPTZ NOT NULL,
revoked_at TIMESTAMPTZ NULL
);
CREATE TABLE IF NOT EXISTS sense_identity_audit (
id TEXT PRIMARY KEY,
actor_id TEXT NULL REFERENCES sense_identity_users(id),
action TEXT NOT NULL,
target TEXT NOT NULL DEFAULT '',
outcome TEXT NOT NULL,
metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
created_at TIMESTAMPTZ NOT NULL
);
CREATE INDEX IF NOT EXISTS sense_identity_audit_created_idx ON sense_identity_audit(created_at DESC);