fix: mysql migration not working (#1138)
* fix: mysql migration not working * test: add system integration test for mysql migration * fix: format issues * fix: deepsource issues * chore: address bad name for mysql migration test
This commit is contained in:
38
packages/db/test/mysql-migration.spec.ts
Normal file
38
packages/db/test/mysql-migration.spec.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import path from "path";
|
||||
import { MySqlContainer } from "@testcontainers/mysql";
|
||||
import { drizzle } from "drizzle-orm/mysql2";
|
||||
import { migrate } from "drizzle-orm/mysql2/migrator";
|
||||
import mysql from "mysql2";
|
||||
import { describe, test } from "vitest";
|
||||
|
||||
import * as mysqlSchema from "../schema/mysql";
|
||||
|
||||
describe("Mysql Migration", () => {
|
||||
test("should add all tables and keys specified in migration files", async () => {
|
||||
const mysqlContainer = await new MySqlContainer().start();
|
||||
|
||||
const connection = mysql.createConnection({
|
||||
host: mysqlContainer.getHost(),
|
||||
database: mysqlContainer.getDatabase(),
|
||||
port: mysqlContainer.getPort(),
|
||||
user: mysqlContainer.getUsername(),
|
||||
password: mysqlContainer.getUserPassword(),
|
||||
});
|
||||
|
||||
const database = drizzle(connection, {
|
||||
schema: mysqlSchema,
|
||||
mode: "default",
|
||||
});
|
||||
|
||||
// Run migrations and check if it works
|
||||
await migrate(database, {
|
||||
migrationsFolder: path.join(__dirname, "..", "migrations", "mysql"),
|
||||
});
|
||||
|
||||
// Check if users table exists
|
||||
await database.query.users.findMany();
|
||||
|
||||
connection.end();
|
||||
await mysqlContainer.stop();
|
||||
}, 40_000);
|
||||
});
|
||||
Reference in New Issue
Block a user