fix: revert DB driver to static imports, fix test regressions
- Revert createRequire() for DB drivers — require() can't resolve .ts files in Vitest, breaking 49 test suites - Make cache invalidation fail-safe via try-catch around revalidateTag (throws outside Next.js context: tests, tasks service, websocket) - Fix 6 integration test imports: barrel no longer exports concrete classes, point tests at direct source paths - Fix Redis cache handler lint errors: remove non-null assertions, suppress __NEXT_BUILD_ID underscore warning
This commit is contained in:
11 files changed
+174
-87
No files matched your search
@@ -1,15 +1,12 @@
|
||||
import { createRequire } from "node:module";
|
||||
|
||||
import { DB_CASING } from "../constants";
|
||||
import { dbEnv } from "../env";
|
||||
import { createDbMapping } from "../mapping";
|
||||
import { createMysqlDb } from "./mysql";
|
||||
import { createPostgresDb } from "./postgresql";
|
||||
import type { SharedDrizzleConfig } from "./shared";
|
||||
import { WinstonDrizzleLogger } from "./shared";
|
||||
import { createSqliteDb } from "./sqlite";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
export type Database<TSchema extends Record<string, unknown>> = ReturnType<
|
||||
typeof import("./sqlite").createSqliteDb<TSchema>
|
||||
>;
|
||||
export type Database<TSchema extends Record<string, unknown>> = ReturnType<typeof createSqliteDb<TSchema>>;
|
||||
|
||||
export const createSharedConfig = <TSchema extends Record<string, unknown>>(
|
||||
schema: TSchema,
|
||||
@@ -21,15 +18,10 @@ export const createSharedConfig = <TSchema extends Record<string, unknown>>(
|
||||
|
||||
export const createDb = <TSchema extends Record<string, unknown>>(schema: TSchema) => {
|
||||
const config = createSharedConfig(schema);
|
||||
// ponytail: conditional require — only the configured driver is loaded.
|
||||
// Ceiling: all 3 stay on disk for runtime driver switching; only loaded graph shrinks.
|
||||
const driver = dbEnv.DRIVER ?? "better-sqlite3";
|
||||
switch (driver) {
|
||||
case "mysql2":
|
||||
return (require("./mysql") as typeof import("./mysql")).createMysqlDb(config);
|
||||
case "node-postgres":
|
||||
return (require("./postgresql") as typeof import("./postgresql")).createPostgresDb(config);
|
||||
default:
|
||||
return (require("./sqlite") as typeof import("./sqlite")).createSqliteDb(config);
|
||||
}
|
||||
|
||||
return createDbMapping({
|
||||
mysql2: () => createMysqlDb(config),
|
||||
"node-postgres": () => createPostgresDb(config),
|
||||
"better-sqlite3": () => createSqliteDb(config),
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user