CREATE extension IF NOT EXISTS pgcrypto;
SET TIMEZONE='UTC';

--DROP TABLE IF EXISTS authn;
CREATE TABLE IF NOT EXISTS authn (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    ppid TEXT NOT NULL,
    email TEXT NOT NULL,
    verified BOOL 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')
);

--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);
