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

Function seedMinimalV1Db

apps/local/src/db/owned-database.test.ts:251–331  ·  view source on GitHub ↗
(dbPath: string, scopeId: string)

Source from the content-addressed store, hash-verified

249// a single openapi source makes isLocalV1Database return true and gives the
250// migration real content to carry into v2.
251const seedMinimalV1Db = async (dbPath: string, scopeId: string): Promise<void> => {
252 const client = await openLocalLibsql(dbPath);
253 // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: close the SQLite client even if seeding fails
254 try {
255 await client.execute("PRAGMA foreign_keys = OFF");
256 await client.execute(
257 "CREATE TABLE source (id text NOT NULL, scope_id text NOT NULL, plugin_id text NOT NULL, kind text NOT NULL, name text NOT NULL, PRIMARY KEY(scope_id, id))",
258 );
259 await client.execute(
260 "CREATE TABLE plugin_storage (id text NOT NULL, scope_id text NOT NULL, plugin_id text NOT NULL, collection text NOT NULL, key text NOT NULL, data text NOT NULL, created_at integer NOT NULL, updated_at integer NOT NULL, PRIMARY KEY(scope_id, id))",
261 );
262 await client.execute(
263 "CREATE TABLE credential_binding (id text NOT NULL, scope_id text NOT NULL, plugin_id text NOT NULL, source_id text NOT NULL, source_scope_id text NOT NULL, slot_key text NOT NULL, kind text NOT NULL, text_value text, secret_id text, connection_id text, created_at integer NOT NULL, updated_at integer NOT NULL, PRIMARY KEY(scope_id, id))",
264 );
265 await client.execute(
266 "CREATE TABLE secret (id text NOT NULL, scope_id text NOT NULL, name text NOT NULL, provider text NOT NULL, owned_by_connection_id text, created_at integer NOT NULL, PRIMARY KEY(scope_id, id))",
267 );
268 await client.execute(
269 "CREATE TABLE connection (id text NOT NULL, scope_id text NOT NULL, provider text NOT NULL, identity_label text, access_token_secret_id text, refresh_token_secret_id text, expires_at integer, provider_state text, PRIMARY KEY(scope_id, id))",
270 );
271 await client.execute(
272 "CREATE TABLE tool_policy (id text NOT NULL, scope_id text NOT NULL, pattern text NOT NULL, action text NOT NULL, position text NOT NULL, created_at integer NOT NULL, updated_at integer NOT NULL, PRIMARY KEY(scope_id, id))",
273 );
274 await client.execute(
275 "CREATE TABLE tool (id text NOT NULL, scope_id text NOT NULL, source_id text NOT NULL, plugin_id text NOT NULL, name text NOT NULL, description text NOT NULL, input_schema text, output_schema text, created_at integer NOT NULL, updated_at integer NOT NULL, PRIMARY KEY(scope_id, id))",
276 );
277
278 const now = Date.now();
279 await executeSql(
280 client,
281 "INSERT INTO source (id, scope_id, plugin_id, kind, name) VALUES (?, ?, ?, ?, ?)",
282 ["stripe_api", scopeId, "openapi", "openapi", "Stripe"],
283 );
284 await executeSql(
285 client,
286 "INSERT INTO plugin_storage (id, scope_id, plugin_id, collection, key, data, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
287 [
288 "openapi-source-stripe",
289 scopeId,
290 "openapi",
291 "source",
292 "stripe_api",
293 JSON.stringify({
294 config: {
295 spec: "{}",
296 headers: {
297 Authorization: { kind: "binding", slot: "header:authorization", prefix: "Bearer " },
298 },
299 },
300 }),
301 now,
302 now,
303 ],
304 );
305 await executeSql(
306 client,
307 "INSERT INTO credential_binding (id, scope_id, plugin_id, source_id, source_scope_id, slot_key, kind, text_value, secret_id, connection_id, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
308 [

Callers 1

Calls 4

openLocalLibsqlFunction · 0.90
executeSqlFunction · 0.90
executeMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected