Skip to content

feat(db): migrate database service from Neon to Docker Postgres - #5

Merged
dumpboxs merged 2 commits into
mainfrom
feat/issue-4-neon-to-docker-postgres
Apr 10, 2026
Merged

feat(db): migrate database service from Neon to Docker Postgres#5
dumpboxs merged 2 commits into
mainfrom
feat/issue-4-neon-to-docker-postgres

Conversation

@mrboxs

@mrboxs mrboxs commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • migrate Drizzle DB connection from Neon HTTP driver to pg Pool + drizzle-orm/node-postgres
  • remove @neondatabase/serverless, add pg and @types/pg
  • add docker-compose.yml for local Postgres service
  • add database lifecycle scripts in package.json (db:start, db:watch, db:stop, db:down)
  • update .env.example for local Postgres URL

Validation

  • bun run db:push (success)
  • bun run db:start may fail if host port 5432 is already in use

Closes #4

Summary by CodeRabbit

  • New Features

    • Added Docker Compose configuration for a local PostgreSQL instance with health checks and persistent storage
    • Added npm scripts to manage the Docker-backed database (start, watch, stop, down)
  • Chores

    • Switched database runtime to a standard PostgreSQL client
    • Updated example environment connection string for local development and adjusted package dependencies/types for PostgreSQL tooling

@dumpboxs

dumpboxs commented Apr 9, 2026

Copy link
Copy Markdown
Owner

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e8f4db6b-09ab-4bf8-9bed-40c314c11c7e

📥 Commits

Reviewing files that changed from the base of the PR and between 2aa26f1 and aa5a09d.

📒 Files selected for processing (2)
  • package.json
  • src/db/index.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/db/index.ts
  • package.json

📝 Walkthrough

Walkthrough

Migrates DB from Neon to local Docker Postgres: replaces Neon client with pg.Pool + drizzle-orm/node-postgres, adds docker-compose.yml, updates .env.example to local Postgres URL, and adds db lifecycle scripts and pg deps in package.json.

Changes

Cohort / File(s) Summary
Environment
\.env\.example
Updated DATABASE_URL to postgresql://postgres:password@localhost:5432/elysiajs-paib-koding.
Docker Compose
docker-compose.yml
Added Compose file defining a postgres service with env vars, port mapping, named volume, healthcheck, and restart policy.
Package metadata & scripts
package.json
Replaced Neon dependency with pg and @types/pg; added Docker Compose DB scripts: db:start, db:watch, db:stop, db:down (plus existing drizzle scripts).
Database connection
src/db/index.ts
Replaced Neon serverless client with pg.Pool, added error listener on pool, and switched to drizzle-orm/node-postgres usage.

Sequence Diagram(s)

sequenceDiagram
  participant App as Application (drizzle)
  participant Pool as pg.Pool
  participant DB as Postgres (docker-compose)
  App->>Pool: createDb() -> new Pool(connectionString)
  Note right of Pool: pool handles connections\nand emits 'error' events
  App->>Pool: drizzle queries via client
  Pool->>DB: TCP connection / SQL commands
  DB-->>Pool: query results
  Pool-->>App: results returned to drizzle
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 From cloud to local I softly prance,
I swapped the Neon for a docker dance,
Volumes hum and ports align,
A pool that drinks the postgres brine,
Hop, migrate, and watch our data shine!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: migrating from Neon to Docker Postgres database service, which is the primary objective of this pull request.
Linked Issues check ✅ Passed The pull request addresses all coding requirements from issue #4: replaced Neon with pg/drizzle-orm/node-postgres, added docker-compose.yml with proper configuration, updated package.json scripts, modified src/db/index.ts with error handling, and updated .env.example.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #4 requirements: database migration dependencies, docker-compose configuration, package.json scripts for db lifecycle, db connection implementation, and environment variable updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/issue-4-neon-to-docker-postgres

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docker-compose.yml`:
- Line 5: Replace the floating image tag to pin Postgres to a stable major
version; update the docker-compose service line that currently reads "image:
postgres" to a specific tag like "postgres:16" (or a variant such as
"postgres:16-bookworm" or "postgres:16-alpine") so the service uses a
reproducible Postgres major version instead of the floating "postgres" tag.

In `@package.json`:
- Line 15: The npm script "db:start" currently runs "docker compose up -d" which
can return before Postgres is healthy; update the "db:start" script to include
the "--wait" flag so docker compose blocks until services with healthchecks
(your Postgres) are healthy before returning, i.e., modify the db:start command
string to add --wait to ensure downstream tasks like db:push don't race with an
unready DB.

In `@src/db/index.ts`:
- Around line 8-12: Attach an 'error' listener to the created Pool instance to
catch idle-client errors so they don't bubble to Node and crash the process:
after const pool = new Pool(...) add pool.on('error', (err) => { /* log the
error and handle gracefully (e.g., console.error or your logger) without
rethrowing */ }); keep returning drizzle({ client: pool, schema }) as-is so the
pool is used with the new listener.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2e8c720f-8784-4541-a7d3-2ea3891bee2d

📥 Commits

Reviewing files that changed from the base of the PR and between be1fb64 and 2aa26f1.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • .env.example
  • docker-compose.yml
  • package.json
  • src/db/index.ts

Comment thread docker-compose.yml
Comment thread package.json Outdated
Comment thread src/db/index.ts
@dumpboxs
dumpboxs merged commit 3abbf6a into main Apr 10, 2026
1 check passed
@dumpboxs
dumpboxs deleted the feat/issue-4-neon-to-docker-postgres branch April 10, 2026 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate Database Service from Neon to Docker Postgres

2 participants