2025-07-16 12:36:11 +02:00
|
|
|
import {drizzle} from "drizzle-orm/node-postgres";
|
|
|
|
|
|
2025-08-29 15:31:23 +02:00
|
|
|
import * as settings from "./schema/01_setting";
|
|
|
|
|
import * as user from "./schema/02_user";
|
|
|
|
|
import * as organisation from "./schema/03_organization";
|
|
|
|
|
import * as invitation from "./schema/04_member";
|
|
|
|
|
import * as member from "./schema/05_invitation";
|
|
|
|
|
import * as project from "./schema/06_project";
|
|
|
|
|
import * as agent from "./schema/08_agent";
|
|
|
|
|
import * as database from "./schema/07_database";
|
2025-11-09 16:47:58 +01:00
|
|
|
import * as notificationChannel from "./schema/09_notification-channel";
|
|
|
|
|
import * as organizationNotificationChannel from "./schema/09_notification-channel";
|
2025-07-16 12:36:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
import {Pool} from "pg";
|
|
|
|
|
|
|
|
|
|
// Do not delete
|
2025-05-16 15:54:17 +02:00
|
|
|
import dotenv from "dotenv";
|
2025-07-16 12:36:11 +02:00
|
|
|
import {migrate} from "drizzle-orm/node-postgres/migrator";
|
2025-05-16 15:54:17 +02:00
|
|
|
|
|
|
|
|
dotenv.config({
|
|
|
|
|
path: ".env",
|
|
|
|
|
});
|
|
|
|
|
|
2025-07-16 12:36:11 +02:00
|
|
|
const pool = new Pool({
|
|
|
|
|
connectionString: process.env.DATABASE_URL!,
|
2025-05-16 15:54:17 +02:00
|
|
|
});
|
2025-07-16 12:36:11 +02:00
|
|
|
|
|
|
|
|
export const schemas = {
|
|
|
|
|
...settings,
|
|
|
|
|
...user,
|
|
|
|
|
...organisation,
|
|
|
|
|
...invitation,
|
|
|
|
|
...member,
|
|
|
|
|
...project,
|
|
|
|
|
...agent,
|
2025-11-09 16:47:58 +01:00
|
|
|
...database,
|
|
|
|
|
...notificationChannel,
|
|
|
|
|
...organizationNotificationChannel
|
2025-07-16 12:36:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const db = drizzle({
|
|
|
|
|
client: pool,
|
2025-11-08 20:07:49 +01:00
|
|
|
// logger: process.env.NODE_ENV != 'production',
|
2025-07-16 12:36:11 +02:00
|
|
|
schema: schemas,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export async function makeMigration() {
|
|
|
|
|
if (process.env.NODE_ENV != "development") {
|
|
|
|
|
const pool = new Pool({
|
|
|
|
|
connectionString: process.env.DATABASE_URL!,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const database = drizzle({client: pool});
|
|
|
|
|
|
|
|
|
|
console.log("Running migrations...");
|
|
|
|
|
try {
|
|
|
|
|
await migrate(database, {migrationsFolder: "./src/db/migrations"});
|
|
|
|
|
console.log("Migrations applied successfully.");
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error applying migrations:", error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|