database ssl connection fix

This commit is contained in:
dal 2025-09-22 08:32:06 -06:00
parent c9f5a64999
commit e63fd79df5
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
3 changed files with 43 additions and 2 deletions

View File

@ -10,12 +10,20 @@ if (!connectionString) {
throw new Error('DATABASE_URL environment variable is not defined');
}
// Disable SSL for local development
const isDevelopment = process.env.ENVIRONMENT === 'development' || process.env.NODE_ENV === 'development';
// Append sslmode=disable for local development if not already present
const dbUrl = isDevelopment && !connectionString.includes('sslmode=')
? `${connectionString}?sslmode=disable`
: connectionString;
export default defineConfig({
schema: './src/schema.ts',
out: './drizzle',
dialect: 'postgresql',
dbCredentials: {
url: connectionString || '',
url: dbUrl || '',
},
verbose: true,
strict: true,

View File

@ -1,3 +1,14 @@
import { config } from 'dotenv';
import * as path from 'path';
import { fileURLToPath } from 'url';
// Get the directory name for ES modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Load environment variables from root .env file
config({ path: path.resolve(__dirname, '../../../.env') });
import { drizzle } from 'drizzle-orm/postgres-js';
import type { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
@ -49,12 +60,17 @@ export function initializePool<T extends Record<string, postgres.PostgresType>>(
}
// Create postgres client with pool configuration
// Disable SSL for local development
const isDevelopment = process.env.ENVIRONMENT === 'development' || process.env.NODE_ENV === 'development';
console.log('Database connection - ENVIRONMENT:', process.env.ENVIRONMENT, 'NODE_ENV:', process.env.NODE_ENV, 'isDevelopment:', isDevelopment);
globalPool = postgres(connectionString, {
max: poolSize,
idle_timeout: 30,
connect_timeout: 30,
prepare: true,
ssl: {
ssl: isDevelopment ? false : {
rejectUnauthorized: false, // Allow self-signed certificates
},
...config,

View File

@ -100,6 +100,23 @@
"env": [
"NODE_TLS_REJECT_UNAUTHORIZED"
]
},
"db:seed": {
"cache": false,
"env": [
"DATABASE_URL",
"ENVIRONMENT",
"NODE_ENV"
]
},
"db:init": {
"cache": false,
"dependsOn": ["db:migrate"],
"env": [
"DATABASE_URL",
"ENVIRONMENT",
"NODE_ENV"
]
}
},
"globalEnv": [