1
0
mirror of https://github.com/delight-im/PHP-Auth.git synced 2025-08-02 14:17:26 +02:00

Add check constraints for unsigned integers in PostgreSQL schema

This commit is contained in:
Marco
2018-03-12 01:51:33 +01:00
parent 1121685cef
commit 62d9e44aa4

View File

@@ -5,25 +5,25 @@
BEGIN; BEGIN;
CREATE TABLE IF NOT EXISTS "users" ( CREATE TABLE IF NOT EXISTS "users" (
"id" SERIAL PRIMARY KEY, "id" SERIAL PRIMARY KEY CHECK ("id" >= 0),
"email" VARCHAR(249) UNIQUE NOT NULL, "email" VARCHAR(249) UNIQUE NOT NULL,
"password" VARCHAR(255) NOT NULL, "password" VARCHAR(255) NOT NULL,
"username" VARCHAR(100) DEFAULT NULL, "username" VARCHAR(100) DEFAULT NULL,
"status" SMALLINT NOT NULL DEFAULT '0', "status" SMALLINT NOT NULL DEFAULT '0' CHECK ("status" >= 0),
"verified" SMALLINT NOT NULL DEFAULT '0', "verified" SMALLINT NOT NULL DEFAULT '0' CHECK ("verified" >= 0),
"resettable" SMALLINT NOT NULL DEFAULT '1', "resettable" SMALLINT NOT NULL DEFAULT '1' CHECK ("resettable" >= 0),
"roles_mask" INTEGER NOT NULL DEFAULT '0', "roles_mask" INTEGER NOT NULL DEFAULT '0' CHECK ("roles_mask" >= 0),
"registered" INTEGER NOT NULL, "registered" INTEGER NOT NULL CHECK ("registered" >= 0),
"last_login" INTEGER DEFAULT NULL "last_login" INTEGER DEFAULT NULL CHECK ("last_login" >= 0)
); );
CREATE TABLE IF NOT EXISTS "users_confirmations" ( CREATE TABLE IF NOT EXISTS "users_confirmations" (
"id" SERIAL PRIMARY KEY, "id" SERIAL PRIMARY KEY CHECK ("id" >= 0),
"user_id" INTEGER NOT NULL, "user_id" INTEGER NOT NULL CHECK ("user_id" >= 0),
"email" VARCHAR(249) NOT NULL, "email" VARCHAR(249) NOT NULL,
"selector" VARCHAR(16) UNIQUE NOT NULL, "selector" VARCHAR(16) UNIQUE NOT NULL,
"token" VARCHAR(255) NOT NULL, "token" VARCHAR(255) NOT NULL,
"expires" INTEGER NOT NULL "expires" INTEGER NOT NULL CHECK ("expires" >= 0)
); );
CREATE INDEX IF NOT EXISTS "email_expires" ON "users_confirmations" ("email", "expires"); CREATE INDEX IF NOT EXISTS "email_expires" ON "users_confirmations" ("email", "expires");
@@ -31,30 +31,30 @@ CREATE INDEX IF NOT EXISTS "email_expires" ON "users_confirmations" ("email", "e
CREATE INDEX IF NOT EXISTS "user_id" ON "users_confirmations" ("user_id"); CREATE INDEX IF NOT EXISTS "user_id" ON "users_confirmations" ("user_id");
CREATE TABLE IF NOT EXISTS "users_remembered" ( CREATE TABLE IF NOT EXISTS "users_remembered" (
"id" BIGSERIAL PRIMARY KEY, "id" BIGSERIAL PRIMARY KEY CHECK ("id" >= 0),
"user" INTEGER NOT NULL, "user" INTEGER NOT NULL CHECK ("user" >= 0),
"selector" VARCHAR(24) UNIQUE NOT NULL, "selector" VARCHAR(24) UNIQUE NOT NULL,
"token" VARCHAR(255) NOT NULL, "token" VARCHAR(255) NOT NULL,
"expires" INTEGER NOT NULL "expires" INTEGER NOT NULL CHECK ("expires" >= 0)
); );
CREATE INDEX IF NOT EXISTS "user" ON "users_remembered" ("user"); CREATE INDEX IF NOT EXISTS "user" ON "users_remembered" ("user");
CREATE TABLE IF NOT EXISTS "users_resets" ( CREATE TABLE IF NOT EXISTS "users_resets" (
"id" BIGSERIAL PRIMARY KEY, "id" BIGSERIAL PRIMARY KEY CHECK ("id" >= 0),
"user" INTEGER NOT NULL, "user" INTEGER NOT NULL CHECK ("user" >= 0),
"selector" VARCHAR(20) UNIQUE NOT NULL, "selector" VARCHAR(20) UNIQUE NOT NULL,
"token" VARCHAR(255) NOT NULL, "token" VARCHAR(255) NOT NULL,
"expires" INTEGER NOT NULL "expires" INTEGER NOT NULL CHECK ("expires" >= 0)
); );
CREATE INDEX IF NOT EXISTS "user_expires" ON "users_resets" ("user", "expires"); CREATE INDEX IF NOT EXISTS "user_expires" ON "users_resets" ("user", "expires");
CREATE TABLE IF NOT EXISTS "users_throttling" ( CREATE TABLE IF NOT EXISTS "users_throttling" (
"bucket" VARCHAR(44) PRIMARY KEY, "bucket" VARCHAR(44) PRIMARY KEY,
"tokens" REAL NOT NULL, "tokens" REAL NOT NULL CHECK ("tokens" >= 0),
"replenished_at" INTEGER NOT NULL, "replenished_at" INTEGER NOT NULL CHECK ("replenished_at" >= 0),
"expires_at" INTEGER NOT NULL "expires_at" INTEGER NOT NULL CHECK ("expires_at" >= 0)
); );
CREATE INDEX IF NOT EXISTS "expires_at" ON "users_throttling" ("expires_at"); CREATE INDEX IF NOT EXISTS "expires_at" ON "users_throttling" ("expires_at");