Skip to content

Commit 781100f

Browse files
feat(database): Add unified MongoDB and PostgreSQL dual-write mechanism (#258)
* feat: implement dual-write system for MongoDB to PostgreSQL synchronization - Added comprehensive documentation for the dual-write feature in README.md - Updated requirements.txt to include psycopg2-binary for PostgreSQL support - Modified Django settings to configure PostgreSQL as the primary database - Introduced dual-write operations with error handling and monitoring capabilities - Enhanced project structure for future migration paths and Docker development setup * feat: enhance PostgreSQL integration with new models and dual-write functionality * refactor: consolidate PostgreSQL models * feat: implement priority field fix and enhance dual-write functionality * refactor: update PostgreSQL models and enhance dual-write service functionality * refactor: simplify Postgres watchlist model and update dual-write service transformation * fix: deferred task in postgres * refactor: update Postgres audit log model * refactor: remove old watchlist models and update user role structure for enhanced functionality * refactor: enhance PostgreSQL model definitions and integrate dual-write service for task assignments and user roles * feat: add task assignment creation functionality and streamline task assignment deletion process * refactor: update task assignment models and repository to streamline data handling and enhance dual-write service integration * feat: implement dual-write synchronization for team creation invite codes and update watchlist collection naming * feat: add PostgreSQL synchronization service and management command for labels and roles * chore: remove pgAdmin service from docker-compose configuration * chore: remove deprecated docker-compose and environment configuration files * feat: add PostgreSQL availability checks and environment variables for dual-write and sync services * feat: configure database settings for testing and production environments * fix: update environment variable names for PostgreSQL configuration in docker-compose and application settings * refactor: update PostgreSQL environment variable name and enhance docker-compose commands and health checks * refactor: rename PostgreSQL task assignment index names for consistency --------- Co-authored-by: Amit Prakash <[email protected]>
1 parent 4d042bc commit 781100f

39 files changed

+3633
-38
lines changed

.env.example

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,10 @@ CORS_ALLOWED_ORIGINS='http://localhost:3000,http://localhost:8000'
2929

3030
SWAGGER_UI_PATH='/api/schema'
3131

32-
32+
33+
34+
POSTGRES_HOST: postgres
35+
POSTGRES_PORT: 5432
36+
POSTGRES_DB: todo_postgres
37+
POSTGRES_USER: todo_user
38+
POSTGRES_PASSWORD: todo_password

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,4 @@
148148
- If port 5678 is in use, specify a different port with `--debug-port`
149149
- Ensure VS Code Python extension is installed
150150
- Check that breakpoints are set in the correct files
151-
- Verify the debug server shows "Debug server listening on port 5678"
151+
- Verify the debug server shows "Debug server listening on port 5678"

docker-compose.yml

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,65 @@ services:
22
django-app:
33
build: .
44
container_name: todo-django-app
5-
command: python -Xfrozen_modules=off manage.py runserver_debug 0.0.0.0:8000 --debug-port 5678
5+
command: >
6+
sh -c "
7+
python manage.py makemigrations &&
8+
python manage.py migrate &&
9+
python manage.py shell -c 'from todo_project.db.init import initialize_database; initialize_database()' &&
10+
python manage.py runserver 0.0.0.0:8000
11+
"
612
environment:
713
MONGODB_URI: mongodb://db:27017
814
DB_NAME: todo-app
915
PYTHONUNBUFFERED: 1
1016
PYDEVD_DISABLE_FILE_VALIDATION: 1
17+
# PostgreSQL Configuration
18+
POSTGRES_HOST: postgres
19+
POSTGRES_PORT: 5432
20+
POSTGRES_DB: todo_postgres
21+
POSTGRES_USER: todo_user
22+
POSTGRES_PASSWORD: todo_password
1123
volumes:
1224
- .:/app
1325
ports:
1426
- "8000:8000"
1527
- "5678:5678" # Debug port
1628
depends_on:
17-
- db
18-
- mongo-init
29+
db:
30+
condition: service_started
31+
mongo-init:
32+
condition: service_completed_successfully
33+
postgres:
34+
condition: service_healthy
1935
stdin_open: true
2036
tty: true
2137

38+
postgres:
39+
image: postgres:15
40+
container_name: todo-postgres
41+
environment:
42+
POSTGRES_DB: todo_postgres
43+
POSTGRES_USER: todo_user
44+
POSTGRES_PASSWORD: todo_password
45+
POSTGRES_HOST_AUTH_METHOD: trust
46+
ports:
47+
- "5432:5432"
48+
volumes:
49+
- postgres_data:/var/lib/postgresql/data
50+
- ./init-scripts:/docker-entrypoint-initdb.d
51+
healthcheck:
52+
test:
53+
[
54+
"CMD-SHELL",
55+
"pg_isready -U todo_user -d todo_app && echo 'Postgres healthcheck passed'",
56+
]
57+
interval: 10s
58+
timeout: 5s
59+
retries: 5
60+
start_period: 10s
61+
62+
63+
2264
db:
2365
image: mongo:latest
2466
command: ["--replSet", "rs0", "--bind_ip_all", "--port", "27017"]
@@ -28,7 +70,14 @@ services:
2870
volumes:
2971
- ./mongo_data:/data/db
3072
healthcheck:
31-
test: ["CMD", "mongosh", "--quiet", "--eval", "if (db.runCommand({ping:1}).ok) process.exit(0); else process.exit(1)"]
73+
test:
74+
[
75+
"CMD",
76+
"mongosh",
77+
"--quiet",
78+
"--eval",
79+
"if (db.runCommand({ping:1}).ok) process.exit(0); else process.exit(1)",
80+
]
3281
interval: 10s
3382
timeout: 5s
3483
retries: 5
@@ -67,3 +116,6 @@ services:
67116
depends_on:
68117
- db
69118
- mongo-init
119+
120+
volumes:
121+
postgres_data:

0 commit comments

Comments
 (0)