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