example-sveltekit-email-pas.../setup.sql
pilcrowOnPaper 8332a0471f update sql
2024-10-04 10:28:58 +09:00

57 lines
1.5 KiB
SQL

CREATE TABLE user (
id INTEGER NOT NULL PRIMARY KEY,
email TEXT NOT NULL UNIQUE,
username TEXT NOT NULL,
password_hash TEXT NOT NULL,
email_verified INTEGER NOT NULL DEFAULT 0,
recovery_code BLOB NOT NULL
);
CREATE INDEX email_index ON user(email);
CREATE TABLE session (
id TEXT NOT NULL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES user(id),
expires_at INTEGER NOT NULL,
two_factor_verified INTEGER NOT NULL DEFAULT 0
);
CREATE TABLE email_verification_request (
id TEXT NOT NULL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES user(id),
email TEXT NOT NULL,
code TEXT NOT NULL,
expires_at INTEGER NOT NULL
);
CREATE TABLE password_reset_session (
id TEXT NOT NULL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES user(id),
email TEXT NOT NULL,
code TEXT NOT NULL,
expires_at INTEGER NOT NULL,
email_verified INTEGER NOT NULL NOT NULL DEFAULT 0,
two_factor_verified INTEGER NOT NULL DEFAULT 0
);
CREATE TABLE totp_credential (
id INTEGER NOT NULL PRIMARY KEY,
user_id INTEGER NOT NULL UNIQUE REFERENCES user(id),
key BLOB NOT NULL
);
CREATE TABLE passkey_credential (
id BLOB NOT NULL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES user(id),
name TEXT NOT NULL,
algorithm INTEGER NOT NULL,
public_key BLOB NOT NULL
);
CREATE TABLE security_key_credential (
id BLOB NOT NULL PRIMARY KEY,
user_id INTEGER NOT NULL REFERENCES user(id),
name TEXT NOT NULL,
algorithm INTEGER NOT NULL,
public_key BLOB NOT NULL
);