goserv/assets/configfs/files/postgres/init.sql

34 lines
1.2 KiB
MySQL
Raw Normal View History

CREATE extension IF NOT EXISTS pgcrypto;
SET TIMEZONE='UTC';
2020-10-10 20:52:46 +00:00
-- AuthN
--
--DROP TABLE IF EXISTS "authn";
CREATE TABLE IF NOT EXISTS "authn" (
"id" TEXT PRIMARY KEY DEFAULT gen_random_uuid(),
"ppid" TEXT NOT NULL,
"email" TEXT NOT NULL,
"verified" BOOL NOT NULL DEFAULT FALSE,
"created_at" TIMESTAMP NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'),
"updated_at" TIMESTAMP NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'),
"deleted_at" TIMESTAMP NOT NULL DEFAULT ('epoch' AT TIME ZONE 'UTC')
);
2020-10-10 20:52:46 +00:00
--CREATE INDEX CONCURRENTLY IF NOT EXISTS "idx_slug" ON "authn" ("ppid");
CREATE INDEX IF NOT EXISTS "idx_ppid" ON "authn" ("ppid");
CREATE INDEX IF NOT EXISTS "idx_email" ON "authn" ("email");
2020-10-10 20:52:46 +00:00
-- Events
--
--DROP TABLE IF EXISTS "events";
CREATE TABLE IF NOT EXISTS "events" (
"id" TEXT PRIMARY KEY DEFAULT gen_random_uuid(),
"action" TEXT NOT NULL,
"table" TEXT NOT NULL,
"record" TEXT NOT NULL,
"by" TEXT NOT NULL,
"at" TIMESTAMP NOT NULL DEFAULT (now() AT TIME ZONE 'UTC'),
);
--CREATE INDEX CONCURRENTLY IF NOT EXISTS "idx_record" ON "events" ("record");
CREATE INDEX IF NOT EXISTS "idx_record" ON authn ("record");
CREATE INDEX IF NOT EXISTS "idx_by" ON authn ("by");