feat: add PostgreSQL+PostGIS Docker setup with spatial schema#127
feat: add PostgreSQL+PostGIS Docker setup with spatial schema#127
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughAdds PostgreSQL/PostGIS database infrastructure: a Docker Compose service, an example .env with DB credentials, .gitignore entries, and an initialization SQL script that enables PostGIS and creates geospatial tables for items, store geofences, user pings, and aggregated inventory maps. Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as Developer (docker-compose)
participant Docker as Docker Engine
participant DB as Postgres/PostGIS container
participant Init as /docker-entrypoint-initdb.d scripts
Dev->>Docker: docker-compose up db
Docker->>DB: start container (postgis image)
DB->>DB: initialize DB files (pgdata)
DB->>Init: execute `01-init.sql` on first start
Init->>DB: CREATE EXTENSION, CREATE TABLES, CREATE INDEXES
Docker->>DB: run healthcheck (pg_isready)
DB-->>Docker: healthy / ready
Dev-->>DB: applications connect using env credentials
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (3)
init-scripts/01-init.sql (1)
7-13: Consider adding a unique constraint onupc_code.If
upc_code(Universal Product Code) should uniquely identify products, consider adding a unique constraint. If duplicates are intentionally allowed (e.g., same product at different stores), this is fine as-is.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@init-scripts/01-init.sql` around lines 7 - 13, Add a unique constraint on the upc_code column in the items table so UPCs cannot be duplicated: modify the CREATE TABLE items(...) to declare upc_code VARCHAR(50) UNIQUE or add an explicit constraint (e.g., CONSTRAINT uniq_items_upc UNIQUE (upc_code)); if the table already exists, add it with ALTER TABLE items ADD CONSTRAINT uniq_items_upc UNIQUE (upc_code). Ensure the change references the items table and upc_code column so the DB enforces uniqueness.docker-compose.yml (2)
12-13: Consider using a non-default port or documenting port requirements.Binding to
5432:5432may conflict with a locally installed PostgreSQL. Consider:
- Using a different host port (e.g.,
5433:5432)- Documenting that port 5432 must be available
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docker-compose.yml` around lines 12 - 13, The docker compose service binds PostgreSQL to the default host port "5432:5432", which can conflict with a local Postgres; change the exposed host port in the service's ports setting (e.g., "5433:5432") or add documentation that the host must free port 5432 before running; update the ports entry (the line containing ports and "- \"5432:5432\"") or add a short note to README/compose docs explaining the required host port and how to override it.
1-1: Remove the obsoleteversionkey from docker-compose.yml.The
versionattribute is ignored by Docker Compose V2+ and triggers a warning when present. Removing it is optional but reduces noise and aligns with the Compose Specification.♻️ Proposed change
-version: '3.8' - services:🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docker-compose.yml` at line 1, Remove the obsolete top-level "version" key from docker-compose.yml: open the docker-compose.yml file and delete the line containing "version: '3.8'" so the file follows the Compose Specification and avoids the Docker Compose V2+ warning.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.env.example:
- Around line 1-3: The .env.example credentials
(POSTGRES_USER/POSTGRES_PASSWORD) don't match the Spring config
(spring.datasource.username/spring.datasource.password), causing auth failures;
fix by either updating application properties to read the environment variables
(use spring.datasource.username=${POSTGRES_USER} and
spring.datasource.password=${POSTGRES_PASSWORD}) or make the .env.example values
match the hardcoded values in application.properties (e.g., change
POSTGRES_USER/POSTGRES_PASSWORD to postgres/postgres), and ensure POSTGRES_DB,
POSTGRES_USER and POSTGRES_PASSWORD in .env.example are consistent with the
values used by the application.
In `@docker-compose.yml`:
- Line 16: The docker-compose mount references a non-existent host file
"./schema.sql"; update the volume entry that currently reads "-
./schema.sql:/docker-entrypoint-initdb.d/schema.sql" to use the actual schema
file path "./init-scripts/01-init.sql" (so it mounts
"./init-scripts/01-init.sql:/docker-entrypoint-initdb.d/schema.sql") and ensure
the init-scripts/01-init.sql file is present in the repo; look for the volume
line in the docker-compose service definition to change it.
In `@init-scripts/01-init.sql`:
- Around line 1-78: The init SQL file containing CREATE TABLEs like
store_geofences, raw_user_pings and store_inventory_map is not being mounted
where the Postgres container expects it (it expects schema.sql at container
init), so fix by either renaming the existing init-scripts file to schema.sql at
the repository root so the container will load it, or update the docker-compose
service volume mount to point to the current init-scripts/01-init.sql file (so
the container receives the SQL with the CREATE EXTENSION and CREATE TABLE
statements).
---
Nitpick comments:
In `@docker-compose.yml`:
- Around line 12-13: The docker compose service binds PostgreSQL to the default
host port "5432:5432", which can conflict with a local Postgres; change the
exposed host port in the service's ports setting (e.g., "5433:5432") or add
documentation that the host must free port 5432 before running; update the ports
entry (the line containing ports and "- \"5432:5432\"") or add a short note to
README/compose docs explaining the required host port and how to override it.
- Line 1: Remove the obsolete top-level "version" key from docker-compose.yml:
open the docker-compose.yml file and delete the line containing "version: '3.8'"
so the file follows the Compose Specification and avoids the Docker Compose V2+
warning.
In `@init-scripts/01-init.sql`:
- Around line 7-13: Add a unique constraint on the upc_code column in the items
table so UPCs cannot be duplicated: modify the CREATE TABLE items(...) to
declare upc_code VARCHAR(50) UNIQUE or add an explicit constraint (e.g.,
CONSTRAINT uniq_items_upc UNIQUE (upc_code)); if the table already exists, add
it with ALTER TABLE items ADD CONSTRAINT uniq_items_upc UNIQUE (upc_code).
Ensure the change references the items table and upc_code column so the DB
enforces uniqueness.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2f6b1875-9a19-4487-8476-63f8bba4f730
📒 Files selected for processing (4)
.env.example.gitignoredocker-compose.ymlinit-scripts/01-init.sql
| POSTGRES_DB=p2p_shopping | ||
| POSTGRES_USER=p2p_user | ||
| POSTGRES_PASSWORD=p2p_password |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check application.properties database credentials
echo "=== application.properties datasource config ==="
rg 'spring\.datasource\.' src/main/resources/application.properties 2>/dev/null || cat src/main/resources/application.propertiesRepository: P2P-Shopping/server
Length of output: 309
Fix credential mismatch between environment and Spring configuration.
The credentials in .env.example (p2p_user/p2p_password) do not match application.properties (postgres/postgres). This will cause database authentication failures at runtime.
Either:
- Update
application.propertiesto use environment variables:spring.datasource.username=${POSTGRES_USER}andspring.datasource.password=${POSTGRES_PASSWORD} - Align both files to use the same credentials
🧰 Tools
🪛 dotenv-linter (4.0.0)
[warning] 3-3: [UnorderedKey] The POSTGRES_PASSWORD key should go before the POSTGRES_USER key
(UnorderedKey)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.env.example around lines 1 - 3, The .env.example credentials
(POSTGRES_USER/POSTGRES_PASSWORD) don't match the Spring config
(spring.datasource.username/spring.datasource.password), causing auth failures;
fix by either updating application properties to read the environment variables
(use spring.datasource.username=${POSTGRES_USER} and
spring.datasource.password=${POSTGRES_PASSWORD}) or make the .env.example values
match the hardcoded values in application.properties (e.g., change
POSTGRES_USER/POSTGRES_PASSWORD to postgres/postgres), and ensure POSTGRES_DB,
POSTGRES_USER and POSTGRES_PASSWORD in .env.example are consistent with the
values used by the application.
|



Summary by CodeRabbit
New Features
Chores