start of shellcore DB

This commit is contained in:
gollyohmolly committed 2026-11-15 13:55:22 +01:00
1 parent 4461f52775
commit 244bd918d6
8 files changed
+70 -2

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
CREATE TABLE IF NOT EXISTS accounts (
id UUID PRIMARY KEY DEFAULT gen_random_uuid (),
username VARCHAR(32),
displayName VARCHAR(64),
avatarURL TEXT,
passwordHash TEXT,
email TEXT,
emailVerified BOOLEAN NOT NULL DEFAULT FALSE,
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 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 UNIQUE INDEX IF NOT EXISTS accountsEmailUnique ON accounts (LOWER(email));
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);