CREATE TABLE `issuer_overlay_revision` (
	`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
	`ticker` text NOT NULL,
	`revision_number` integer NOT NULL,
	`definition_hash` text NOT NULL,
	`definition_json` text NOT NULL,
	`diagnostics_json` text,
	`source_snapshot_ids` text NOT NULL DEFAULT '[]',
	`created_at` text NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `issuer_overlay_revision_ticker_revision_uidx` ON `issuer_overlay_revision` (`ticker`,`revision_number`);
--> statement-breakpoint
CREATE UNIQUE INDEX `issuer_overlay_revision_ticker_hash_uidx` ON `issuer_overlay_revision` (`ticker`,`definition_hash`);
--> statement-breakpoint
CREATE INDEX `issuer_overlay_revision_ticker_created_idx` ON `issuer_overlay_revision` (`ticker`,`created_at`);
--> statement-breakpoint
CREATE TABLE `issuer_overlay` (
	`ticker` text PRIMARY KEY NOT NULL,
	`status` text NOT NULL DEFAULT 'empty',
	`active_revision_id` integer,
	`last_built_at` text,
	`last_error` text,
	`stats_json` text,
	`created_at` text NOT NULL,
	`updated_at` text NOT NULL,
	FOREIGN KEY (`active_revision_id`) REFERENCES `issuer_overlay_revision`(`id`) ON UPDATE no action ON DELETE set null
);
--> statement-breakpoint
CREATE INDEX `issuer_overlay_status_idx` ON `issuer_overlay` (`status`,`updated_at`);
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_snapshot` ADD `issuer_overlay_revision_id` integer REFERENCES `issuer_overlay_revision`(`id`) ON UPDATE no action ON DELETE set null;
