交付双端基础、实时联系人和隔离浏览器

This commit is contained in:
xhgit committed 2026-11-13 18:03:32 +08:00
1 parent 43687d5e7e
commit 67fef3ff87
59 files changed
+5094 -1

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
CREATE TABLE users (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
username text UNIQUE NOT NULL CHECK (username ~ '^[a-z0-9_]{3,32}$'),
password_hash text NOT NULL,
created_at timestamptz NOT NULL DEFAULT now()
);
CREATE TABLE devices (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
public_key bytea NOT NULL CHECK (octet_length(public_key) = 32),
name text NOT NULL,
platform text NOT NULL CHECK (platform IN ('web', 'windows')),
created_at timestamptz NOT NULL DEFAULT now(),
last_active_at timestamptz NOT NULL DEFAULT now(),
revoked_at timestamptz,
UNIQUE (user_id, public_key)
);
CREATE TABLE sessions (
token_hash bytea PRIMARY KEY CHECK (octet_length(token_hash) = 32),
device_id uuid NOT NULL REFERENCES devices(id) ON DELETE CASCADE,
expires_at timestamptz NOT NULL
);
CREATE INDEX sessions_device ON sessions(device_id);
CREATE INDEX sessions_expiry ON sessions(expires_at);