feat: Add route grouping schema compatibility checks and integration into migration process

This commit is contained in:
cita
2026-03-08 13:29:25 +08:00
parent 4172ad4297
commit 7081be14c7
6 changed files with 259 additions and 18 deletions
@@ -130,6 +130,35 @@ describe('databaseMigrationService', () => {
expect(useSystemProxySql).toContain('use_system_proxy');
});
it.each(['postgres', 'mysql'] as const)('patches token_routes decision snapshot columns for %s', async (dialect) => {
const executedSql: string[] = [];
await __databaseMigrationServiceTestUtils.ensureSchema({
dialect,
begin: async () => {},
commit: async () => {},
rollback: async () => {},
execute: async (sqlText) => {
executedSql.push(sqlText);
return [];
},
queryScalar: async (sqlText, params = []) => {
if (sqlText.includes('information_schema.tables')) {
return 1;
}
if (sqlText.includes('information_schema.columns')) {
const columnName = String(params[1] ?? '');
return columnName === 'decision_snapshot' ? 0 : 1;
}
return 0;
},
close: async () => {},
});
expect(
executedSql.some((sqlText) => sqlText.includes('ADD COLUMN') && sqlText.includes('decision_snapshot')),
).toBe(true);
});
it('includes useSystemProxy when building site migration statements', () => {
const statements = __databaseMigrationServiceTestUtils.buildStatements({
version: 'test',
@@ -5,6 +5,7 @@ import { mkdirSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { db, schema } from '../db/index.js';
import { ensureSiteSchemaCompatibility, type SiteSchemaInspector } from '../db/siteSchemaCompatibility.js';
import { ensureRouteGroupingSchemaCompatibility } from '../db/routeGroupingSchemaCompatibility.js';
export type MigrationDialect = 'sqlite' | 'mysql' | 'postgres';
@@ -433,6 +434,7 @@ async function ensureSchema(client: SqlClient): Promise<void> {
}
await ensureSiteSchemaCompatibility(createSiteSchemaInspector(client));
await ensureRouteGroupingSchemaCompatibility(createSiteSchemaInspector(client));
}
async function ensureTargetState(client: SqlClient, overwrite: boolean): Promise<void> {