feat(db): support postgresql database (#3643)

Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
This commit is contained in:
Yuichi Nakai
2025-08-30 03:30:03 +09:00
committed by GitHub
parent a4aa2aea90
commit 5168cba8e4
22 changed files with 3603 additions and 32 deletions

View File

@@ -6,6 +6,7 @@ import { createEnv } from "@homarr/core/infrastructure/env";
const drivers = {
betterSqlite3: "better-sqlite3",
mysql2: "mysql2",
nodePostgres: "node-postgres",
} as const;
const isDriver = (driver: (typeof drivers)[keyof typeof drivers]) => process.env.DB_DRIVER === driver;
@@ -21,7 +22,7 @@ export const env = createEnv({
*/
server: {
DB_DRIVER: z
.union([z.literal(drivers.betterSqlite3), z.literal(drivers.mysql2)], {
.union([z.literal(drivers.betterSqlite3), z.literal(drivers.mysql2), z.literal(drivers.nodePostgres)], {
message: `Invalid database driver, supported are ${Object.keys(drivers).join(", ")}`,
})
.default(drivers.betterSqlite3),
@@ -42,7 +43,7 @@ export const env = createEnv({
.regex(/\d+/)
.transform(Number)
.refine((number) => number >= 1)
.default(3306),
.default(isDriver(drivers.mysql2) ? 3306 : 5432),
DB_USER: z.string(),
DB_PASSWORD: z.string(),
DB_NAME: z.string(),