skeleton/assets/migrations/1_user.up.sql
2019-08-22 00:48:27 +02:00

37 lines
1.2 KiB
SQL

CREATE TABLE "user" (
"id" bigserial NOT NULL,
"is_admin" boolean NOT NULL DEFAULT false,
"password" bytea NULL,
"created_at" timestamptz NOT NULL DEFAULT NOW(),
PRIMARY KEY ("id")
);
CREATE TABLE "email" (
"address" text NOT NULL,
"user_id" bigint NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT NOW(),
FOREIGN KEY ("user_id") REFERENCES "user" ("id") ON DELETE CASCADE,
PRIMARY KEY ("address")
);
CREATE INDEX ON "email" ("user_id");
CREATE TABLE "confirmation" (
"email_address" text NOT NULL,
"user_id" bigint NOT NULL,
"selector" text NOT NULL,
"verifier" bytea NOT NULL, -- hashed
"expires_at" timestamptz NOT NULL DEFAULT NOW(),
FOREIGN KEY ("user_id") REFERENCES "user" ("id") ON DELETE CASCADE,
PRIMARY KEY ("selector")
);
CREATE INDEX ON "confirmation" ("user_id");
CREATE TABLE "reset" (
"user_id" bigint NOT NULL,
"selector" text NOT NULL,
"verifier" bytea NOT NULL, -- hashed
"expires_at" timestamptz NOT NULL DEFAULT NOW(),
FOREIGN KEY ("user_id") REFERENCES "user" ("id") ON DELETE CASCADE,
PRIMARY KEY ("selector")
);
CREATE UNIQUE INDEX ON "reset" ("user_id");