Unified · Split
| @@ -7,7 +7,7 @@ · 6 unmodified lines | ||
| 7 | 7 | // cloud test DB on 5434. |
| 8 | 8 | |
| 9 | 9 | import { describe, expect, it } from "@effect/vitest"; |
| 10 | −import { Effect } from "effect"; | |
| 10 | +import { Data, Effect } from "effect"; | |
| 11 | 11 | import postgres from "postgres"; |
| 12 | 12 | import { drizzle } from "drizzle-orm/postgres-js"; |
| 13 | 13 | import { relations } from "drizzle-orm"; |
| @@ -21,7 +21,7 @@ import { · 7 unmodified lines | ||
| 21 | 21 | jsonb, |
| 22 | 22 | } from "drizzle-orm/pg-core"; |
| 23 | 23 | |
| 24 | −import type { DBAdapter } from "@executor-js/storage-core"; | |
| 24 | +import type { DBAdapter, StorageFailure } from "@executor-js/storage-core"; | |
| 25 | 25 | import { |
| 26 | 26 | conformanceSchema, |
| 27 | 27 | runAdapterConformance, |
| @@ -31,6 +31,13 @@ import { makePostgresAdapter } from "./index"; · 3 unmodified lines | ||
| 31 | 31 | |
| 32 | 32 | const url = "postgresql://postgres:postgres@127.0.0.1:5435/postgres"; |
| 33 | 33 | |
| 34 | +class PostgresTestDatabaseError extends Data.TaggedError( | |
| 35 | + "PostgresTestDatabaseError", | |
| 36 | +)<{ | |
| 37 | + readonly message: string; | |
| 38 | + readonly cause: unknown; | |
| 39 | +}> {} | |
| 40 | + | |
| 34 | 41 | // max=1 so BEGIN/COMMIT sent via `db.execute(sql.raw(...))` always hit |
| 35 | 42 | // the same connection — postgres.js with a larger pool rejects unsafe |
| 36 | 43 | // transaction control that isn't bound to a single reserved client. |
| @@ -135,9 +142,10 @@ const createConformanceTables = Effect.tryPromise({ · 98 unmodified lines | ||
| 135 | 142 | ); |
| 136 | 143 | }, |
| 137 | 144 | catch: (cause) => |
| 138 | − new Error( | |
| 139 | − `failed to create postgres conformance tables: ${String(cause)}`, | |
| 140 | − ), | |
| 145 | + new PostgresTestDatabaseError({ | |
| 146 | + message: "failed to create postgres conformance tables", | |
| 147 | + cause, | |
| 148 | + }), | |
| 141 | 149 | }); |
| 142 | 150 | |
| 143 | 151 | const resetTables = Effect.gen(function* () { |
| @@ -145,18 +153,19 @@ const resetTables = Effect.gen(function* () { · 1 unmodified line | ||
| 145 | 153 | try: () => |
| 146 | 154 | sql`DROP TABLE IF EXISTS "source", "tag", "source_tag", "with_defaults", "blob" CASCADE`.then( |
| 147 | 155 | () => undefined, |
| 148 | − ), | |
| 156 | + ), | |
| 149 | 157 | catch: (cause) => |
| 150 | − new Error( | |
| 151 | − `failed to reset postgres conformance tables: ${String(cause)}`, | |
| 152 | − ), | |
| 158 | + new PostgresTestDatabaseError({ | |
| 159 | + message: "failed to reset postgres conformance tables", | |
| 160 | + cause, | |
| 161 | + }), | |
| 153 | 162 | }); |
| 154 | 163 | yield* createConformanceTables; |
| 155 | 164 | }); |
| 156 | 165 | |
| 157 | 166 | const withAdapter = <A, E>( |
| 158 | 167 | fn: (adapter: DBAdapter) => Effect.Effect<A, E>, |
| 159 | −): Effect.Effect<A, E | Error> => | |
| 168 | +): Effect.Effect<A, E | StorageFailure | PostgresTestDatabaseError> => | |
| 160 | 169 | Effect.gen(function* () { |
| 161 | 170 | yield* resetTables; |
| 162 | 171 | const db = drizzle(sql, { schema: conformanceTables }); |
| @@ -165,7 +174,7 @@ const withAdapter = <A, E>( · 2 unmodified lines | ||
| 165 | 174 | schema: conformanceSchema, |
| 166 | 175 | }); |
| 167 | 176 | return yield* fn(adapter); |
| 168 | − }) as Effect.Effect<A, E | Error>; | |
| 177 | + }); | |
| 169 | 178 | |
| 170 | 179 | runAdapterConformance("postgres", withAdapter); |
| 171 | 180 | |
| @@ -191,7 +200,10 @@ const resetScopedTable = Effect.tryPromise({ · 19 unmodified lines | ||
| 191 | 200 | ); |
| 192 | 201 | }, |
| 193 | 202 | catch: (cause) => |
| 194 | − new Error(`failed to reset scoped_item table: ${String(cause)}`), | |
| 203 | + new PostgresTestDatabaseError({ | |
| 204 | + message: "failed to reset scoped_item table", | |
| 205 | + cause, | |
| 206 | + }), | |
| 195 | 207 | }); |
| 196 | 208 | |
| 197 | 209 | const makeScopedAdapter = () => |