fix: mysql operations not working (#1728)
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
import Database from "better-sqlite3";
|
||||
|
||||
import { database } from "./driver";
|
||||
import * as sqliteSchema from "./schema/sqlite";
|
||||
|
||||
// Export only the types from the sqlite schema as we're using that.
|
||||
export const schema = sqliteSchema;
|
||||
|
||||
export * from "drizzle-orm";
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import { defaultServerSettings, defaultServerSettingsKeys } from "@homarr/server
|
||||
|
||||
import { createId, eq } from "..";
|
||||
import type { Database } from "..";
|
||||
import { onboarding, serverSettings } from "../schema";
|
||||
import { groups } from "../schema/mysql";
|
||||
import { onboarding, serverSettings } from "../schema/sqlite";
|
||||
|
||||
export const seedDataAsync = async (db: Database) => {
|
||||
await seedEveryoneGroupAsync(db);
|
||||
|
||||
@@ -2,7 +2,7 @@ import Database from "better-sqlite3";
|
||||
import { drizzle } from "drizzle-orm/better-sqlite3";
|
||||
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
|
||||
|
||||
import { schema } from "../..";
|
||||
import * as sqliteSchema from "../../schema/sqlite";
|
||||
import { seedDataAsync } from "../seed";
|
||||
|
||||
const migrationsFolder = process.argv[2] ?? ".";
|
||||
@@ -10,7 +10,7 @@ const migrationsFolder = process.argv[2] ?? ".";
|
||||
const migrateAsync = async () => {
|
||||
const sqlite = new Database(process.env.DB_URL?.replace("file:", ""));
|
||||
|
||||
const db = drizzle(sqlite, { schema, casing: "snake_case" });
|
||||
const db = drizzle(sqlite, { schema: sqliteSchema, casing: "snake_case" });
|
||||
|
||||
migrate(db, { migrationsFolder });
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"exports": {
|
||||
".": "./index.ts",
|
||||
"./client": "./client.ts",
|
||||
"./schema/sqlite": "./schema/sqlite.ts",
|
||||
"./schema": "./schema/index.ts",
|
||||
"./test": "./test/index.ts",
|
||||
"./queries": "./queries/index.ts",
|
||||
"./validationSchemas": "./validationSchemas.ts"
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { WidgetKind } from "@homarr/definitions";
|
||||
import type { Database } from "..";
|
||||
import { inArray } from "..";
|
||||
import type { inferSupportedIntegrations } from "../../widgets/src";
|
||||
import { items } from "../schema/sqlite";
|
||||
import { items } from "../schema";
|
||||
|
||||
export const getItemsWithIntegrationsAsync = async <TKind extends WidgetKind>(
|
||||
db: Database,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { defaultServerSettings, defaultServerSettingsKeys } from "@homarr/server
|
||||
|
||||
import type { Database } from "..";
|
||||
import { eq } from "..";
|
||||
import { serverSettings } from "../schema/sqlite";
|
||||
import { serverSettings } from "../schema";
|
||||
|
||||
export const getServerSettingsAsync = async (db: Database) => {
|
||||
const settings = await db.query.serverSettings.findMany();
|
||||
|
||||
45
packages/db/schema/index.ts
Normal file
45
packages/db/schema/index.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import type { InferSelectModel } from "drizzle-orm";
|
||||
|
||||
import * as mysqlSchema from "./mysql";
|
||||
import * as sqliteSchema from "./sqlite";
|
||||
|
||||
type Schema = typeof sqliteSchema;
|
||||
|
||||
const schema = process.env.DB_DRIVER === "mysql2" ? (mysqlSchema as unknown as Schema) : sqliteSchema;
|
||||
|
||||
// Sadly we can't use export * from here as we have multiple possible exports
|
||||
export const {
|
||||
accounts,
|
||||
apiKeys,
|
||||
apps,
|
||||
boardGroupPermissions,
|
||||
boardUserPermissions,
|
||||
boards,
|
||||
groupMembers,
|
||||
groupPermissions,
|
||||
groups,
|
||||
iconRepositories,
|
||||
icons,
|
||||
integrationGroupPermissions,
|
||||
integrationItems,
|
||||
integrationSecrets,
|
||||
integrationUserPermissions,
|
||||
integrations,
|
||||
invites,
|
||||
items,
|
||||
medias,
|
||||
onboarding,
|
||||
searchEngines,
|
||||
sections,
|
||||
serverSettings,
|
||||
sessions,
|
||||
users,
|
||||
verificationTokens,
|
||||
} = schema;
|
||||
|
||||
export type User = InferSelectModel<typeof schema.users>;
|
||||
export type Account = InferSelectModel<typeof schema.accounts>;
|
||||
export type Session = InferSelectModel<typeof schema.sessions>;
|
||||
export type VerificationToken = InferSelectModel<typeof schema.verificationTokens>;
|
||||
export type Integration = InferSelectModel<typeof schema.integrations>;
|
||||
export type IntegrationSecret = InferSelectModel<typeof schema.integrationSecrets>;
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { AdapterAccount } from "@auth/core/adapters";
|
||||
import type { DayOfWeek } from "@mantine/dates";
|
||||
import type { InferSelectModel } from "drizzle-orm";
|
||||
import { relations, sql } from "drizzle-orm";
|
||||
import type { AnySQLiteColumn } from "drizzle-orm/sqlite-core";
|
||||
import { blob, index, int, primaryKey, sqliteTable, text } from "drizzle-orm/sqlite-core";
|
||||
@@ -567,10 +566,3 @@ export const searchEngineRelations = relations(searchEngines, ({ one }) => ({
|
||||
references: [integrations.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export type User = InferSelectModel<typeof users>;
|
||||
export type Account = InferSelectModel<typeof accounts>;
|
||||
export type Session = InferSelectModel<typeof sessions>;
|
||||
export type VerificationToken = InferSelectModel<typeof verificationTokens>;
|
||||
export type Integration = InferSelectModel<typeof integrations>;
|
||||
export type IntegrationSecret = InferSelectModel<typeof integrationSecrets>;
|
||||
|
||||
@@ -2,11 +2,11 @@ import Database from "better-sqlite3";
|
||||
import { drizzle } from "drizzle-orm/better-sqlite3";
|
||||
import { migrate } from "drizzle-orm/better-sqlite3/migrator";
|
||||
|
||||
import { schema } from "..";
|
||||
import * as sqliteSchema from "../schema/sqlite";
|
||||
|
||||
export const createDb = (debug?: boolean) => {
|
||||
const sqlite = new Database(":memory:");
|
||||
const db = drizzle(sqlite, { schema, logger: debug, casing: "snake_case" });
|
||||
const db = drizzle(sqlite, { schema: sqliteSchema, logger: debug, casing: "snake_case" });
|
||||
migrate(db, {
|
||||
migrationsFolder: "./packages/db/migrations/sqlite",
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createSelectSchema } from "drizzle-zod";
|
||||
|
||||
import { apps, boards, groups, invites, searchEngines, serverSettings, users } from "./schema/sqlite";
|
||||
import { apps, boards, groups, invites, searchEngines, serverSettings, users } from "./schema";
|
||||
|
||||
export const selectAppSchema = createSelectSchema(apps);
|
||||
export const selectBoardSchema = createSelectSchema(boards);
|
||||
|
||||
Reference in New Issue
Block a user