Skip to content

feat: add PostgreSQL configuration support for production#435

Open
Kishalll wants to merge 3 commits into
Kuldeeep18:mainfrom
Kishalll:feature/337-postgres-production-config
Open

feat: add PostgreSQL configuration support for production#435
Kishalll wants to merge 3 commits into
Kuldeeep18:mainfrom
Kishalll:feature/337-postgres-production-config

Conversation

@Kishalll

@Kishalll Kishalll commented Jun 24, 2026

Copy link
Copy Markdown

Pull Request

🔗 Related Issue

Closes #337


📝 Summary of Changes

Adds PostgreSQL configuration support for production deployments via DATABASE_URL environment variable, while keeping SQLite as the default for local development.

  • requirements.txt: Added dj-database-url>=2.2,<3.0 and psycopg2-binary>=2.9,<3.0
  • backend/backend/settings.py: Replaced hardcoded SQLite DATABASES dict with dj_database_url.config() that reads DATABASE_URL env var. Falls back to SQLite when not set. Enables SSL when DEBUG=False for production.
  • backend/.env.example: Added DATABASE_URL= entry with comments
  • README.md: Updated both Stack sections to mention PostgreSQL, added "Production database setup" subsection with connection string example
  • Removed previously tracked __pycache__/*.pyc and db.sqlite3 from git index

🏷️ Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactor
  • 📝 Documentation update
  • 🎨 UI / Style change
  • 🔧 Chore

🧪 Testing

Steps to test:

  1. Run python backend/manage.py check — should report 0 issues
  2. Run python backend/manage.py test users leads tenants — all 39 tests pass
  3. Without DATABASE_URL set, verify the app uses SQLite (check DATABASES['default']['ENGINE'] is django.db.backends.sqlite3)
  4. With DATABASE_URL=postgresql://user:pass@host:5432/db set, verify the app uses PostgreSQL (check DATABASES['default']['ENGINE'] is django.db.backends.postgresql)

✅ Checklist

  • No merge conflicts
  • Changes follow the project guidelines
  • Documentation updated (if applicable)
  • Related issue linked
  • Changes tested locally (if applicable)

Summary by CodeRabbit

  • New Features
    • Added support for configuring production databases via DATABASE_URL.
    • The app now defaults to SQLite for local development and can use PostgreSQL in production.
  • Documentation
    • Updated the README and environment examples with DATABASE_URL placeholders and PostgreSQL connection string guidance.
    • Documented the automatic fallback to SQLite when DATABASE_URL is not provided.

Kishalll added 2 commits June 24, 2026 12:35
- Add dj-database-url and psycopg2-binary to requirements.txt
- Replace hardcoded SQLite DATABASES config in settings.py with
  dj_database_url.config() that reads DATABASE_URL env var
- Falls back to SQLite when DATABASE_URL is not set (dev default)
- Enables SSL when DEBUG=False for production PostgreSQL connections
- Update .env.example with DATABASE_URL entry and comments
- Update README Stack sections and add production database setup docs
- Remove previously tracked __pycache__/*.pyc and db.sqlite3 from index
@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: c234c308-042d-4eea-9399-d72c3780face

📥 Commits

Reviewing files that changed from the base of the PR and between fc0d899 and 894abe5.

📒 Files selected for processing (2)
  • backend/config/asgi.py
  • backend/config/wsgi.py
✅ Files skipped from review due to trivial changes (1)
  • backend/config/asgi.py

📝 Walkthrough

Walkthrough

The PR adds dj-database-url and psycopg2-binary, switches Django database settings to dj_database_url.config(...) with SQLite fallback, updates ASGI and WSGI settings module defaults, and documents DATABASE_URL usage in .env.example and the README.

Changes

PostgreSQL Production Database Support

Layer / File(s) Summary
Database config implementation and dependencies
requirements.txt, backend/backend/settings.py
Adds dj-database-url>=2.2,<3.0 and psycopg2-binary>=2.9,<3.0 to requirements.txt. Imports dj_database_url in settings.py and replaces the explicit SQLite ENGINE/NAME dict with dj_database_url.config(...), defaulting to sqlite:///BASE_DIR/db.sqlite3, setting conn_max_age=600, and enabling ssl_require when DEBUG is false.
Environment example and README documentation
backend/.env.example, README.md
Adds a DATABASE_URL= placeholder and fallback-to-SQLite comments to .env.example. Updates both Stack sections and both backend/.env setup blocks in the README to document DATABASE_URL with a PostgreSQL example connection string.
ASGI and WSGI settings module updates
backend/config/asgi.py, backend/config/wsgi.py
Changes the default DJANGO_SETTINGS_MODULE value in both entrypoints from config.settings to backend.settings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hoppity-hah, the settings bloom,
DATABASE_URL now lights the room.
SQLite hops for local days,
Postgres prances in prod ways. 🥕

🚥 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 clearly summarizes the main change: adding PostgreSQL production support.
Linked Issues check ✅ Passed The PR meets the linked issue requirements for DATABASE_URL support, SQLite fallback, env example, README guidance, and psycopg2-binary.
Out of Scope Changes check ✅ Passed The extra ASGI/WSGI settings module updates are related to the database settings change and do not appear unrelated.
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.

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/backend/settings.py`:
- Around line 118-122: The runtime settings are still loading config.settings,
so the database configuration change in backend/settings.py is not being used in
deployment. Update the active settings module backend/config/settings.py to
include the same dj_database_url.config(...) database setup (or, alternatively,
change backend/config/wsgi.py and backend/config/asgi.py to import
backend.settings) so the deployed entrypoints and settings source stay aligned.
🪄 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 Plus

Run ID: f4baa4a7-9174-494f-b7f6-3b0108f77afe

📥 Commits

Reviewing files that changed from the base of the PR and between 4a33158 and fc0d899.

⛔ Files ignored due to path filters (51)
  • backend/backend/__pycache__/__init__.cpython-314.pyc is excluded by !**/*.pyc
  • backend/backend/__pycache__/celery.cpython-314.pyc is excluded by !**/*.pyc
  • backend/backend/__pycache__/settings.cpython-314.pyc is excluded by !**/*.pyc
  • backend/backend/__pycache__/urls.cpython-314.pyc is excluded by !**/*.pyc
  • backend/backend/__pycache__/wsgi.cpython-314.pyc is excluded by !**/*.pyc
  • backend/campaigns/__pycache__/__init__.cpython-314.pyc is excluded by !**/*.pyc
  • backend/campaigns/__pycache__/ai.cpython-314.pyc is excluded by !**/*.pyc
  • backend/campaigns/__pycache__/apps.cpython-314.pyc is excluded by !**/*.pyc
  • backend/campaigns/__pycache__/gmail_service.cpython-314.pyc is excluded by !**/*.pyc
  • backend/campaigns/__pycache__/google_auth_views.cpython-314.pyc is excluded by !**/*.pyc
  • backend/campaigns/__pycache__/models.cpython-314.pyc is excluded by !**/*.pyc
  • backend/campaigns/__pycache__/serializers.cpython-314.pyc is excluded by !**/*.pyc
  • backend/campaigns/__pycache__/tasks.cpython-314.pyc is excluded by !**/*.pyc
  • backend/campaigns/__pycache__/tests.cpython-314.pyc is excluded by !**/*.pyc
  • backend/campaigns/__pycache__/views.cpython-314.pyc is excluded by !**/*.pyc
  • backend/campaigns/migrations/__pycache__/0001_initial.cpython-314.pyc is excluded by !**/*.pyc
  • backend/campaigns/migrations/__pycache__/0002_campaignlead_last_sent_message_id_and_more.cpython-314.pyc is excluded by !**/*.pyc
  • backend/campaigns/migrations/__pycache__/0003_alter_sequencestep_channel_type.cpython-314.pyc is excluded by !**/*.pyc
  • backend/campaigns/migrations/__pycache__/0004_connectedemailaccount_connected_by.cpython-314.pyc is excluded by !**/*.pyc
  • backend/campaigns/migrations/__pycache__/__init__.cpython-314.pyc is excluded by !**/*.pyc
  • backend/config/__pycache__/__init__.cpython-314.pyc is excluded by !**/*.pyc
  • backend/config/__pycache__/settings.cpython-314.pyc is excluded by !**/*.pyc
  • backend/config/__pycache__/urls.cpython-314.pyc is excluded by !**/*.pyc
  • backend/config/__pycache__/wsgi.cpython-314.pyc is excluded by !**/*.pyc
  • backend/leads/__pycache__/__init__.cpython-314.pyc is excluded by !**/*.pyc
  • backend/leads/__pycache__/apps.cpython-314.pyc is excluded by !**/*.pyc
  • backend/leads/__pycache__/models.cpython-314.pyc is excluded by !**/*.pyc
  • backend/leads/__pycache__/serializers.cpython-314.pyc is excluded by !**/*.pyc
  • backend/leads/__pycache__/tasks.cpython-314.pyc is excluded by !**/*.pyc
  • backend/leads/__pycache__/tests.cpython-314.pyc is excluded by !**/*.pyc
  • backend/leads/__pycache__/views.cpython-314.pyc is excluded by !**/*.pyc
  • backend/leads/migrations/__pycache__/0001_initial.cpython-314.pyc is excluded by !**/*.pyc
  • backend/leads/migrations/__pycache__/__init__.cpython-314.pyc is excluded by !**/*.pyc
  • backend/tenants/__pycache__/__init__.cpython-314.pyc is excluded by !**/*.pyc
  • backend/tenants/__pycache__/admin.cpython-314.pyc is excluded by !**/*.pyc
  • backend/tenants/__pycache__/apps.cpython-314.pyc is excluded by !**/*.pyc
  • backend/tenants/__pycache__/middleware.cpython-314.pyc is excluded by !**/*.pyc
  • backend/tenants/__pycache__/models.cpython-314.pyc is excluded by !**/*.pyc
  • backend/tenants/__pycache__/security.cpython-314.pyc is excluded by !**/*.pyc
  • backend/tenants/__pycache__/tests.cpython-314.pyc is excluded by !**/*.pyc
  • backend/tenants/migrations/__pycache__/0001_initial.cpython-314.pyc is excluded by !**/*.pyc
  • backend/tenants/migrations/__pycache__/__init__.cpython-314.pyc is excluded by !**/*.pyc
  • backend/users/__pycache__/__init__.cpython-314.pyc is excluded by !**/*.pyc
  • backend/users/__pycache__/apps.cpython-314.pyc is excluded by !**/*.pyc
  • backend/users/__pycache__/jwt.cpython-314.pyc is excluded by !**/*.pyc
  • backend/users/__pycache__/models.cpython-314.pyc is excluded by !**/*.pyc
  • backend/users/__pycache__/serializers.cpython-314.pyc is excluded by !**/*.pyc
  • backend/users/__pycache__/tests.cpython-314.pyc is excluded by !**/*.pyc
  • backend/users/__pycache__/views.cpython-314.pyc is excluded by !**/*.pyc
  • backend/users/migrations/__pycache__/0001_initial.cpython-314.pyc is excluded by !**/*.pyc
  • backend/users/migrations/__pycache__/__init__.cpython-314.pyc is excluded by !**/*.pyc
📒 Files selected for processing (5)
  • README.md
  • backend/.env.example
  • backend/backend/settings.py
  • backend/db.sqlite3
  • requirements.txt

Comment thread backend/backend/settings.py
config/wsgi.py and config/asgi.py were still loading config.settings
which hardcoded SQLite. Switch them to backend.settings which uses
dj-database-url for proper DATABASE_URL support.
@Kishalll

Copy link
Copy Markdown
Author

@Kuldeeep18 pls review

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.

LO-089 [Medium - DevOps]: Add PostgreSQL Configuration Support for Production

1 participant