63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { readFileSync } from 'node:fs';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { dirname, join } from 'node:path';
|
|
|
|
const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
const migration = readFileSync(join(currentDir, '202606230001_create_visa_schema.sql'), 'utf8');
|
|
|
|
const requiredTables = [
|
|
'models',
|
|
'model_versions',
|
|
'visa_agents',
|
|
'visa_variables',
|
|
'visa_sensing_relations',
|
|
'visa_sensing_variables',
|
|
'visa_internal_functions',
|
|
'visa_function_inputs',
|
|
'visa_function_updates',
|
|
'visa_associated_data',
|
|
'visa_inputs',
|
|
'visa_outputs',
|
|
'visa_schedule_steps',
|
|
'visa_termination_conditions',
|
|
'visa_validations',
|
|
'visa_consistency_check_results',
|
|
];
|
|
|
|
for (const table of requiredTables) {
|
|
assert.match(migration, new RegExp(`create table if not exists ${table}`, 'i'), `${table} table missing`);
|
|
}
|
|
|
|
const requiredForeignKeys = [
|
|
'references model_versions',
|
|
'references visa_agents',
|
|
'references visa_variables',
|
|
'references visa_sensing_relations',
|
|
'references visa_internal_functions',
|
|
'references visa_associated_data',
|
|
];
|
|
|
|
for (const foreignKey of requiredForeignKeys) {
|
|
assert.match(migration, new RegExp(foreignKey, 'i'), `${foreignKey} foreign key missing`);
|
|
}
|
|
|
|
const requiredIndexes = [
|
|
'idx_visa_agents_model_version',
|
|
'idx_visa_variables_agent',
|
|
'idx_visa_sensing_observer',
|
|
'idx_visa_functions_agent',
|
|
'idx_visa_schedule_model_version',
|
|
'idx_visa_checks_model_version',
|
|
];
|
|
|
|
for (const indexName of requiredIndexes) {
|
|
assert.match(migration, new RegExp(`create index if not exists ${indexName}`, 'i'), `${indexName} index missing`);
|
|
}
|
|
|
|
assert.match(migration, /unique \(model_version_id, function_code\)/i);
|
|
assert.match(migration, /unique \(model_version_id, validation_code\)/i);
|
|
assert.match(migration, /check \(status in \('draft', 'checked', 'released', 'archived'\)\)/i);
|
|
|
|
console.log('visa schema migration tests passed');
|