Repository Public
1CREATE TABLE "auth_enrollments" (2 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,3 "purpose" text NOT NULL,4 "token_hash" text NOT NULL,5 "revoke_existing" boolean DEFAULT false NOT NULL,6 "created_at" timestamp with time zone DEFAULT now() NOT NULL,7 "expires_at" timestamp with time zone NOT NULL,8 "consumed_at" timestamp with time zone,9 "closed_reason" text,10 CONSTRAINT "auth_enrollments_token_hash_unique" UNIQUE("token_hash")11);12--> statement-breakpoint13CREATE TABLE "idempotency_keys" (14 "key" text PRIMARY KEY NOT NULL,15 "session_id" text NOT NULL,16 "method" text NOT NULL,17 "path" text NOT NULL,18 "status" integer,19 "response" jsonb,20 "created_at" timestamp with time zone DEFAULT now() NOT NULL21);22--> statement-breakpoint23CREATE TABLE "inbox_actions" (24 "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,25 "workspace_id" uuid NOT NULL,26 "page_id" uuid NOT NULL,27 "action" text NOT NULL,28 "before" jsonb DEFAULT '{}'::jsonb NOT NULL,29 "created" jsonb DEFAULT '{}'::jsonb NOT NULL,30 "created_at" timestamp with time zone DEFAULT now() NOT NULL,31 "undone_at" timestamp with time zone32);33--> statement-breakpoint34ALTER TABLE "pages" ADD COLUMN "inbox_at" timestamp with time zone;--> statement-breakpoint35ALTER TABLE "pages" ADD COLUMN "capture_kind" text;--> statement-breakpoint36ALTER TABLE "sessions" ADD COLUMN "credential_id" text;--> statement-breakpoint37ALTER TABLE "sessions" ADD COLUMN "label" text;--> statement-breakpoint38ALTER TABLE "sessions" ADD COLUMN "verified_at" timestamp with time zone;--> statement-breakpoint39ALTER TABLE "sessions" ADD COLUMN "revoked_reason" text;--> statement-breakpoint40ALTER TABLE "sessions" ADD COLUMN "prev_token_hash" text;--> statement-breakpoint41ALTER TABLE "sessions" ADD COLUMN "prev_valid_until" timestamp with time zone;--> statement-breakpoint42ALTER TABLE "webauthn_challenges" ADD COLUMN "expires_at" timestamp with time zone;--> statement-breakpoint43ALTER TABLE "webauthn_challenges" ADD COLUMN "session_id" uuid;--> statement-breakpoint44ALTER TABLE "webauthn_challenges" ADD COLUMN "enrollment_id" uuid;--> statement-breakpoint45ALTER TABLE "webauthn_credentials" ADD COLUMN "aaguid" text;--> statement-breakpoint46ALTER TABLE "inbox_actions" ADD CONSTRAINT "inbox_actions_workspace_id_workspaces_id_fk" FOREIGN KEY ("workspace_id") REFERENCES "public"."workspaces"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint47ALTER TABLE "inbox_actions" ADD CONSTRAINT "inbox_actions_page_id_pages_id_fk" FOREIGN KEY ("page_id") REFERENCES "public"."pages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint48CREATE INDEX "idempotency_created_idx" ON "idempotency_keys" USING btree ("created_at");--> statement-breakpoint49CREATE INDEX "inbox_actions_ws_idx" ON "inbox_actions" USING btree ("workspace_id","created_at");--> statement-breakpoint50CREATE INDEX "pages_inbox_idx" ON "pages" USING btree ("workspace_id","inbox_at");--> statement-breakpoint51-- Sessions of the pre-1.1.0 login are dead weight: mark them revoked (kept for the audit trail, never deleted).52UPDATE "sessions" SET "revoked_at" = now(), "revoked_reason" = 'legacy-v1' WHERE "revoked_at" IS NULL;--> statement-breakpoint53-- Challenges are single-use and short-lived; anything left from the old flow is unusable.54DELETE FROM "webauthn_challenges";55--> statement-breakpoint56-- The owner row keeps its identity; the password hash and TOTP secret of the removed login are obsolete credential material and are blanked.57UPDATE "users" SET "password_hash" = '!', "totp_secret" = NULL, "totp_enabled" = false;58