| 147 | ) |
| 148 | |
| 149 | const loadMigration = ([id, name, load]: ResolvedMigration) => |
| 150 | Effect.catchAllDefect(load, (_) => |
| 151 | Effect.fail( |
| 152 | new MigrationError({ |
| 153 | reason: "import-error", |
| 154 | message: `Could not import migration "${id}_${name}"\n\n${_}` |
| 155 | }) |
| 156 | )).pipe( |
| 157 | Effect.flatMap((_) => |
| 158 | Effect.isEffect(_) |
| 159 | ? Effect.succeed(_) |
| 160 | : _.default |
| 161 | ? Effect.succeed(_.default?.default ?? _.default) |
| 162 | : Effect.fail( |
| 163 | new MigrationError({ |
| 164 | reason: "import-error", |
| 165 | message: `Default export not found for migration "${id}_${name}"` |
| 166 | }) |
| 167 | ) |
| 168 | ), |
| 169 | Effect.filterOrFail( |
| 170 | (_): _ is Effect.Effect<unknown> => Effect.isEffect(_), |
| 171 | () => |
| 172 | new MigrationError({ |
| 173 | reason: "import-error", |
| 174 | message: `Default export was not an Effect for migration "${id}_${name}"` |
| 175 | }) |
| 176 | ) |
| 177 | ) |
| 178 | |
| 179 | const runMigration = ( |
| 180 | id: number, |