ALTER TABLE `filing_taxonomy_snapshot` ADD `parser_engine` text DEFAULT 'legacy-ts' NOT NULL;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_snapshot` ADD `parser_version` text DEFAULT '0.0.0' NOT NULL;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_snapshot` ADD `taxonomy_regime` text DEFAULT 'unknown' NOT NULL;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_snapshot` ADD `fiscal_pack` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_snapshot` ADD `faithful_rows` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_snapshot` ADD `surface_rows` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_snapshot` ADD `detail_rows` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_snapshot` ADD `kpi_rows` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_snapshot` ADD `normalization_summary` text;
--> statement-breakpoint
UPDATE `filing_taxonomy_snapshot`
SET
  `faithful_rows` = COALESCE(`faithful_rows`, `statement_rows`),
  `surface_rows` = COALESCE(`surface_rows`, '{"income":[],"balance":[],"cash_flow":[],"equity":[],"comprehensive_income":[]}'),
  `detail_rows` = COALESCE(`detail_rows`, '{"income":{},"balance":{},"cash_flow":{},"equity":{},"comprehensive_income":{}}'),
  `kpi_rows` = COALESCE(`kpi_rows`, '[]');
--> statement-breakpoint
CREATE TABLE `filing_taxonomy_context` (
  `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
  `snapshot_id` integer NOT NULL,
  `context_id` text NOT NULL,
  `entity_identifier` text,
  `entity_scheme` text,
  `period_start` text,
  `period_end` text,
  `period_instant` text,
  `segment_json` text,
  `scenario_json` text,
  `created_at` text NOT NULL,
  FOREIGN KEY (`snapshot_id`) REFERENCES `filing_taxonomy_snapshot`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE INDEX `filing_taxonomy_context_snapshot_idx` ON `filing_taxonomy_context` (`snapshot_id`);
--> statement-breakpoint
CREATE UNIQUE INDEX `filing_taxonomy_context_uidx` ON `filing_taxonomy_context` (`snapshot_id`,`context_id`);
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_concept` ADD `balance` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_concept` ADD `period_type` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_concept` ADD `data_type` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_concept` ADD `authoritative_concept_key` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_concept` ADD `mapping_method` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_concept` ADD `surface_key` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_concept` ADD `detail_parent_surface_key` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_concept` ADD `kpi_key` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_concept` ADD `residual_flag` integer DEFAULT false NOT NULL;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_fact` ADD `data_type` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_fact` ADD `authoritative_concept_key` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_fact` ADD `mapping_method` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_fact` ADD `surface_key` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_fact` ADD `detail_parent_surface_key` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_fact` ADD `kpi_key` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_fact` ADD `residual_flag` integer DEFAULT false NOT NULL;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_fact` ADD `precision` text;
--> statement-breakpoint
ALTER TABLE `filing_taxonomy_fact` ADD `nil` integer DEFAULT false NOT NULL;
