CREATE TABLE `articles` (
	`id` integer PRIMARY KEY AUTOINCREMENT 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 DEFAULT false,
	`is_starred` integer DEFAULT false,
	`is_broken` integer DEFAULT false,
	`broken_reason` text,
	`link_fixed` text,
	`content_fetched_at` integer,
	`created_at` integer,
	`updated_at` integer,
	FOREIGN KEY (`feed_id`) REFERENCES `feeds`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE INDEX `articles_feed_idx` ON `articles` (`feed_id`);--> statement-breakpoint
CREATE INDEX `articles_guid_idx` ON `articles` (`guid`);--> statement-breakpoint
CREATE INDEX `articles_link_idx` ON `articles` (`link`);--> statement-breakpoint
CREATE INDEX `articles_published_idx` ON `articles` (`published_at`);--> statement-breakpoint
CREATE INDEX `articles_read_idx` ON `articles` (`is_read`);--> statement-breakpoint
CREATE INDEX `articles_broken_idx` ON `articles` (`is_broken`);--> statement-breakpoint
CREATE INDEX `articles_feed_read_idx` ON `articles` (`feed_id`,`is_read`);--> statement-breakpoint
CREATE INDEX `articles_feed_pub_idx` ON `articles` (`feed_id`,`published_at`);--> statement-breakpoint
CREATE INDEX `articles_author_idx` ON `articles` (`author`);--> statement-breakpoint
CREATE INDEX `articles_starred_idx` ON `articles` (`is_starred`);--> statement-breakpoint
CREATE TABLE `feeds` (
	`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
	`title` text NOT NULL,
	`xml_url` text NOT NULL,
	`html_url` text,
	`description` text,
	`category` text,
	`last_fetched_at` integer,
	`last_modified` text,
	`etag` text,
	`fetch_error` text,
	`error_count` integer DEFAULT 0,
	`is_active` integer DEFAULT true,
	`created_at` integer,
	`updated_at` integer
);
--> statement-breakpoint
CREATE UNIQUE INDEX `feeds_xml_url_unique` ON `feeds` (`xml_url`);--> statement-breakpoint
CREATE INDEX `feeds_category_idx` ON `feeds` (`category`);--> statement-breakpoint
CREATE INDEX `feeds_active_idx` ON `feeds` (`is_active`);--> statement-breakpoint
CREATE TABLE `fetch_cache` (
	`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
	`url` text NOT NULL,
	`etag` text,
	`last_modified` text,
	`content_hash` text,
	`status_code` integer,
	`fetched_at` integer
);
--> statement-breakpoint
CREATE UNIQUE INDEX `fetch_cache_url_unique` ON `fetch_cache` (`url`);--> statement-breakpoint
CREATE INDEX `fetch_cache_url_idx` ON `fetch_cache` (`url`);--> statement-breakpoint
CREATE TABLE `opml_imports` (
	`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
	`file_path` text NOT NULL,
	`file_name` text,
	`feeds_imported` integer DEFAULT 0,
	`feeds_skipped` integer DEFAULT 0,
	`imported_at` integer
);
