Skip to content

feat: allow local Postgres for development/test#1355

Open
sh1nj1 wants to merge 1 commit into
mainfrom
feat/dev-postgres-config
Open

feat: allow local Postgres for development/test#1355
sh1nj1 wants to merge 1 commit into
mainfrom
feat/dev-postgres-config

Conversation

@sh1nj1

@sh1nj1 sh1nj1 commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

Lets the Rails app run against a local PostgreSQL database in development/test, as a step in the SQLite → Postgres migration. Previously the development/test blocks in config/database.yml hardcoded a SQLite file path, so even setting a Postgres DATABASE_URL was silently ignored (Rails would look for a Postgres DB literally named storage/development.sqlite3).

Defaults are unchanged: with no env vars, dev/test still use SQLite — zero disruption to existing worktrees.

How to use

# Local Postgres, no URL needed (uses collavre_db / collavre_user):
DB_ADAPTER=postgresql ./bin/dev

# Or point at any Postgres via URL:
DATABASE_URL=postgresql://collavre_user@localhost/collavre_db ./bin/dev

Adapter selection precedence in database.yml:

  1. DATABASE_URL set → use its scheme (postgres/postgresql normalized).
  2. DB_ADAPTER=postgresql → local Postgres, no URL required.
  3. otherwise → sqlite3 (default).

Local Postgres defaults are env-overridable: DATABASE_HOST (localhost), DATABASE_USERNAME (collavre_user), DATABASE_PASSWORD, DATABASE_NAME (collavre_db), TEST_DATABASE_NAME (collavre_test).

Changes

  • config/database.yml — dev/test blocks branch on adapter; Postgres uses url: (URL mode) or local collavre_db/collavre_user defaults. production and desktop blocks untouched.
  • Gemfile — move pg into the :development and :test groups (was :production only) so the adapter loads locally. Requires libpq. Gemfile.lock unchanged (groups aren't recorded there).
  • env.template — documents the new opt-in dev/test Postgres vars.

Verification (live, local)

  • DB_ADAPTER=postgresql bin/rails runneradapter=PostgreSQL, database=collavre_db, user=collavre_user, server=14.15 (Homebrew), 35 tables. ✅
  • No env → default_adapter=sqlite3 (unchanged). ✅
  • DATABASE_URL=postgres://…PostgreSQL. ✅
  • ERB+YAML parse for all four envs (development/test/production/desktop). ✅

Notes

Development and test still default to SQLite (zero-config, unchanged for
existing worktrees). Opt into Postgres with DB_ADAPTER=postgresql (uses the
local collavre_db / collavre_user with sensible env-overridable defaults) or
by setting DATABASE_URL. Previously the development/test blocks hardcoded a
SQLite database path, so a Postgres DATABASE_URL was silently ignored.

Move the pg gem into the development and test groups so the adapter is
available locally. Production and desktop configs are unchanged.

Part of the SQLite -> Postgres migration; complements the db:sqlite_to_postgres
data-copy task (#1350).
Copilot AI review requested due to automatic review settings July 6, 2026 15:54
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants