refactor(server): split logic in to packages

This commit is contained in:
Mauricio Siu
2024-09-29 02:28:58 -06:00
parent 21dee4abac
commit 9b7aacc934
280 changed files with 28569 additions and 196 deletions

View File

@@ -0,0 +1,28 @@
import { type PostgresJsDatabase, drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
// import { sc } from "@dokploy/schema";
import * as schema from "./schema";
// schema
// import * as schema from "@dokploy/schema";
// type Schema = typeof schema;
// type Schema = typeof schema;
declare global {
// eslint-disable-next-line no-var -- only var works here
var db: PostgresJsDatabase<typeof schema> | undefined;
}
export let db: PostgresJsDatabase<typeof schema>;
if (process.env.NODE_ENV === "production") {
db = drizzle(postgres(process.env.DATABASE_URL || ""), {
schema,
});
} else {
if (!global.db)
global.db = drizzle(postgres(process.env.DATABASE_URL || ""), {
schema,
});
db = global.db;
}