-- Migration: per-region storefront cache versions. -- -- One row per region in `region_cache_versions` drives the versioned per-region -- cache files (products/stores/banners/essential-consts, availability, slots). -- Rows for regions created later are auto-created on first use -- (getRegionCacheVersions), so the seed below only covers existing regions. -- -- NOTE: SQLite has no `ADD COLUMN IF NOT EXISTS`; tables use IF NOT EXISTS so the -- file is safe if re-applied, but rely on the migration journal to run it once. CREATE TABLE IF NOT EXISTS `region_cache_versions` ( `region_id` integer NOT NULL, `cache_version` integer NOT NULL DEFAULT 1, `availability_version_num` integer NOT NULL DEFAULT 1, `slots_version_num` integer NOT NULL DEFAULT 1, FOREIGN KEY (`region_id`) REFERENCES `regions`(`id`) ON UPDATE no action ON DELETE no action ); --> statement-breakpoint CREATE UNIQUE INDEX IF NOT EXISTS `unique_region_cache_version_region` ON `region_cache_versions` (`region_id`); --> statement-breakpoint -- Seed one row per existing region. INSERT INTO `region_cache_versions` (`region_id`, `cache_version`, `availability_version_num`, `slots_version_num`) SELECT `id`, 1, 1, 1 FROM `regions` WHERE NOT EXISTS (SELECT 1 FROM `region_cache_versions` WHERE `region_cache_versions`.`region_id` = `regions`.`id`);