feat(database): configure PostgreSQL connection and apply initial migrations

This commit is contained in:
vickytechkey 2026-10-19 20:29:10 +05:30
parent ea2dd0275d
commit 4b58cd0afc
11 changed files with 102 additions and 22 deletions

View file

@ -1,7 +1,10 @@
# Docker Compose defaults. New installs use PostgreSQL 18. Existing PostgreSQL
# 16 installs must set POSTGRES_IMAGE_TAG=16-alpine until after a dump/restore.
POSTGRES_IMAGE_TAG=18-alpine
DATABASE_URL=postgres://postgres:postgres@postgres:5432/getcito
# PostgreSQL database configuration
DB_HOST=16.113.106.152
DB_PORT=5432
DB_USER=vignesh
DB_PASSWORD=vignesh_secret_pass_2026
DB_NAME=getcito
DATABASE_URL=postgres://vignesh:vignesh_secret_pass_2026@16.113.106.152:5432/getcito
DEPLOYMENT_MODE=local
VITE_DEPLOYMENT_MODE=local
BETTER_AUTH_SECRET=replace-with-random-hex

View file

@ -2,7 +2,12 @@
# Core Database & Application Settings
# ==============================================================================
# PostgreSQL connection string. (Required)
DATABASE_URL=postgres://postgres:postgres@localhost:5432/getcito
DB_HOST=16.113.106.152
DB_PORT=5432
DB_USER=vignesh
DB_PASSWORD=vignesh_secret_pass_2026
DB_NAME=getcito
DATABASE_URL=postgres://vignesh:vignesh_secret_pass_2026@16.113.106.152:5432/getcito
# Deployment mode: local, demo, whitelabel, or cloud. (Required)
DEPLOYMENT_MODE=local

View file

@ -1,4 +1,10 @@
DATABASE_URL=postgres://postgres:postgres@localhost:5432/getcito
# PostgreSQL database configuration
DB_HOST=16.113.106.152
DB_PORT=5432
DB_USER=vignesh
DB_PASSWORD=vignesh_secret_pass_2026
DB_NAME=getcito
DATABASE_URL=postgres://vignesh:vignesh_secret_pass_2026@16.113.106.152:5432/getcito
DEPLOYMENT_MODE=local
VITE_DEPLOYMENT_MODE=local
BETTER_AUTH_SECRET=replace-with-random-hex

View file

@ -17,10 +17,19 @@ export async function getBoss(): Promise<PgBoss> {
return bossPromise;
}
const connectionString = process.env.DATABASE_URL;
if (!connectionString) {
throw new Error("DATABASE_URL is required for pg-boss");
function getDatabaseUrl(): string {
if (process.env.DATABASE_URL) {
return process.env.DATABASE_URL;
}
const host = process.env.DB_HOST || "16.113.106.152";
const port = process.env.DB_PORT || "5432";
const user = process.env.DB_USER || "vignesh";
const pass = process.env.DB_PASSWORD || process.env.DB_PASS || "vignesh_secret_pass_2026";
const name = process.env.DB_NAME || "getcito";
return `postgres://${encodeURIComponent(user)}:${encodeURIComponent(pass)}@${host}:${port}/${name}`;
}
const connectionString = getDatabaseUrl();
bossPromise = (async () => {
const boss = new PgBoss({

View file

@ -14,8 +14,19 @@ import {
type FanoutModelTotalRow,
type FanoutPromptTotalRow,
} from "@/lib/fanout-analysis";
function getDatabaseUrl(): string {
if (process.env.DATABASE_URL) {
return process.env.DATABASE_URL;
}
const host = process.env.DB_HOST || "16.113.106.152";
const port = process.env.DB_PORT || "5432";
const user = process.env.DB_USER || "vignesh";
const pass = process.env.DB_PASSWORD || process.env.DB_PASS || "vignesh_secret_pass_2026";
const name = process.env.DB_NAME || "getcito";
return `postgres://${encodeURIComponent(user)}:${encodeURIComponent(pass)}@${host}:${port}/${name}`;
}
const db = drizzle(process.env.DATABASE_URL!);
const db = drizzle(getDatabaseUrl());
// ============================================================================
// Types

View file

@ -32,11 +32,20 @@ async function requireAdmin() {
// Postgres client helper for pg-boss queries
// ============================================================================
async function withPgClient<T>(fn: (client: Client) => Promise<T>): Promise<T> {
const connectionString = process.env.DATABASE_URL;
if (!connectionString) {
throw new Error("DATABASE_URL is required");
function getDatabaseUrl(): string {
if (process.env.DATABASE_URL) {
return process.env.DATABASE_URL;
}
const host = process.env.DB_HOST || "16.113.106.152";
const port = process.env.DB_PORT || "5432";
const user = process.env.DB_USER || "vignesh";
const pass = process.env.DB_PASSWORD || process.env.DB_PASS || "vignesh_secret_pass_2026";
const name = process.env.DB_NAME || "getcito";
return `postgres://${encodeURIComponent(user)}:${encodeURIComponent(pass)}@${host}:${port}/${name}`;
}
async function withPgClient<T>(fn: (client: Client) => Promise<T>): Promise<T> {
const connectionString = getDatabaseUrl();
const client = new Client({ connectionString });
await client.connect();
try {

View file

@ -1,11 +1,19 @@
import { PgBoss } from "pg-boss";
const connectionString = process.env.DATABASE_URL;
if (!connectionString) {
throw new Error("DATABASE_URL is required for pg-boss");
function getDatabaseUrl(): string {
if (process.env.DATABASE_URL) {
return process.env.DATABASE_URL;
}
const host = process.env.DB_HOST || "16.113.106.152";
const port = process.env.DB_PORT || "5432";
const user = process.env.DB_USER || "vignesh";
const pass = process.env.DB_PASSWORD || process.env.DB_PASS || "vignesh_secret_pass_2026";
const name = process.env.DB_NAME || "getcito";
return `postgres://${encodeURIComponent(user)}:${encodeURIComponent(pass)}@${host}:${port}/${name}`;
}
const connectionString = getDatabaseUrl();
const boss = new PgBoss({
connectionString,
// Use same DB as app, pg-boss creates its own schema

View file

@ -10,7 +10,7 @@ import pg from "pg";
import { TEST_USER, TEST_BRAND_ID, TEST_BRAND_NAME } from "./seed";
const AUTH_STATE_PATH = "e2e/.auth/user.json";
const DATABASE_URL = "postgres://postgres:postgres@localhost:5432/getcito";
const DATABASE_URL = process.env.DATABASE_URL || "postgres://vignesh:vignesh_secret_pass_2026@16.113.106.152:5432/getcito";
export default async function globalSetup(config: FullConfig) {
const baseURL = config.projects[0]?.use?.baseURL || "http://localhost:1515";

View file

@ -10,7 +10,7 @@
*/
import pg from "pg";
const DATABASE_URL = "postgres://postgres:postgres@localhost:5432/getcito";
const DATABASE_URL = process.env.DATABASE_URL || "postgres://vignesh:vignesh_secret_pass_2026@16.113.106.152:5432/getcito";
// ---------------------------------------------------------------------------
// Fixed IDs for test fixtures (so tests can reference them directly)

View file

@ -1,9 +1,22 @@
import { defineConfig } from "drizzle-kit";
function getDatabaseUrl(): string {
if (process.env.DATABASE_URL) {
return process.env.DATABASE_URL;
}
const host = process.env.DB_HOST || "16.113.106.152";
const port = process.env.DB_PORT || "5432";
const user = process.env.DB_USER || "vignesh";
const pass = process.env.DB_PASSWORD || process.env.DB_PASS || "vignesh_secret_pass_2026";
const name = process.env.DB_NAME || "getcito";
return `postgres://${encodeURIComponent(user)}:${encodeURIComponent(pass)}@${host}:${port}/${name}`;
}
export default defineConfig({
schema: ['./src/db/schema.ts', './src/db/schema-auth.ts'],
out: './src/db/migrations',
dialect: "postgresql",
dbCredentials: {
url: process.env.DATABASE_URL!,
url: getDatabaseUrl(),
},
});

View file

@ -2,6 +2,22 @@ import { drizzle } from "drizzle-orm/node-postgres";
import { Pool } from "pg";
import * as schema from "./schema";
export function getDatabaseUrl(): string {
if (process.env.DATABASE_URL) {
return process.env.DATABASE_URL;
}
const host = process.env.DB_HOST || "16.113.106.152";
const port = process.env.DB_PORT || "5432";
const user = process.env.DB_USER || "vignesh";
const pass = process.env.DB_PASSWORD || process.env.DB_PASS || "vignesh_secret_pass_2026";
const name = process.env.DB_NAME || "getcito";
return `postgres://${encodeURIComponent(user)}:${encodeURIComponent(pass)}@${host}:${port}/${name}`;
}
if (!process.env.DATABASE_URL) {
process.env.DATABASE_URL = getDatabaseUrl();
}
/**
* Connection ceiling per process. node-postgres defaults to 10, which the worker
* outgrew: a single prompt cycle writes a run and its citations for every model
@ -12,4 +28,4 @@ import * as schema from "./schema";
*/
const POOL_MAX = 20;
export const db = drizzle(new Pool({ connectionString: process.env.DATABASE_URL, max: POOL_MAX }), { schema });
export const db = drizzle(new Pool({ connectionString: getDatabaseUrl(), max: POOL_MAX }), { schema });