CREATE TABLE "theme_policies" (
	"id" bigserial PRIMARY KEY NOT NULL,
	"did" text NOT NULL,
	"rkey" text NOT NULL,
	"cid" text NOT NULL,
	"default_light_theme_uri" text NOT NULL,
	"default_dark_theme_uri" text NOT NULL,
	"allow_user_choice" boolean NOT NULL,
	"indexed_at" timestamp with time zone NOT NULL
);
--> statement-breakpoint
CREATE TABLE "theme_policy_available_themes" (
	"policy_id" bigint NOT NULL,
	"theme_uri" text NOT NULL,
	"theme_cid" text NOT NULL,
	CONSTRAINT "theme_policy_available_themes_policy_id_theme_uri_pk" PRIMARY KEY("policy_id","theme_uri")
);
--> statement-breakpoint
CREATE TABLE "themes" (
	"id" bigserial PRIMARY KEY NOT NULL,
	"did" text NOT NULL,
	"rkey" text NOT NULL,
	"cid" text NOT NULL,
	"name" text NOT NULL,
	"color_scheme" text NOT NULL,
	"tokens" jsonb NOT NULL,
	"css_overrides" text,
	"font_urls" text[],
	"created_at" timestamp with time zone NOT NULL,
	"indexed_at" timestamp with time zone NOT NULL
);
--> statement-breakpoint
ALTER TABLE "theme_policy_available_themes" ADD CONSTRAINT "theme_policy_available_themes_policy_id_theme_policies_id_fk" FOREIGN KEY ("policy_id") REFERENCES "public"."theme_policies"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE UNIQUE INDEX "theme_policies_did_rkey_idx" ON "theme_policies" USING btree ("did","rkey");--> statement-breakpoint
CREATE UNIQUE INDEX "themes_did_rkey_idx" ON "themes" USING btree ("did","rkey");