fix(data): retain applied legacy backfill for upgrades

This commit is contained in:
ZheFox
2026-08-25 21:22:57 +08:00
parent 2f2d444f97
commit ec6ddb43a7
2 changed files with 68 additions and 5 deletions
@@ -0,0 +1,59 @@
DO $$
BEGIN
IF EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'providers'
AND column_name = 'enabled'
) AND EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'providers'
AND column_name = 'is_active'
) THEN
UPDATE public.providers
SET enabled = is_active
WHERE is_active IS NOT NULL
AND enabled IS DISTINCT FROM is_active;
END IF;
IF EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'provider_endpoints'
AND column_name = 'enabled'
) AND EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'provider_endpoints'
AND column_name = 'is_active'
) THEN
UPDATE public.provider_endpoints
SET enabled = is_active
WHERE is_active IS NOT NULL
AND enabled IS DISTINCT FROM is_active;
END IF;
IF EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'models'
AND column_name = 'enabled'
) AND EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'models'
AND column_name = 'is_active'
) THEN
UPDATE public.models
SET enabled = is_active
WHERE is_active IS NOT NULL
AND enabled IS DISTINCT FROM is_active;
END IF;
END $$;
@@ -47,7 +47,8 @@ fn pending_backfills_from_applied_returns_all_versions_when_none_applied() {
20260504120000,
20260505120000,
20260517012000,
20260716010000
20260716010000,
20260722140744
]
);
}
@@ -68,7 +69,8 @@ fn pending_backfills_from_applied_skips_versions_already_applied() {
20260504120000,
20260505120000,
20260517012000,
20260716010000
20260716010000,
20260722140744
]
);
}
@@ -965,13 +967,14 @@ async fn run_backfills_rebuilds_stats_and_records_execution() {
let pending_before = pending_backfills(&pool)
.await
.expect("pending backfills should load");
assert_eq!(pending_before.len(), 6);
assert_eq!(pending_before.len(), 7);
assert_eq!(pending_before[0].version, 20260422110000);
assert_eq!(pending_before[1].version, 20260422120000);
assert_eq!(pending_before[2].version, 20260504120000);
assert_eq!(pending_before[3].version, 20260505120000);
assert_eq!(pending_before[4].version, 20260517012000);
assert_eq!(pending_before[5].version, 20260716010000);
assert_eq!(pending_before[6].version, 20260722140744);
run_backfills(&pool)
.await
@@ -995,7 +998,8 @@ async fn run_backfills_rebuilds_stats_and_records_execution() {
20260504120000,
20260505120000,
20260517012000,
20260716010000
20260716010000,
20260722140744
]
);
@@ -1669,5 +1673,5 @@ ORDER BY total_tokens
.fetch_one(&pool)
.await
.expect("backfill count should load");
assert_eq!(applied_count, 6);
assert_eq!(applied_count, 7);
}