shellcoreDB made... n shi

This commit is contained in:
gollyohmolly committed 2026-11-23 19:41:00 +01:00
1 parent 244bd918d6
commit bcc9894062
19 files changed
+493 -22

No files matched your search

@@ -0,0 +1,37 @@
-- Apply to an existing database created from the original shellcore.sql.
-- This intentionally refuses to discard any populated plaintext email values.
BEGIN;
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM accounts WHERE email IS NOT NULL) THEN
RAISE EXCEPTION 'Existing email data requires a separately designed encrypted mail-store migration';
END IF;
IF EXISTS (SELECT 1 FROM accounts WHERE username IS NULL) THEN
RAISE EXCEPTION 'Every existing account needs a username before migration';
END IF;
IF EXISTS (
SELECT 1 FROM accounts a
WHERE a.passwordHash IS NULL
AND NOT EXISTS (SELECT 1 FROM externalAccounts e WHERE e.accountId = a.id AND e.provider = 'steam')
) THEN
RAISE EXCEPTION 'An account without a local password needs a verified Steam link before migration';
END IF;
END $$;
CREATE TABLE IF NOT EXISTS localCredentials (
accountId UUID PRIMARY KEY REFERENCES accounts (id) ON DELETE CASCADE,
passwordHash TEXT NOT NULL
);
INSERT INTO localCredentials (accountId, passwordHash)
SELECT id, passwordHash FROM accounts WHERE passwordHash IS NOT NULL
ON CONFLICT (accountId) DO NOTHING;
ALTER TABLE accounts ALTER COLUMN username SET NOT NULL;
DROP INDEX IF EXISTS accountsEmailUnique;
ALTER TABLE accounts DROP COLUMN passwordHash;
ALTER TABLE accounts DROP COLUMN emailVerified;
ALTER TABLE accounts DROP COLUMN email;
COMMIT;
+39
View File
@@ -0,0 +1,39 @@
CREATE TABLE IF NOT EXISTS accounts (
id UUID PRIMARY KEY DEFAULT gen_random_uuid (),
username VARCHAR(32) NOT NULL,
displayName VARCHAR(64),
avatarURL TEXT,
status TEXT NOT NULL DEFAULT 'active' CHECK (status in ('active', 'suspended', 'disabled')),
createdAt TIMESTAMPTZ NOT NULL DEFAULT NOW (),
updatedAt TIMESTAMPTZ NOT NULL DEFAULT NOW (),
lastLoginAt TIMESTAMPTZ
);
CREATE TABLE IF NOT EXISTS localCredentials (
accountId UUID PRIMARY KEY REFERENCES accounts (id) ON DELETE CASCADE,
passwordHash TEXT NOT NULL
);
CREATE TABLE externalAccounts (
id UUID PRIMARY KEY DEFAULT gen_random_uuid (),
accountId UUID NOT NULL REFERENCES accounts (id) ON DELETE CASCADE,
provider TEXT NOT NULL,
providerUserId TEXT NOT NULL,
linkedAt TIMESTAMPTZ NOT NULL DEFAULT NOW (),
UNIQUE (provider, providerUserId),
UNIQUE (accountId, provider)
);
CREATE UNIQUE INDEX IF NOT EXISTS accountsUsernameUnique ON accounts (LOWER(username));
CREATE TABLE IF NOT EXISTS sessions (
id UUID PRIMARY KEY DEFAULT gen_random_uuid (),
accountId UUID NOT NULL REFERENCES accounts (id) ON DELETE CASCADE,
tokenHash TEXT NOT NULL UNIQUE,
createdAt TIMESTAMPTZ NOT NULL DEFAULT NOW (),
expiresAt TIMESTAMPTZ NOT NULL,
lastUsedAt TIMESTAMPTZ,
revokedAt TIMESTAMPTZ
);
CREATE INDEX IF NOT EXISTS lookUp ON sessions (accountId);