refactor(db): move to core package (#4589)

This commit is contained in:
Meier Lukas
2025-12-17 08:59:52 +01:00
committed by GitHub
parent e954ea861c
commit 298a96054e
30 changed files with 258 additions and 217 deletions

View File

@@ -2,11 +2,13 @@ import Database from "better-sqlite3";
import { drizzle } from "drizzle-orm/better-sqlite3";
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
import { DB_CASING } from "@homarr/core/infrastructure/db/constants";
import * as sqliteSchema from "../schema/sqlite";
export const createDb = (debug?: boolean) => {
const sqlite = new Database(":memory:");
const db = drizzle(sqlite, { schema: sqliteSchema, logger: debug, casing: "snake_case" });
const db = drizzle(sqlite, { schema: sqliteSchema, logger: debug, casing: DB_CASING });
migrate(db, {
migrationsFolder: "./packages/db/migrations/sqlite",
});

View File

@@ -5,6 +5,8 @@ import { migrate } from "drizzle-orm/mysql2/migrator";
import mysql from "mysql2";
import { describe, test } from "vitest";
import { DB_CASING } from "@homarr/core/infrastructure/db/constants";
import * as mysqlSchema from "../schema/mysql";
describe("Mysql Migration", () => {
@@ -22,7 +24,7 @@ describe("Mysql Migration", () => {
const database = drizzle(connection, {
schema: mysqlSchema,
mode: "default",
casing: "snake_case",
casing: DB_CASING,
});
// Run migrations and check if it works

View File

@@ -5,6 +5,8 @@ import { migrate } from "drizzle-orm/node-postgres/migrator";
import { Pool } from "pg";
import { describe, test } from "vitest";
import { DB_CASING } from "@homarr/core/infrastructure/db/constants";
import * as pgSchema from "../schema/postgresql";
describe("PostgreSql Migration", () => {
@@ -26,7 +28,7 @@ describe("PostgreSql Migration", () => {
const database = drizzle({
schema: pgSchema,
casing: "snake_case",
casing: DB_CASING,
client: pool,
});