···11+CREATE TABLE "atproto_session" (
22+ "sub" text PRIMARY KEY NOT NULL,
33+ "value_ciphertext" "bytea" NOT NULL,
44+ "value_nonce" "bytea" NOT NULL,
55+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
66+ "updated_at" timestamp with time zone
77+);
88+--> statement-breakpoint
99+CREATE TABLE "atproto_state" (
1010+ "key" text PRIMARY KEY NOT NULL,
1111+ "value_ciphertext" "bytea" NOT NULL,
1212+ "value_nonce" "bytea" NOT NULL,
1313+ "created_at" timestamp with time zone DEFAULT now() NOT NULL
1414+);
1515+--> statement-breakpoint
1616+CREATE TABLE "installation" (
1717+ "id" bigint PRIMARY KEY NOT NULL,
1818+ "account_login" text NOT NULL,
1919+ "account_id" bigint NOT NULL,
2020+ "account_type" text NOT NULL,
2121+ "suspended_at" timestamp with time zone,
2222+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
2323+ CONSTRAINT "installation_account_type_chk" CHECK ("installation"."account_type" in ('User','Organization'))
2424+);
2525+--> statement-breakpoint
2626+CREATE TABLE "job" (
2727+ "id" bigserial PRIMARY KEY NOT NULL,
2828+ "kind" text NOT NULL,
2929+ "payload" jsonb NOT NULL,
3030+ "attempts" integer DEFAULT 0 NOT NULL,
3131+ "run_after" timestamp with time zone DEFAULT now() NOT NULL,
3232+ "locked_by" text,
3333+ "locked_until" timestamp with time zone,
3434+ "status" text DEFAULT 'queued' NOT NULL,
3535+ "last_error" text,
3636+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
3737+ "updated_at" timestamp with time zone,
3838+ CONSTRAINT "job_status_chk" CHECK ("job"."status" in ('queued','running','done','failed'))
3939+);
4040+--> statement-breakpoint
4141+CREATE TABLE "repo_mapping" (
4242+ "id" bigserial PRIMARY KEY NOT NULL,
4343+ "installation_id" bigint NOT NULL,
4444+ "github_repo_id" bigint NOT NULL,
4545+ "github_full_name" text NOT NULL,
4646+ "tangled_repo_did" text,
4747+ "tangled_full_name" text,
4848+ "knot" text,
4949+ "primary_side" text DEFAULT 'github' NOT NULL,
5050+ "last_synced_refs" jsonb DEFAULT '{}'::jsonb NOT NULL,
5151+ "status" text DEFAULT 'pending' NOT NULL,
5252+ "last_error" text,
5353+ "disabled_at" timestamp with time zone,
5454+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
5555+ "updated_at" timestamp with time zone,
5656+ CONSTRAINT "repo_mapping_installation_repo_unq" UNIQUE("installation_id","github_repo_id"),
5757+ CONSTRAINT "repo_mapping_primary_side_chk" CHECK ("repo_mapping"."primary_side" in ('github','tangled')),
5858+ CONSTRAINT "repo_mapping_status_chk" CHECK ("repo_mapping"."status" in ('pending','enrolling','active','error'))
5959+);
6060+--> statement-breakpoint
6161+CREATE TABLE "ssh_key" (
6262+ "id" bigserial PRIMARY KEY NOT NULL,
6363+ "installation_id" bigint NOT NULL,
6464+ "did" text NOT NULL,
6565+ "public_key" text NOT NULL,
6666+ "private_key_ciphertext" "bytea" NOT NULL,
6767+ "private_key_nonce" "bytea" NOT NULL,
6868+ "tangled_key_rkey" text,
6969+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
7070+ "rotated_at" timestamp with time zone,
7171+ CONSTRAINT "ssh_key_installation_did_unq" UNIQUE("installation_id","did")
7272+);
7373+--> statement-breakpoint
7474+CREATE TABLE "user_identity" (
7575+ "did" text PRIMARY KEY NOT NULL,
7676+ "handle" text,
7777+ "installation_id" bigint,
7878+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
7979+ "updated_at" timestamp with time zone
8080+);
8181+--> statement-breakpoint
8282+CREATE TABLE "webhook_event" (
8383+ "delivery_id" uuid PRIMARY KEY NOT NULL,
8484+ "source" text NOT NULL,
8585+ "event" text NOT NULL,
8686+ "received_at" timestamp with time zone DEFAULT now() NOT NULL,
8787+ "processed_at" timestamp with time zone,
8888+ CONSTRAINT "webhook_event_source_chk" CHECK ("webhook_event"."source" in ('github','tangled'))
8989+);
9090+--> statement-breakpoint
9191+ALTER TABLE "repo_mapping" ADD CONSTRAINT "repo_mapping_installation_id_installation_id_fk" FOREIGN KEY ("installation_id") REFERENCES "public"."installation"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
9292+ALTER TABLE "ssh_key" ADD CONSTRAINT "ssh_key_installation_id_installation_id_fk" FOREIGN KEY ("installation_id") REFERENCES "public"."installation"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
9393+ALTER TABLE "user_identity" ADD CONSTRAINT "user_identity_installation_id_installation_id_fk" FOREIGN KEY ("installation_id") REFERENCES "public"."installation"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
9494+CREATE INDEX "job_status_run_after_idx" ON "job" USING btree ("status","run_after");--> statement-breakpoint
9595+CREATE INDEX "repo_mapping_installation_idx" ON "repo_mapping" USING btree ("installation_id");--> statement-breakpoint
9696+CREATE INDEX "ssh_key_installation_idx" ON "ssh_key" USING btree ("installation_id");--> statement-breakpoint
9797+CREATE INDEX "user_identity_installation_idx" ON "user_identity" USING btree ("installation_id");