Skip to content

Fix Docker postgres migration and schema initialization#235

Open
anshggss wants to merge 3 commits into
vishnukothakapu:mainfrom
anshggss:amt/dockerFix
Open

Fix Docker postgres migration and schema initialization#235
anshggss wants to merge 3 commits into
vishnukothakapu:mainfrom
anshggss:amt/dockerFix

Conversation

@anshggss

@anshggss anshggss commented May 26, 2026

Copy link
Copy Markdown
Contributor

Title: Fix Docker Postgres setup with data persistence and correct schema initialization

Closes #226

Summary

  • Updated docker-compose.yml to align the Postgres password with the app's expected credentials (postgres), add a named volume for data persistence, and mount the init/ directory so SQL runs on first
    container startup
  • Replaced the placeholder init.sql (which only created the database) with a complete schema matching the current Prisma model — all tables, enums, indexes, and foreign keys are now defined

Why

Previously, the Docker Postgres container had no data persistence (data was lost on container restart) and no schema — meaning a fresh docker compose up would spin up an empty database that the app couldn't
use. This PR makes the local Docker setup fully self-contained and ready to use without running migrations manually.

Test plan

  • Run docker compose up from the docker/ directory on a clean environment
  • Confirm the linkid database is seeded with the full schema (check tables via psql or a DB client)
  • Restart the container and verify data persists across restarts
  • Confirm the app connects and functions normally against the Dockerized Postgres

Summary by CodeRabbit

  • Chores
    • Docker Compose now exposes the database port and persists database files using a named volume for reliable local data.
    • A full application database schema has been provisioned, including user, link, analytics, job, and session-related structures with indexes and referential integrity.
  • Documentation
    • Updated setup notes with guidance for resolving failed database migration states.

Review Change Stack

Copilot AI review requested due to automatic review settings May 26, 2026 17:23
@vercel

vercel Bot commented May 26, 2026

Copy link
Copy Markdown

@anshggss is attempting to deploy a commit to the vishnukothakapu's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented May 26, 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 Plus

Run ID: 121835f8-be34-47ec-a9ea-a8809078d9ca

📥 Commits

Reviewing files that changed from the base of the PR and between a076fe2 and 5b595f2.

📒 Files selected for processing (3)
  • README.md
  • docker/docker-compose.yml
  • docker/init/init.sql
💤 Files with no reviewable changes (1)
  • docker/init/init.sql
✅ Files skipped from review due to trivial changes (1)
  • README.md

📝 Walkthrough

Walkthrough

This PR enables Docker-based DB initialization, adding a complete SQL schema (tables, enums, indexes, FKs), updates docker-compose to mount and persist Postgres data, and documents resolving Prisma migration issues.

Changes

Database Schema and Docker Initialization

Layer / File(s) Summary
Database schema definition
docker/init/init.sql
JobStatus enum and core tables (User, UserAlias, Link, ClickEvent, DailyLinkAnalytics, account-merge tables, Account, Session, VerificationToken, profile draft/version/preview token tables, Job, deleteOtp, invalidatedSession) are created; indexes added; cascading foreign key constraints wired between tables.
Docker Postgres initialization wiring
docker/docker-compose.yml
Postgres service now exposes port 5432, mounts ./init into the container initialization path, and declares/mounts a named postgres_data volume at /var/lib/postgresql/data for persistence.
Database setup docs
README.md
Adds guidance to resolve failed Prisma migrations by locating the /prisma/migrations init migration and running npx prisma migrate resolve --applied <migration_name>.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 In Docker's den the schemas grow,
Tables lined in tidy row,
Init scripts mount, the volume stays,
Migrations marked in careful ways,
Hop, link, and bounce—data flows! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main changes: updating docker-compose.yml for Postgres configuration and replacing init.sql with complete schema initialization.
Linked Issues check ✅ Passed The PR addresses issue #226 by updating docker-compose.yml to expose Postgres port and add volume persistence, and replacing init.sql with complete database schema to enable schema initialization on container startup without manual migrations.
Out of Scope Changes check ✅ Passed Changes are limited to docker configuration and initialization files. The README update providing migration guidance is a reasonable scope addition supporting the Docker initialization objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@anshggss

Copy link
Copy Markdown
Contributor Author

Hey @vishnukothakapu kindly have a look at the pr and list under GSSOC'26

@vercel

vercel Bot commented May 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
linkid Ready Ready Preview, Comment May 27, 2026 6:35am

Comment thread docker/docker-compose.yml Outdated
Comment thread docker/init/init.sql Outdated
Comment thread docker/init/init.sql Outdated
@anshggss

anshggss commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

@Anushreebasics kindly verify
Final Changes I'll be making :

  1. I'll change the password back to postgres
  2. I'll remove the init file completely since prisma migrations do the same work and either ways previously as well it wasn't being used
  3. add a note in the readme about how the migrations work

…nit.sql to support prisma migrations, changed password to password in docker-compose
@anshggss

Copy link
Copy Markdown
Contributor Author

@Anushreebasics I've made the requested changes, kindly review them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Migrations aren't run on docker container initialization

3 participants