MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / resetDB

Function resetDB

packages/core/fumadb/test/shared.ts:440–569  ·  view source on GitHub ↗
(provider: SQLProvider)

Source from the content-addressed store, hash-verified

438}
439
440export async function resetDB(provider: SQLProvider) {
441 const kysely = kyselyTests.find((kysely) => kysely.provider === provider)!;
442 const db = kysely.db as Kysely<any>;
443
444 if (provider === "mysql") {
445 await db.transaction().execute(async () => {
446 await sql`SET FOREIGN_KEY_CHECKS = 0`.execute(db);
447 const tables = await db
448 .selectFrom("information_schema.tables")
449 .select("TABLE_NAME")
450 .where((b) =>
451 b.or([
452 b("TABLE_SCHEMA", "not in", [
453 "mysql",
454 "performance_schema",
455 "information_schema",
456 "sys",
457 ]),
458 b("TABLE_NAME", "=", "__drizzle_migrations"),
459 ]),
460 )
461 .where("TABLE_TYPE", "=", "BASE TABLE")
462 .execute();
463 for (const table of tables) {
464 await db.schema.dropTable(table.TABLE_NAME).ifExists().execute();
465 }
466
467 await sql`SET FOREIGN_KEY_CHECKS = 1`.execute(db);
468 });
469
470 return;
471 }
472
473 if (provider === "sqlite") {
474 const tables = await db
475 .selectFrom("sqlite_master")
476 .select("name")
477 .where("type", "=", "table")
478 .where("name", "not like", "sqlite_%")
479 .execute();
480
481 await sql`PRAGMA foreign_keys = OFF`.execute(db);
482 await Promise.all(
483 tables.map((table) =>
484 db.schema.dropTable(table.name).ifExists().execute(),
485 ),
486 );
487 await sql`PRAGMA foreign_keys = ON`.execute(db);
488 return;
489 }
490
491 if (provider === "postgresql" || provider === "cockroachdb") {
492 const tables = await db
493 .selectFrom("information_schema.tables")
494 .select(["table_schema", "table_name"])
495 .where("table_type", "=", "BASE TABLE")
496 .where("table_schema", "not in", [
497 "pg_catalog",

Callers 4

migrate.test.tsFile · 0.90
cli.tsFile · 0.90
query.test.tsFile · 0.90
relations.test.tsFile · 0.90

Calls 2

executeMethod · 0.65
transactionMethod · 0.65

Tested by

no test coverage detected