Skip to content

feat: add PostgreSQL+PostGIS Docker setup with spatial schema#127

Open
Edd1e1 wants to merge 2 commits intomainfrom
feature/be-1.1-database-setup
Open

feat: add PostgreSQL+PostGIS Docker setup with spatial schema#127
Edd1e1 wants to merge 2 commits intomainfrom
feature/be-1.1-database-setup

Conversation

@Edd1e1
Copy link
Copy Markdown

@Edd1e1 Edd1e1 commented Mar 30, 2026

  • Setup Docker cu PostgreSQL 16 + PostGIS 3.4
  • Schema DB cu 4 tabele: items, store_geofences, raw_user_pings, store_inventory_map
  • GIST indexes pe coloanele spatiale
  • .env.example pentru configurare locala

Summary by CodeRabbit

  • New Features

    • Initial geospatial inventory and store-location capabilities enabling location-based item mapping, nearby queries, and confidence-scored estimates.
  • Chores

    • Provisioned local PostgreSQL/PostGIS database infrastructure with persistent storage and health checks.
    • Added environment configuration template and updated ignore rules to keep secrets and DB data out of version control.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 90c1c63f-4869-40dc-bb0a-dad37a36b212

📥 Commits

Reviewing files that changed from the base of the PR and between e83f0bf and 8e932da.

📒 Files selected for processing (1)
  • docker-compose.yml
✅ Files skipped from review due to trivial changes (1)
  • docker-compose.yml

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Env & Gitignore
./.env.example, ./.gitignore
Added .env.example with POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD placeholders; ignored pgdata/ and .env.
Docker Compose
./docker-compose.yml
Added service db using postgis/postgis:16-3.4, mapped port 5432:5432, named volume pgdata, mounts ./init-scripts to /docker-entrypoint-initdb.d, and includes a healthcheck using pg_isready.
DB Init Scripts
init-scripts/01-init.sql
New SQL init script: enables postgis extension; creates items, store_geofences, raw_user_pings, and store_inventory_map tables with UUID PKs, foreign keys, SRID 4326 geometries, GIST spatial indexes, constraints, and relevant non-spatial indexes.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add PostgreSQL+PostGIS Docker setup with spatial schema' accurately and concisely summarizes the main changes: adding Docker configuration for PostgreSQL with PostGIS and the associated spatial database schema.
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
  • Commit unit tests in branch feature/be-1.1-database-setup

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

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (3)
init-scripts/01-init.sql (1)

7-13: Consider adding a unique constraint on upc_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:5432 may 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 obsolete version key from docker-compose.yml.

The version attribute 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7877dae and e83f0bf.

📒 Files selected for processing (4)
  • .env.example
  • .gitignore
  • docker-compose.yml
  • init-scripts/01-init.sql

Comment on lines +1 to +3
POSTGRES_DB=p2p_shopping
POSTGRES_USER=p2p_user
POSTGRES_PASSWORD=p2p_password
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 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.properties

Repository: 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:

  1. Update application.properties to use environment variables: spring.datasource.username=${POSTGRES_USER} and spring.datasource.password=${POSTGRES_PASSWORD}
  2. 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.

@sonarqubecloud
Copy link
Copy Markdown

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.

1 participant