新增独立鉴权的 /api/v1/admin 与 Vue 控制台;会员授予与审计同事务,并补集成/单测。 Co-authored-by: Cursor <cursoragent@cursor.com>
34 lines
1.3 KiB
SQL
34 lines
1.3 KiB
SQL
-- Ops admin Phase A (ECR-006)
|
|
|
|
CREATE TABLE IF NOT EXISTS admin_accounts (
|
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
username varchar(64) NOT NULL UNIQUE,
|
|
password_hash text NOT NULL,
|
|
status varchar(32) NOT NULL DEFAULT 'active',
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
deleted_at timestamptz NULL
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS admin_sessions (
|
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
admin_id uuid NOT NULL REFERENCES admin_accounts(id),
|
|
token varchar(128) NOT NULL UNIQUE,
|
|
expires_at timestamptz NOT NULL,
|
|
created_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_admin_sessions_admin_id ON admin_sessions(admin_id);
|
|
CREATE INDEX IF NOT EXISTS idx_admin_sessions_expires ON admin_sessions(expires_at);
|
|
|
|
CREATE TABLE IF NOT EXISTS admin_audit_logs (
|
|
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
admin_id uuid NOT NULL REFERENCES admin_accounts(id),
|
|
action varchar(64) NOT NULL,
|
|
target_type varchar(32) NOT NULL DEFAULT '',
|
|
target_id varchar(64) NOT NULL DEFAULT '',
|
|
meta jsonb NOT NULL DEFAULT '{}',
|
|
created_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
CREATE INDEX IF NOT EXISTS idx_admin_audit_created ON admin_audit_logs(created_at DESC);
|
|
CREATE INDEX IF NOT EXISTS idx_admin_audit_admin ON admin_audit_logs(admin_id);
|