@smithers-orchestrator/db 0.20.4 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/src/SqlMessageStorage.js +1 -823
- package/src/adapter.js +1 -1
- package/src/internal-schema/index.js +1 -0
- package/src/internal-schema/smithersFrames.js +6 -1
- package/src/internal-schema/smithersNodeDiffs.js +6 -1
- package/src/internal-schema/smithersSchemaMigrations.js +12 -0
- package/src/internal-schema/smithersTimeTravelAudit.js +8 -2
- package/src/internal-schema.js +25 -2
- package/src/schema-migrations.js +481 -0
- package/src/sql-message-storage.js +11 -69
|
@@ -4,6 +4,7 @@ import { SqlError } from "@effect/sql/SqlError";
|
|
|
4
4
|
import * as Statement from "@effect/sql/Statement";
|
|
5
5
|
import { Database } from "bun:sqlite";
|
|
6
6
|
import { Context, Effect, Layer, ManagedRuntime, Scope } from "effect";
|
|
7
|
+
import { runSmithersSchemaMigrations } from "./schema-migrations.js";
|
|
7
8
|
import { camelToSnake } from "./utils/camelToSnake.js";
|
|
8
9
|
/** @typedef {import("drizzle-orm/bun-sqlite").BunSQLiteDatabase} BunSQLiteDatabase */
|
|
9
10
|
/** @typedef {import("./SqlMessageStorageEventHistoryQuery.ts").SqlMessageStorageEventHistoryQuery} SqlMessageStorageEventHistoryQuery */
|
|
@@ -73,7 +74,8 @@ const CREATE_TABLE_STATEMENTS = [
|
|
|
73
74
|
mounted_task_ids_json TEXT,
|
|
74
75
|
task_index_json TEXT,
|
|
75
76
|
note TEXT,
|
|
76
|
-
PRIMARY KEY (run_id, frame_no)
|
|
77
|
+
PRIMARY KEY (run_id, frame_no),
|
|
78
|
+
FOREIGN KEY (run_id) REFERENCES _smithers_runs(run_id) ON DELETE CASCADE
|
|
77
79
|
)`,
|
|
78
80
|
`CREATE TABLE IF NOT EXISTS _smithers_approvals (
|
|
79
81
|
run_id TEXT NOT NULL,
|
|
@@ -161,7 +163,8 @@ const CREATE_TABLE_STATEMENTS = [
|
|
|
161
163
|
diff_json TEXT NOT NULL,
|
|
162
164
|
computed_at_ms INTEGER NOT NULL,
|
|
163
165
|
size_bytes INTEGER NOT NULL,
|
|
164
|
-
PRIMARY KEY (run_id, node_id, iteration, base_ref)
|
|
166
|
+
PRIMARY KEY (run_id, node_id, iteration, base_ref),
|
|
167
|
+
FOREIGN KEY (run_id) REFERENCES _smithers_runs(run_id) ON DELETE CASCADE
|
|
165
168
|
)`,
|
|
166
169
|
`CREATE TABLE IF NOT EXISTS _smithers_time_travel_audit (
|
|
167
170
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -171,7 +174,8 @@ const CREATE_TABLE_STATEMENTS = [
|
|
|
171
174
|
caller TEXT NOT NULL,
|
|
172
175
|
timestamp_ms INTEGER NOT NULL,
|
|
173
176
|
result TEXT NOT NULL,
|
|
174
|
-
duration_ms INTEGER
|
|
177
|
+
duration_ms INTEGER,
|
|
178
|
+
FOREIGN KEY (run_id) REFERENCES _smithers_runs(run_id) ON DELETE CASCADE
|
|
175
179
|
)`,
|
|
176
180
|
`CREATE TABLE IF NOT EXISTS _smithers_sandboxes (
|
|
177
181
|
run_id TEXT NOT NULL,
|
|
@@ -324,47 +328,6 @@ const CREATE_INDEX_STATEMENTS = [
|
|
|
324
328
|
`CREATE INDEX IF NOT EXISTS _smithers_time_travel_audit_lookup_idx
|
|
325
329
|
ON _smithers_time_travel_audit (run_id, caller, timestamp_ms)`,
|
|
326
330
|
];
|
|
327
|
-
const MIGRATION_STATEMENTS = [
|
|
328
|
-
`ALTER TABLE _smithers_attempts ADD COLUMN response_text TEXT`,
|
|
329
|
-
`ALTER TABLE _smithers_attempts ADD COLUMN jj_cwd TEXT`,
|
|
330
|
-
`ALTER TABLE _smithers_attempts ADD COLUMN heartbeat_at_ms INTEGER`,
|
|
331
|
-
`ALTER TABLE _smithers_attempts ADD COLUMN heartbeat_data_json TEXT`,
|
|
332
|
-
`ALTER TABLE _smithers_attempts ADD COLUMN cached INTEGER DEFAULT 0`,
|
|
333
|
-
`ALTER TABLE _smithers_attempts ADD COLUMN meta_json TEXT`,
|
|
334
|
-
`ALTER TABLE _smithers_runs ADD COLUMN workflow_hash TEXT`,
|
|
335
|
-
`ALTER TABLE _smithers_runs ADD COLUMN heartbeat_at_ms INTEGER`,
|
|
336
|
-
`ALTER TABLE _smithers_runs ADD COLUMN runtime_owner_id TEXT`,
|
|
337
|
-
`ALTER TABLE _smithers_runs ADD COLUMN cancel_requested_at_ms INTEGER`,
|
|
338
|
-
`ALTER TABLE _smithers_runs ADD COLUMN hijack_requested_at_ms INTEGER`,
|
|
339
|
-
`ALTER TABLE _smithers_runs ADD COLUMN hijack_target TEXT`,
|
|
340
|
-
`ALTER TABLE _smithers_runs ADD COLUMN vcs_type TEXT`,
|
|
341
|
-
`ALTER TABLE _smithers_runs ADD COLUMN vcs_root TEXT`,
|
|
342
|
-
`ALTER TABLE _smithers_runs ADD COLUMN vcs_revision TEXT`,
|
|
343
|
-
`ALTER TABLE _smithers_runs ADD COLUMN parent_run_id TEXT`,
|
|
344
|
-
`ALTER TABLE _smithers_runs ADD COLUMN error_json TEXT`,
|
|
345
|
-
`ALTER TABLE _smithers_runs ADD COLUMN config_json TEXT`,
|
|
346
|
-
`ALTER TABLE _smithers_approvals ADD COLUMN request_json TEXT`,
|
|
347
|
-
`ALTER TABLE _smithers_approvals ADD COLUMN decision_json TEXT`,
|
|
348
|
-
`ALTER TABLE _smithers_approvals ADD COLUMN auto_approved INTEGER NOT NULL DEFAULT 0`,
|
|
349
|
-
`CREATE INDEX IF NOT EXISTS _smithers_runs_parent_idx ON _smithers_runs (parent_run_id)`,
|
|
350
|
-
// Ticket 0001: Alert model extensions
|
|
351
|
-
`ALTER TABLE _smithers_alerts ADD COLUMN fingerprint TEXT`,
|
|
352
|
-
`ALTER TABLE _smithers_alerts ADD COLUMN node_id TEXT`,
|
|
353
|
-
`ALTER TABLE _smithers_alerts ADD COLUMN iteration INTEGER`,
|
|
354
|
-
`ALTER TABLE _smithers_alerts ADD COLUMN owner TEXT`,
|
|
355
|
-
`ALTER TABLE _smithers_alerts ADD COLUMN runbook TEXT`,
|
|
356
|
-
`ALTER TABLE _smithers_alerts ADD COLUMN labels_json TEXT`,
|
|
357
|
-
`ALTER TABLE _smithers_alerts ADD COLUMN reaction_json TEXT`,
|
|
358
|
-
`ALTER TABLE _smithers_alerts ADD COLUMN source_event_type TEXT`,
|
|
359
|
-
`ALTER TABLE _smithers_alerts ADD COLUMN first_fired_at_ms INTEGER`,
|
|
360
|
-
`ALTER TABLE _smithers_alerts ADD COLUMN last_fired_at_ms INTEGER`,
|
|
361
|
-
`ALTER TABLE _smithers_alerts ADD COLUMN occurrence_count INTEGER DEFAULT 1`,
|
|
362
|
-
`ALTER TABLE _smithers_alerts ADD COLUMN silenced_until_ms INTEGER`,
|
|
363
|
-
`ALTER TABLE _smithers_alerts ADD COLUMN acknowledged_by TEXT`,
|
|
364
|
-
`ALTER TABLE _smithers_alerts ADD COLUMN resolved_by TEXT`,
|
|
365
|
-
`CREATE INDEX IF NOT EXISTS _smithers_alerts_fingerprint_idx ON _smithers_alerts (fingerprint)`,
|
|
366
|
-
`CREATE INDEX IF NOT EXISTS _smithers_alerts_run_status_idx ON _smithers_alerts (run_id, status)`,
|
|
367
|
-
];
|
|
368
331
|
/**
|
|
369
332
|
* @param {string} identifier
|
|
370
333
|
* @returns {string}
|
|
@@ -623,31 +586,10 @@ export class SqlMessageStorage {
|
|
|
623
586
|
ensureSchemaEffect() {
|
|
624
587
|
const sqlite = this.sqlite;
|
|
625
588
|
return Effect.sync(() => {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
try {
|
|
631
|
-
sqlite.run(statement);
|
|
632
|
-
}
|
|
633
|
-
catch {
|
|
634
|
-
// Ignore legacy migration failures for already-applied changes.
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
const frameColumns = sqlite
|
|
638
|
-
.query(`PRAGMA table_info("_smithers_frames")`)
|
|
639
|
-
.all();
|
|
640
|
-
if (!frameColumns.some((column) => column.name === "encoding")) {
|
|
641
|
-
try {
|
|
642
|
-
sqlite.run(`ALTER TABLE _smithers_frames ADD COLUMN encoding TEXT NOT NULL DEFAULT 'full'`);
|
|
643
|
-
}
|
|
644
|
-
catch {
|
|
645
|
-
// Ignore if another caller added it first.
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
for (const statement of CREATE_INDEX_STATEMENTS) {
|
|
649
|
-
sqlite.run(statement);
|
|
650
|
-
}
|
|
589
|
+
runSmithersSchemaMigrations(sqlite, {
|
|
590
|
+
createTableStatements: CREATE_TABLE_STATEMENTS,
|
|
591
|
+
createIndexStatements: CREATE_INDEX_STATEMENTS,
|
|
592
|
+
});
|
|
651
593
|
});
|
|
652
594
|
}
|
|
653
595
|
/**
|