Skip to content

Commit

Permalink
Merge pull request #68 from crux-bphc/fix-prod-staging-postgres-port-…
Browse files Browse the repository at this point in the history
…clash

Move postgres port to env var to avoid clash between staging and prod db
  • Loading branch information
majimearun authored Aug 1, 2023
2 parents ba3992a + 68527d3 commit 8ba8a04
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ POSTGRES_USER=""
PGUSER="" # should be same as POSTGRES_USER
POSTGRES_PASSWORD=""
POSTGRES_DB="" # should be same as POSTGRES_USER for some reason
POSTGRES_PORT=5432
DB_HOST="db"
NODE_ENV="development"
PROD_URL="http://localhost:3000"
Expand Down
1 change: 1 addition & 0 deletions .env.testing
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ POSTGRES_USER="chrono"
PGUSER="chrono" # should be same as POSTGRES_USER
POSTGRES_PASSWORD="aSBrbm93IHdoYXQgeW91IGFyZQ=="
POSTGRES_DB="chrono" # should be same as POSTGRES_USER for some reason
POSTGRES_PORT=5432
DB_HOST="db-testing"
NODE_ENV="development"
PROD_URL="http://localhost:3000"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ POSTGRES_USER="chrono"
PGUSER="chrono" # should be same as POSTGRES_USER
POSTGRES_PASSWORD="aSBrbm93IHdoYXQgeW91IGFyZQ=="
POSTGRES_DB="chrono" # should be same as POSTGRES_USER for some reason
POSTGRES_PORT=5432
DB_HOST="db"
NODE_ENV="development"
PROD_URL="http://localhost:3000"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
env_file:
- .env
ports:
- "5432:5432"
- "${POSTGRES_PORT}:5432"
healthcheck:
test: ["CMD", "pg_isready", "-d", "${POSTGRES_DB}"]
interval: 10s
Expand Down
1 change: 1 addition & 0 deletions src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const serverSchema = z.object({
POSTGRES_USER: z.string().min(1),
POSTGRES_PASSWORD: z.string().min(1),
POSTGRES_DB: z.string().min(1),
POSTGRES_PORT: z.coerce.number().default(5432),
DB_HOST: z.string().min(1),
PROD_URL: z.string().url().min(1),
FRONTEND_URL: z.string().url().min(1),
Expand Down
2 changes: 1 addition & 1 deletion src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { SearchHistory } from "./entity/SearchHistory";

export const AppDataSource = new DataSource({
type: "postgres",
url: `postgres://${env.POSTGRES_USER}:${env.POSTGRES_PASSWORD}@${env.DB_HOST}:5432?db=${env.POSTGRES_DB}`,
url: `postgres://${env.POSTGRES_USER}:${env.POSTGRES_PASSWORD}@${env.DB_HOST}:${env.POSTGRES_PORT}?db=${env.POSTGRES_DB}`,
synchronize: true,
logging: false,
entities: [User, Timetable, Course, Section, SearchHistory],
Expand Down

0 comments on commit 8ba8a04

Please sign in to comment.