( client: SqliteDataMigrationClient, org: OrgPlan, )
| 284 | }); |
| 285 | |
| 286 | const applyOrg = ( |
| 287 | client: SqliteDataMigrationClient, |
| 288 | org: OrgPlan, |
| 289 | ): Effect.Effect<void, DataMigrationError> => |
| 290 | Effect.gen(function* () { |
| 291 | if (org.completed) return; |
| 292 | if (org.hardErrors.length > 0) return; |
| 293 | const now = Date.now(); |
| 294 | |
| 295 | for (const copy of org.blobCopies.filter((item) => item.backend === "database")) { |
| 296 | const source = yield* execute(client, { |
| 297 | sql: "SELECT value FROM blob WHERE namespace = ? AND key = ? LIMIT 1", |
| 298 | args: [copy.sourceNamespace, copy.key], |
| 299 | }); |
| 300 | const sourceRow = source.rows[0]; |
| 301 | if (!sourceRow || typeof sourceRow.value !== "string") { |
| 302 | return yield* new DataMigrationError({ |
| 303 | migration: MIGRATION_NAME, |
| 304 | cause: `Missing source blob ${copy.sourceNamespace}/${copy.key}`, |
| 305 | }); |
| 306 | } |
| 307 | yield* execute(client, { |
| 308 | sql: `INSERT OR IGNORE INTO blob (namespace, key, value, row_id, id) |
| 309 | VALUES (?, ?, ?, ?, ?)`, |
| 310 | args: [ |
| 311 | copy.targetNamespace, |
| 312 | copy.key, |
| 313 | sourceRow.value, |
| 314 | stableId("blob", org.tenant, copy.targetNamespace, copy.key), |
| 315 | JSON.stringify([copy.targetNamespace, copy.key]), |
| 316 | ], |
| 317 | }); |
| 318 | } |
| 319 | |
| 320 | for (const row of org.integrations.filter((item) => item.action === "create")) { |
| 321 | yield* execute(client, { |
| 322 | sql: `INSERT OR IGNORE INTO integration |
| 323 | (slug, plugin_id, name, description, config, health_check, config_revised_at, |
| 324 | can_remove, can_refresh, created_at, updated_at, row_id, tenant) |
| 325 | VALUES (?, ?, ?, ?, ?, ?, NULL, 1, 1, ?, ?, ?, ?)`, |
| 326 | args: [ |
| 327 | row.target.slug, |
| 328 | row.target.pluginId, |
| 329 | row.target.name, |
| 330 | row.target.description, |
| 331 | JSON.stringify(scrubJson(row.config)), |
| 332 | row.healthCheck ? JSON.stringify(scrubJson(row.healthCheck)) : null, |
| 333 | now, |
| 334 | now, |
| 335 | stableId("integration", org.tenant, row.target.slug), |
| 336 | org.tenant, |
| 337 | ], |
| 338 | }); |
| 339 | } |
| 340 | |
| 341 | for (const row of org.connections.filter((item) => item.action === "clone")) { |
| 342 | yield* execute(client, { |
| 343 | sql: `INSERT OR IGNORE INTO connection |
no test coverage detected