config and plugin
This commit is contained in:
@@ -44,6 +44,10 @@ function migrateServers(handle: Database.Database): void {
|
||||
// Additive columns on tables the script model owns. Same pattern as
|
||||
// migrateServers — CREATE TABLE IF NOT EXISTS won't backfill columns onto
|
||||
// pre-existing tables, so we introspect and ALTER as needed.
|
||||
const SCRIPTS_COLUMNS: Array<{ name: string; ddl: string }> = [
|
||||
{ name: 'kind', ddl: "ALTER TABLE scripts ADD COLUMN kind TEXT NOT NULL DEFAULT 'script'" }
|
||||
];
|
||||
|
||||
const SCRIPT_VERSIONS_COLUMNS: Array<{ name: string; ddl: string }> = [
|
||||
// state was added post-launch to make untested/tested/test-failed visible
|
||||
// in the UI. Existing rows default to 'untested' — this is safe because
|
||||
@@ -51,7 +55,16 @@ const SCRIPT_VERSIONS_COLUMNS: Array<{ name: string; ddl: string }> = [
|
||||
// the authoritative "promoted" signal), and any version already gated
|
||||
// through a ready-promote beta will be re-marked next time that state
|
||||
// machine fires.
|
||||
{ name: 'state', ddl: "ALTER TABLE script_versions ADD COLUMN state TEXT NOT NULL DEFAULT 'untested'" }
|
||||
{ name: 'state', ddl: "ALTER TABLE script_versions ADD COLUMN state TEXT NOT NULL DEFAULT 'untested'" },
|
||||
{ name: 'kind', ddl: "ALTER TABLE script_versions ADD COLUMN kind TEXT NOT NULL DEFAULT 'script'" }
|
||||
];
|
||||
|
||||
const BETA_SCRIPTS_COLUMNS: Array<{ name: string; ddl: string }> = [
|
||||
{ name: 'kind', ddl: "ALTER TABLE beta_scripts ADD COLUMN kind TEXT NOT NULL DEFAULT 'script'" }
|
||||
];
|
||||
|
||||
const DEPLOYMENT_SCRIPTS_COLUMNS: Array<{ name: string; ddl: string }> = [
|
||||
{ name: 'kind', ddl: "ALTER TABLE deployment_scripts ADD COLUMN kind TEXT NOT NULL DEFAULT 'script'" }
|
||||
];
|
||||
|
||||
const DEPLOYMENTS_COLUMNS: Array<{ name: string; ddl: string }> = [
|
||||
@@ -146,8 +159,16 @@ export function db(): Database.Database {
|
||||
dropLegacyBetaTables(_db);
|
||||
_db.exec(schemaSql);
|
||||
migrateServers(_db);
|
||||
migrateTable(_db, 'scripts', SCRIPTS_COLUMNS);
|
||||
migrateTable(_db, 'script_versions', SCRIPT_VERSIONS_COLUMNS);
|
||||
migrateTable(_db, 'beta_scripts', BETA_SCRIPTS_COLUMNS);
|
||||
migrateTable(_db, 'deployment_scripts', DEPLOYMENT_SCRIPTS_COLUMNS);
|
||||
migrateTable(_db, 'deployments', DEPLOYMENTS_COLUMNS);
|
||||
_db.exec(
|
||||
`CREATE UNIQUE INDEX IF NOT EXISTS idx_scripts_one_baseline_per_scope
|
||||
ON scripts(scope_type, scope_value) WHERE kind = 'baseline'`
|
||||
);
|
||||
_db.exec(`CREATE INDEX IF NOT EXISTS idx_scripts_kind ON scripts(kind)`);
|
||||
backfillMultiScriptJoins(_db);
|
||||
|
||||
return _db;
|
||||
|
||||
Reference in New Issue
Block a user