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

Function insertPlan

apps/local/src/db/v1-v2-migration.ts:784–1004  ·  view source on GitHub ↗
(
  client: Client,
  snapshot: LocalV1Snapshot,
  plan: MigrationPlan,
  idOverrides: ReadonlyMap<string, string>,
  oauthClientIdValues: ReadonlyMap<string, string>,
  oauthAuthorizationUrls: ReadonlyMap<string, string>,
  tenantId: string,
  secretValues: CollectedSecretValues,
)

Source from the content-addressed store, hash-verified

782};
783
784const insertPlan = async (
785 client: Client,
786 snapshot: LocalV1Snapshot,
787 plan: MigrationPlan,
788 idOverrides: ReadonlyMap<string, string>,
789 oauthClientIdValues: ReadonlyMap<string, string>,
790 oauthAuthorizationUrls: ReadonlyMap<string, string>,
791 tenantId: string,
792 secretValues: CollectedSecretValues,
793): Promise<void> => {
794 const now = timestamp();
795 const ownerForScope = localOwnerForScope(tenantId);
796 const connectionTargets = plan.connections.map((connection) => ({
797 sourceScopeId: connection.sourceScopeId,
798 sourceId: connection.sourceId,
799 tenant: connection.row.tenant,
800 owner: connection.row.owner,
801 subject: ownerSubject(connection.row.owner, connection.row.subject),
802 connection: connection.row.name,
803 }));
804 const runtimeMetadata = buildV1RuntimeMetadataIndex(snapshot.pluginStorage);
805 const targetsFor = (scopeId: string, sourceId: string) =>
806 connectionTargets.filter(
807 (target) => target.sourceScopeId === scopeId && target.sourceId === sourceId,
808 );
809
810 await client.execute("BEGIN");
811 try {
812 for (const row of plan.integrations) {
813 await executeSql(
814 client,
815 "INSERT INTO integration (slug, plugin_id, description, config, can_remove, can_refresh, created_at, updated_at, row_id, tenant) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
816 [
817 row.slug,
818 row.plugin_id,
819 row.description,
820 jsonText(row.config),
821 1,
822 0,
823 now,
824 now,
825 createId(),
826 row.tenant,
827 ],
828 );
829 }
830
831 for (const clientRow of plan.oauthClients) {
832 await executeSql(
833 client,
834 "INSERT INTO oauth_client (slug, authorization_url, token_url, grant, client_id, client_secret_item_id, resource, created_at, row_id, tenant, owner, subject) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
835 [
836 clientRow.slug,
837 authorizationUrlFor(clientRow, oauthAuthorizationUrls),
838 clientRow.tokenUrl,
839 clientRow.grant,
840 clientIdFor(clientRow, oauthClientIdValues),
841 mapId(clientRow.clientSecretItemId, idOverrides),

Callers 1

Calls 15

executeSqlFunction · 0.90
migrateV1ToolAnnotationsFunction · 0.90
timestampFunction · 0.85
localOwnerForScopeFunction · 0.85
jsonTextFunction · 0.85
clientIdForFunction · 0.85
mapIdFunction · 0.85
mapItemIdsFunction · 0.85
sqliteBigintTextFunction · 0.85
targetsForFunction · 0.85

Tested by

no test coverage detected