-- DROP TABLE IF EXISTS public.entity CASCADE;
CREATE TABLE public.entity (
    id                        BIGSERIAL PRIMARY KEY,
    user_id                   BIGINT NOT NULL REFERENCES public.user(id),
    fedid_url                 TEXT NOT NULL,
    short_name                TEXT NOT NULL,
    did_id                    TEXT NOT NULL,
    control_private_key_b64u  TEXT NOT NULL,
    recovery_private_key_b64u TEXT NOT NULL,
    did_doc                   JSONB NOT NULL,
    created_ts                TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_ts                TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
CREATE INDEX idx__public__entity__user_id       ON public.entity (user_id);
CREATE INDEX idx__public__entity__fedid_url     ON public.entity (fedid_url);
CREATE INDEX idx__public__entity__short_name    ON public.entity (short_name);
CREATE INDEX idx__public__entity__did_id        ON public.entity (did_id);
CREATE INDEX idx__public__entity__created_ts    ON public.entity (created_ts);
CREATE INDEX idx__public__entity__updated_ts    ON public.entity (updated_ts);
