MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / seedLegacyScopedSqlite

Function seedLegacyScopedSqlite

apps/desktop/scripts/smoke-sidecar.ts:87–142  ·  view source on GitHub ↗
(dataDir: string, scopeId: string)

Source from the content-addressed store, hash-verified

85};
86
87const seedLegacyScopedSqlite = async (dataDir: string, scopeId: string): Promise<void> => {
88 const db = new Database(join(dataDir, "data.db"));
89 // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: standalone smoke harness closes the SQLite handle before spawning the sidecar
90 try {
91 // Replay the real legacy v1 chain so the fixture matches the migration
92 // history the sidecar's embedded copy expects. A hand-rolled partial
93 // schema that claims the full history is applied makes the v1→v2 data
94 // migration read tables that don't exist.
95 const migrations = await readLegacyMigrations();
96 for (const migration of migrations) {
97 // `--> statement-breakpoint` markers are SQL line comments, so the
98 // whole file executes as one multi-statement batch.
99 db.exec(migration.sql);
100 }
101
102 db.exec(`
103 CREATE TABLE "__drizzle_migrations" (
104 id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
105 hash text NOT NULL,
106 created_at numeric
107 );
108 `);
109 const insertMigration = db.prepare(
110 `INSERT INTO "__drizzle_migrations" (hash, created_at) VALUES (?, ?)`,
111 );
112 for (const migration of migrations) {
113 insertMigration.run(migration.hash, Date.now());
114 }
115
116 db.prepare(
117 `INSERT INTO source (
118 scope_id, id, plugin_id, kind, name, url, can_remove, can_refresh, can_edit, created_at, updated_at
119 ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
120 ).run(
121 scopeId,
122 "legacy-smoke",
123 "smoke",
124 "remote",
125 "Legacy Smoke Source",
126 null,
127 1,
128 0,
129 1,
130 1_700_000_000_000,
131 1_700_000_001_000,
132 );
133 db.prepare("INSERT INTO blob (namespace, key, value) VALUES (?, ?, ?)").run(
134 `${scopeId}/smoke`,
135 "legacy",
136 "{}",
137 );
138 db.exec("PRAGMA wal_checkpoint(TRUNCATE); PRAGMA journal_mode = DELETE;");
139 } finally {
140 db.close();
141 }
142};
143
144// The v1→v2 migration moves the legacy SQLite file set aside as

Callers 1

mainFunction · 0.85

Calls 3

readLegacyMigrationsFunction · 0.85
execMethod · 0.80
closeMethod · 0.65

Tested by

no test coverage detected