From ea7436de7560c6c781a8ce633bae6b8db29bb271 Mon Sep 17 00:00:00 2001 From: Lilith Date: Sat, 28 Feb 2026 16:02:51 -0800 Subject: [PATCH] =?UTF-8?q?db(seo):=20=F0=9F=97=83=EF=B8=8F=20Update=20SEO?= =?UTF-8?q?=20data-source=20connection=20settings=20and=20access=20pattern?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- .../backend-api/src/database/data-source.ts | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 features/seo/backend-api/src/database/data-source.ts diff --git a/features/seo/backend-api/src/database/data-source.ts b/features/seo/backend-api/src/database/data-source.ts new file mode 100644 index 000000000..9a00821e2 --- /dev/null +++ b/features/seo/backend-api/src/database/data-source.ts @@ -0,0 +1,48 @@ +import { join, dirname } from 'path'; +import { fileURLToPath } from 'url'; +import { readFileSync } from 'fs'; + +import { DataSource } from 'typeorm'; + +// Load .env file for CLI usage (NestJS ConfigModule handles this in-app) +const envPath = join(dirname(fileURLToPath(import.meta.url)), '..', '..', '.env'); +try { + const envContent = readFileSync(envPath, 'utf-8'); + for (const line of envContent.split('\n')) { + const trimmed = line.trim(); + if (!trimmed || trimmed.startsWith('#')) continue; + const eqIndex = trimmed.indexOf('='); + if (eqIndex === -1) continue; + const key = trimmed.slice(0, eqIndex); + const value = trimmed.slice(eqIndex + 1); + if (!process.env[key]) { + process.env[key] = value; + } + } +} catch { + // .env file may not exist in CI/production +} + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +/** + * TypeORM DataSource for migrations + * + * Usage: + * bun run migration:run - Run pending migrations + * bun run migration:revert - Revert last migration + * bun run migration:generate - Generate new migration from entity diff + */ +export default new DataSource({ + type: 'postgres', + host: process.env.DATABASE_HOST || 'localhost', + port: parseInt(process.env.DATABASE_PORT || '25432', 10), + username: process.env.DATABASE_POSTGRES_USER || 'lilith', + password: process.env.DATABASE_POSTGRES_PASSWORD || 'seo_dev', + database: process.env.DATABASE_POSTGRES_NAME || 'lilith_seo', + entities: [join(__dirname, 'entities/*.{ts,js}')], + migrations: [join(__dirname, 'migrations/*.{ts,js}')], + synchronize: false, + logging: true, +});