// db.ts
import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
import * as documentsSchema from "@/app/db/surveyDB/schema/surveyDB";

export const pool = new Pool({
  host: process.env.DOCUMENTS_DB_HOST,
  port: Number(process.env.DOCUMENTS_DB_PORT),
  user: process.env.DOCUMENTS_DB_USERNAME,
  password: process.env.DOCUMENTS_DB_PASSWORD,
  database: process.env.DOCUMENTS_DB_NAME,
  max: 20,
  idleTimeoutMillis: 30000,
  ssl: {
    rejectUnauthorized: false, // set to true if you're using a CA-signed cert
  },
});

const schema = {
  ...documentsSchema,
};

export const surveyDB = drizzle(pool, {
  schema: schema,
});
