1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-07-30 21:00:13 +02:00

Add PostgreSQL schema for new tables 'users_2fa' and 'users_otps'

This commit is contained in:
Marco
2024-04-04 17:47:08 +02:00
parent 96b72f0be9
commit 8f249d0080

View File

@@ -18,6 +18,16 @@ CREATE TABLE IF NOT EXISTS "users" (
"force_logout" INTEGER NOT NULL DEFAULT '0' CHECK ("force_logout" >= 0)
);
CREATE TABLE IF NOT EXISTS "users_2fa" (
"id" BIGSERIAL PRIMARY KEY CHECK ("id" >= 0),
"user_id" INTEGER NOT NULL CHECK ("user_id" >= 0),
"mechanism" SMALLINT NOT NULL CHECK ("mechanism" >= 0),
"seed" VARCHAR(255) DEFAULT NULL,
"created_at" INTEGER NOT NULL CHECK ("created_at" >= 0),
"expires_at" INTEGER DEFAULT NULL CHECK ("expires_at" >= 0),
);
CREATE UNIQUE INDEX IF NOT EXISTS "user_id_mechanism" ON "users_2fa" ("user_id", "mechanism");
CREATE TABLE IF NOT EXISTS "users_confirmations" (
"id" SERIAL PRIMARY KEY CHECK ("id" >= 0),
"user_id" INTEGER NOT NULL CHECK ("user_id" >= 0),
@@ -29,6 +39,18 @@ CREATE TABLE IF NOT EXISTS "users_confirmations" (
CREATE INDEX IF NOT EXISTS "email_expires" ON "users_confirmations" ("email", "expires");
CREATE INDEX IF NOT EXISTS "user_id" ON "users_confirmations" ("user_id");
CREATE TABLE IF NOT EXISTS "users_otps" (
"id" BIGSERIAL PRIMARY KEY CHECK ("id" >= 0),
"user_id" INTEGER NOT NULL CHECK ("user_id" >= 0),
"mechanism" SMALLINT NOT NULL CHECK ("mechanism" >= 0),
"single_factor" SMALLINT NOT NULL DEFAULT '0' CHECK ("single_factor" >= 0),
"selector" VARCHAR(24) NOT NULL,
"token" VARCHAR(255) NOT NULL,
"expires_at" INTEGER DEFAULT NULL CHECK ("expires_at" >= 0),
);
CREATE INDEX IF NOT EXISTS "user_id_mechanism" ON "users_otps" ("user_id", "mechanism");
CREATE INDEX IF NOT EXISTS "selector_user_id" ON "users_otps" ("selector", "user_id");
CREATE TABLE IF NOT EXISTS "users_remembered" (
"id" BIGSERIAL PRIMARY KEY CHECK ("id" >= 0),
"user" INTEGER NOT NULL CHECK ("user" >= 0),