start of shellcore DB
This commit is contained in:
1 parent
4461f52775
commit
244bd918d6
8 files changed
+70
-2
No files matched your search
@@ -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);
|
||||
Reference in new issue
Block a user