Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions apps/cloud/src/services/db.schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import { describe, expect, it } from "@effect/vitest";
import { drizzle } from "drizzle-orm/postgres-js";
import { Effect } from "effect";
import postgres from "postgres";

import * as cloudSchema from "./schema";
Expand Down Expand Up @@ -44,20 +45,26 @@ describe("combinedSchema", () => {
// getters could theoretically drop tables if evaluated before their
// declarations. Construct a drizzle instance and walk its fullSchema
// to catch that class of bug too.
it("drizzle(combinedSchema) exposes every table under _.fullSchema", () => {
it.effect("drizzle(combinedSchema) exposes every table under _.fullSchema", () =>
// postgres() lazily connects — safe to build with a dummy url, we
// never .query() so no socket is opened.
const sql = postgres("postgres://u:p@127.0.0.1:1/x", { max: 1 });
try {
const db = drizzle(sql, { schema: combinedSchema });
const drizzleInternals = (value: unknown): { _: { fullSchema: Record<string, unknown> } } =>
value as { _: { fullSchema: Record<string, unknown> } };
const fullSchema = drizzleInternals(db)._.fullSchema;
for (const key of Object.keys(executorSchema)) {
expect(fullSchema, `fullSchema missing "${key}"`).toHaveProperty(key);
}
} finally {
sql.end({ timeout: 0 }).catch(() => undefined);
}
});
Effect.acquireRelease(
Effect.sync(() => postgres("postgres://u:p@127.0.0.1:1/x", { max: 1 })),
(sql) => Effect.promise(() => sql.end({ timeout: 0 })),
).pipe(
Effect.flatMap((sql) =>
Effect.sync(() => {
const db = drizzle(sql, { schema: combinedSchema });
const drizzleInternals = (
value: unknown,
): { _: { fullSchema: Record<string, unknown> } } =>
value as { _: { fullSchema: Record<string, unknown> } };
const fullSchema = drizzleInternals(db)._.fullSchema;
for (const key of Object.keys(executorSchema)) {
expect(fullSchema, `fullSchema missing "${key}"`).toHaveProperty(key);
}
}),
),
),
);
});
Loading