mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Working on the organization system.
This commit is contained in:
+53
-6
@@ -1,13 +1,60 @@
|
||||
import "dotenv/config";
|
||||
import { drizzle } from "drizzle-orm/node-postgres";
|
||||
import {drizzle} from "drizzle-orm/node-postgres";
|
||||
|
||||
import * as settings from "./schema/00_setting";
|
||||
import * as user from "./schema/01_user";
|
||||
import * as organisation from "./schema/02_organization";
|
||||
import * as invitation from "./schema/03_member";
|
||||
import * as member from "./schema/04_invitation";
|
||||
import * as project from "./schema/05_project";
|
||||
import * as agent from "./schema/07_agent";
|
||||
import * as database from "./schema/06_database";
|
||||
|
||||
|
||||
import {Pool} from "pg";
|
||||
|
||||
// Do not delete
|
||||
import dotenv from "dotenv";
|
||||
import { env } from "@/env.mjs";
|
||||
import * as schema from "./schema";
|
||||
import {migrate} from "drizzle-orm/node-postgres/migrator";
|
||||
|
||||
dotenv.config({
|
||||
path: ".env",
|
||||
});
|
||||
|
||||
export const db = drizzle(env.DATABASE_URL!, {
|
||||
schema,
|
||||
const pool = new Pool({
|
||||
connectionString: process.env.DATABASE_URL!,
|
||||
});
|
||||
|
||||
export const schemas = {
|
||||
...settings,
|
||||
...user,
|
||||
...organisation,
|
||||
...invitation,
|
||||
...member,
|
||||
...project,
|
||||
...agent,
|
||||
...database
|
||||
};
|
||||
|
||||
export const db = drizzle({
|
||||
client: pool,
|
||||
logger: true,
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user