mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-01 09:24:46 +00:00
feat(pwa): move app.logicsrc.com from Turso/libSQL to Postgres via @profullstack/libsql-pg (#218)
Production reads DATABASE_URL (postgres://) through @profullstack/libsql-pg, which keeps the @libsql/client surface; no query changed. A missing, non-Postgres or leftover libsql:// URL fails at boot in production. Dev and tests keep libSQL (file:/:memory:) as a devDependency. Postgres migrations in src/migrations-pg/ (converted with libsql-pg convert-schema, same file names so the copied _migrations ledger matches); migrate.mjs picks the dialect. Tests run against Postgres with PWA_TEST_DATABASE_URL. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
c535aaa32c
commit
4ac750e65b
12 changed files with 507 additions and 29 deletions
53
apps/pwa/src/migrations-pg/001_auth.sql
Normal file
53
apps/pwa/src/migrations-pg/001_auth.sql
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
-- Converted from SQLite by @profullstack/libsql-pg. Review every TODO before applying.
|
||||
-- Types: INTEGER -> bigint, REAL -> double precision, BLOB -> bytea, BOOLEAN -> boolean,
|
||||
-- DATETIME/TIMESTAMP -> timestamptz, TEXT -> text; INTEGER PRIMARY KEY -> identity.
|
||||
|
||||
create table if not exists users (
|
||||
id text PRIMARY KEY,
|
||||
email text UNIQUE,
|
||||
password_hash text,
|
||||
coinpay_sub text UNIQUE,
|
||||
display_name text,
|
||||
created_at bigint NOT NULL
|
||||
);
|
||||
|
||||
create table if not exists webauthn_credentials (
|
||||
id text PRIMARY KEY,
|
||||
user_id text NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
public_key text NOT NULL,
|
||||
counter bigint NOT NULL DEFAULT 0,
|
||||
transports text,
|
||||
created_at bigint NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_webauthn_user ON webauthn_credentials(user_id);
|
||||
|
||||
create table if not exists sessions (
|
||||
token text PRIMARY KEY,
|
||||
user_id text NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
created_at bigint NOT NULL,
|
||||
expires_at bigint NOT NULL
|
||||
);
|
||||
|
||||
create table if not exists api_keys (
|
||||
id text PRIMARY KEY,
|
||||
user_id text NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
name text,
|
||||
token_hash text NOT NULL,
|
||||
prefix text NOT NULL,
|
||||
created_at bigint NOT NULL,
|
||||
last_used_at bigint
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_apikeys_user ON api_keys(user_id);
|
||||
|
||||
create table if not exists cli_auth_codes (
|
||||
code text PRIMARY KEY,
|
||||
user_id text NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
code_challenge text NOT NULL,
|
||||
redirect_uri text NOT NULL,
|
||||
name text,
|
||||
used bigint NOT NULL DEFAULT 0,
|
||||
created_at bigint NOT NULL,
|
||||
expires_at bigint NOT NULL
|
||||
);
|
||||
89
apps/pwa/src/migrations-pg/002_credshare.sql
Normal file
89
apps/pwa/src/migrations-pg/002_credshare.sql
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
-- Converted from SQLite by @profullstack/libsql-pg. Review every TODO before applying.
|
||||
-- Types: INTEGER -> bigint, REAL -> double precision, BLOB -> bytea, BOOLEAN -> boolean,
|
||||
-- DATETIME/TIMESTAMP -> timestamptz, TEXT -> text; INTEGER PRIMARY KEY -> identity.
|
||||
|
||||
create table if not exists credshare_keys (
|
||||
user_id text PRIMARY KEY REFERENCES users(id) ON DELETE CASCADE,
|
||||
public_key text NOT NULL,
|
||||
updated_at bigint NOT NULL
|
||||
);
|
||||
|
||||
create table if not exists credshare_teams (
|
||||
id text PRIMARY KEY,
|
||||
slug text NOT NULL UNIQUE,
|
||||
name text NOT NULL,
|
||||
created_by text NOT NULL REFERENCES users(id),
|
||||
created_at bigint NOT NULL
|
||||
);
|
||||
|
||||
create table if not exists credshare_members (
|
||||
id text PRIMARY KEY,
|
||||
team_id text NOT NULL REFERENCES credshare_teams(id) ON DELETE CASCADE,
|
||||
user_id text REFERENCES users(id) ON DELETE SET NULL,
|
||||
email text NOT NULL,
|
||||
role text NOT NULL DEFAULT 'member',
|
||||
status text NOT NULL DEFAULT 'invited',
|
||||
invited_by text REFERENCES users(id),
|
||||
joined_at bigint,
|
||||
created_at bigint NOT NULL,
|
||||
UNIQUE(team_id, email)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_credshare_members_team ON credshare_members(team_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_credshare_members_user ON credshare_members(user_id);
|
||||
|
||||
create table if not exists credshare_invites (
|
||||
id text PRIMARY KEY,
|
||||
team_id text NOT NULL REFERENCES credshare_teams(id) ON DELETE CASCADE,
|
||||
email text NOT NULL,
|
||||
role text NOT NULL DEFAULT 'member',
|
||||
token_hash text NOT NULL UNIQUE,
|
||||
created_by text NOT NULL REFERENCES users(id),
|
||||
expires_at bigint NOT NULL,
|
||||
accepted_at bigint,
|
||||
created_at bigint NOT NULL
|
||||
);
|
||||
|
||||
create table if not exists credshare_vaults (
|
||||
id text PRIMARY KEY,
|
||||
team_id text NOT NULL REFERENCES credshare_teams(id) ON DELETE CASCADE,
|
||||
name text NOT NULL,
|
||||
created_by text NOT NULL REFERENCES users(id),
|
||||
created_at bigint NOT NULL,
|
||||
UNIQUE(team_id, name)
|
||||
);
|
||||
|
||||
create table if not exists credshare_vault_grants (
|
||||
vault_id text NOT NULL REFERENCES credshare_vaults(id) ON DELETE CASCADE,
|
||||
user_id text NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
wrapped_dek text NOT NULL,
|
||||
granted_by text NOT NULL REFERENCES users(id),
|
||||
created_at bigint NOT NULL,
|
||||
PRIMARY KEY (vault_id, user_id)
|
||||
);
|
||||
|
||||
create table if not exists credshare_secrets (
|
||||
vault_id text NOT NULL REFERENCES credshare_vaults(id) ON DELETE CASCADE,
|
||||
name text NOT NULL,
|
||||
nonce text NOT NULL,
|
||||
ciphertext text NOT NULL,
|
||||
fingerprint text NOT NULL,
|
||||
version bigint NOT NULL,
|
||||
updated_by text NOT NULL REFERENCES users(id),
|
||||
updated_at bigint NOT NULL,
|
||||
PRIMARY KEY (vault_id, name)
|
||||
);
|
||||
|
||||
create table if not exists credshare_audit (
|
||||
id text PRIMARY KEY,
|
||||
team_id text,
|
||||
vault_id text,
|
||||
actor_user_id text NOT NULL REFERENCES users(id),
|
||||
action text NOT NULL,
|
||||
key_name text,
|
||||
fingerprint text,
|
||||
created_at bigint NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_credshare_audit_vault ON credshare_audit(vault_id, created_at DESC);
|
||||
16
apps/pwa/src/migrations-pg/003_cli_device_codes.sql
Normal file
16
apps/pwa/src/migrations-pg/003_cli_device_codes.sql
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
-- Converted from SQLite by @profullstack/libsql-pg. Review every TODO before applying.
|
||||
-- Types: INTEGER -> bigint, REAL -> double precision, BLOB -> bytea, BOOLEAN -> boolean,
|
||||
-- DATETIME/TIMESTAMP -> timestamptz, TEXT -> text; INTEGER PRIMARY KEY -> identity.
|
||||
|
||||
create table if not exists cli_device_codes (
|
||||
device_code_hash text PRIMARY KEY,
|
||||
user_code text NOT NULL UNIQUE,
|
||||
user_id text REFERENCES users(id) ON DELETE CASCADE,
|
||||
name text,
|
||||
status text NOT NULL DEFAULT 'pending',
|
||||
created_at bigint NOT NULL,
|
||||
expires_at bigint NOT NULL,
|
||||
last_polled_at bigint
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_cli_device_user_code ON cli_device_codes(user_code);
|
||||
Loading…
Add table
Add a link
Reference in a new issue