diff --git a/packages/db/collection.ts b/packages/db/collection.ts index 00e5aba18..309dced2b 100644 --- a/packages/db/collection.ts +++ b/packages/db/collection.ts @@ -6,6 +6,8 @@ import { dbEnv } from "@homarr/core/infrastructure/db/env"; import type { HomarrDatabase, HomarrDatabaseMysql, HomarrDatabasePostgresql } from "./driver"; import * as schema from "./schema"; +const tables = { ...schema }; + type TableKey = { [K in keyof typeof schema]: (typeof schema)[K] extends { _: { brand: "Table" } } ? K : never; }[keyof typeof schema]; @@ -36,7 +38,7 @@ export const createDbInsertCollectionForTransaction = = 1) { transaction - .insert(schema[key]) + .insert(tables[key]) .values(values as never) .run(); } @@ -50,7 +52,7 @@ export const createDbInsertCollectionForTransaction = = 1) { // Below is actually the mysqlSchema when the driver is mysql - await transaction.insert(schema[key] as never).values(values as never); + await transaction.insert(tables[key] as never).values(values as never); } } }); diff --git a/packages/db/test/schema.spec.ts b/packages/db/test/schema.spec.ts index 246219547..6606636e1 100644 --- a/packages/db/test/schema.spec.ts +++ b/packages/db/test/schema.spec.ts @@ -11,6 +11,9 @@ import * as mysqlSchema from "../schema/mysql"; import * as postgresqlSchema from "../schema/postgresql"; import * as sqliteSchema from "../schema/sqlite"; +const mysqlTables = { ...mysqlSchema }; +const postgresqlTables = { ...postgresqlSchema }; + // We need the following three types as there is currently no support for Buffer in mysql & pg and // so we use a custom type which results in the config beeing different type FixedMysqlConfig = { @@ -63,7 +66,7 @@ test("schemas should match", () => { if (!("uniqueName" in sqliteColumn)) return; if (!("primary" in sqliteColumn)) return; - const mysqlTable = mysqlSchema[tableName]; + const mysqlTable = mysqlTables[tableName]; const mysqlColumn = mysqlTable[columnName as keyof typeof mysqlTable] as object; if (!("isUnique" in mysqlColumn)) return; @@ -84,7 +87,7 @@ test("schemas should match", () => { ).toEqual(mysqlColumn.primary); }); - const mysqlTable = mysqlSchema[tableName]; + const mysqlTable = mysqlTables[tableName]; const sqliteForeignKeys = sqliteTable[Symbol.for("drizzle:SQLiteInlineForeignKeys") as keyof typeof sqliteTable] as | SqliteForeignKey[] | undefined; @@ -144,7 +147,7 @@ test("schemas should match for postgresql", () => { objectEntries(sqliteSchema).forEach(([tableName, sqliteTable]) => { // keys of sqliteSchema and postgresqlSchema are the same, so we can safely use tableName as key // skipcq: JS-E1007 - const postgresqlTable = postgresqlSchema[tableName]; + const postgresqlTable = postgresqlTables[tableName]; Object.entries(sqliteTable).forEach(([columnName, sqliteColumn]: [string, object]) => { if (!("isUnique" in sqliteColumn)) return; if (!("uniqueName" in sqliteColumn)) return;