feat(db): db stuff added in starting migration from old app

This commit is contained in:
2025-08-31 15:01:50 -05:00
parent f348e4e053
commit 2d5fbbbab0
11 changed files with 965 additions and 36 deletions

View File

@@ -5,6 +5,8 @@ import { setupRoutes } from "./internal/routerHandler/routeHandler.js";
import { printers } from "./internal/ocp/printers/printers.js";
import path, { dirname, join } from "path";
import { fileURLToPath } from "url";
import { db } from "./pkg/db/db.js";
import { settings } from "./pkg/db/schema/settings.js";
const PORT = Number(process.env.VITE_PORT) || 4200;
@@ -19,7 +21,13 @@ const main = async () => {
const __dirname = dirname(__filename);
// Db connection stuff
try {
const set = await db.select().from(settings);
console.log(set);
} catch (error) {
console.error("Error getting settings", error);
}
// express app
const app = express();

16
app/src/pkg/db/db.ts Normal file
View File

@@ -0,0 +1,16 @@
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
const dbURL = `postgres://${process.env.DATABASE_USER}:${process.env.DATABASE_PASSWORD}@${process.env.DATABASE_HOST}:${process.env.DATABASE_PORT}/${process.env.DATABASE_DB}`;
const queryClient = postgres(dbURL, {
max: 10,
idle_timeout: 60,
connect_timeout: 30,
max_lifetime: 1000 * 60 * 5, // 5 min time out
onnotice: (notice) => {
console.log("PG notice: ", notice.message);
},
});
export const db = drizzle({ client: queryClient });

View File

@@ -0,0 +1,34 @@
import type { InferInsertModel, InferSelectModel } from "drizzle-orm";
import {
text,
pgTable,
timestamp,
uuid,
uniqueIndex,
jsonb,
boolean,
} from "drizzle-orm/pg-core";
export const settings = pgTable(
"settings",
{
settings_id: uuid("settings_id").defaultRandom().primaryKey(),
name: text("name").notNull(),
value: text("value").notNull(), // this is used in junction with active, only needed if the setting isnt a bool
description: text("description"),
moduleName: text("moduleName"), // what part of lst dose it belong to this is used to split the settings out later
active: boolean("active").default(true),
roles: jsonb("roles").notNull().default(["systemAdmin"]), // role or roles to see this goes along with the moduleName, need to have a x role in module to see this setting.
add_User: text("add_User").default("LST_System").notNull(),
add_Date: timestamp("add_Date").defaultNow(),
upd_user: text("upd_User").default("LST_System").notNull(),
upd_date: timestamp("upd_date").defaultNow(),
},
(table) => [
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
uniqueIndex("name").on(table.name),
]
);
export type Setting = InferSelectModel<typeof settings>;
export type NewSetting = InferInsertModel<typeof settings>;