CREATE DOMAIN uuidv7 AS uuid CHECK (uuid_extract_version(VALUE) = 7);--> statement-breakpoint CREATE TYPE "public"."raw_action" AS ENUM('create', 'update', 'delete');--> statement-breakpoint CREATE TABLE "raw_records" ( "id" uuidv7 PRIMARY KEY NOT NULL, "tap_id" bigint NOT NULL, "received_at" timestamp with time zone DEFAULT now() NOT NULL, "did" text NOT NULL, "rev" text NOT NULL, "collection" text NOT NULL, "rkey" text NOT NULL, "action" "raw_action" NOT NULL, "cid" text, "record" jsonb, CONSTRAINT "raw_records_tap_id_unique" UNIQUE("tap_id"), CONSTRAINT "raw_records_not_null_unless_delete" CHECK (("raw_records"."action" = 'delete' or ("raw_records"."cid" is not null and "raw_records"."record" is not null))) ); --> statement-breakpoint CREATE INDEX "raw_records_collection_index" ON "raw_records" USING btree ("collection");--> statement-breakpoint CREATE INDEX "raw_records_did_collection_rkey_index" ON "raw_records" USING btree ("did","collection","rkey");