-- initDb creates this durable raw audit table in the same IMMEDIATE transaction
-- as legacy duplicate repair, before these unique indexes can be installed.
CREATE TABLE IF NOT EXISTS `article_identity_repair_backups` (
	`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
	`article_id` integer NOT NULL,
	`survivor_article_id` integer NOT NULL,
	`reason` text NOT NULL,
	`removed_at` integer NOT NULL,
	`feed_id` integer NOT NULL,
	`guid` text,
	`title` text,
	`link` text NOT NULL,
	`description` text,
	`content` text,
	`author` text,
	`categories` text,
	`published_at` integer,
	`is_read` integer NOT NULL,
	`is_starred` integer NOT NULL,
	`is_broken` integer NOT NULL,
	`broken_reason` text,
	`link_fixed` text,
	`content_fetched_at` integer,
	`created_at` integer,
	`updated_at` integer
);
--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS `article_identity_repair_backups_article_id_unique` ON `article_identity_repair_backups` (`article_id`);--> statement-breakpoint
CREATE INDEX IF NOT EXISTS `article_identity_repair_backups_survivor_idx` ON `article_identity_repair_backups` (`survivor_article_id`);--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS `articles_feed_guid_unique` ON `articles` (`feed_id`,`guid`) WHERE "articles"."guid" IS NOT NULL AND "articles"."guid" <> '';--> statement-breakpoint
CREATE UNIQUE INDEX IF NOT EXISTS `articles_feed_link_unique` ON `articles` (`feed_id`,`link`);
