ALTER TABLE `watchlist_item` ADD `status` text NOT NULL DEFAULT 'backlog';
--> statement-breakpoint
ALTER TABLE `watchlist_item` ADD `priority` text NOT NULL DEFAULT 'medium';
--> statement-breakpoint
ALTER TABLE `watchlist_item` ADD `updated_at` text NOT NULL DEFAULT '';
--> statement-breakpoint
UPDATE `watchlist_item`
SET `status` = 'backlog'
WHERE `status` IS NULL OR TRIM(`status`) = '';
--> statement-breakpoint
UPDATE `watchlist_item`
SET `priority` = 'medium'
WHERE `priority` IS NULL OR TRIM(`priority`) = '';
--> statement-breakpoint
UPDATE `watchlist_item`
SET `updated_at` = COALESCE(NULLIF(`created_at`, ''), CURRENT_TIMESTAMP)
WHERE `updated_at` IS NULL OR TRIM(`updated_at`) = '';
--> statement-breakpoint
ALTER TABLE `watchlist_item` ADD `last_reviewed_at` text;
--> statement-breakpoint
ALTER TABLE `holding` ADD `company_name` text;
--> statement-breakpoint
CREATE INDEX `watchlist_user_updated_idx` ON `watchlist_item` (`user_id`, `updated_at`);
--> statement-breakpoint
CREATE TABLE `research_journal_entry` (
  `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
  `user_id` text NOT NULL,
  `ticker` text NOT NULL,
  `accession_number` text,
  `entry_type` text NOT NULL,
  `title` text,
  `body_markdown` text NOT NULL,
  `metadata` text,
  `created_at` text NOT NULL,
  `updated_at` text NOT NULL,
  FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE INDEX `research_journal_ticker_idx` ON `research_journal_entry` (`user_id`, `ticker`, `created_at`);
--> statement-breakpoint
CREATE INDEX `research_journal_accession_idx` ON `research_journal_entry` (`user_id`, `accession_number`);
