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