feat(db): establish database schema, RLS policies, and data access layer (US-01, US-02) #12

Merged
gabogg merged 2 commits from feat/us-01-us-02-supabase-persistence into main 2026-09-24 10:34:28 +00:00
Owner

Addresses #1 and #2.

Summary

graph TD
    UI[App.jsx] -->|loadAllShiftsForDate| API[reportApi.js]
    API -->|SELECT / UPSERT| PG[(Supabase PostgreSQL)]
    PG --> DR[daily_reports Table & RLS]
    PG --> OF[officers Table & RLS]
supabase/migrations/
└── 20260917000027_create_daily_reports_table.sql # Schema, indexes, RLS policies (US-01)
src/lib/
├── supabaseClient.js                             # Client init with env fallback (US-02)
├── reportApi.js                                  # CRUD operations & parallel loading (US-02)
└── __tests__/
    ├── schema.test.js                            # SQL schema & constraint tests
    └── reportApi.test.js                         # 16 unit tests for data access methods

Evidence

  • Before: No test suite configured; loadAllShiftsForDate executed a single table scan without parallelization or structured response.
  • After: 22 passing automated tests across schema verification and data access methods. Production build succeeds cleanly.
✓ src/lib/__tests__/schema.test.js (6 tests)
✓ src/lib/__tests__/reportApi.test.js (16 tests)

Test Files  2 passed (2)
     Tests  22 passed (22)
  Duration  2.13s

Merge Danger

Door: two-way

Reversible standard schema migration and client data access layer without breaking existing UI contracts.

Blast Radius: low

Internal persistence and data access layer; App.jsx consumes parallel shift loader seamlessly.

Addresses #1 and #2. ## Summary ```mermaid graph TD UI[App.jsx] -->|loadAllShiftsForDate| API[reportApi.js] API -->|SELECT / UPSERT| PG[(Supabase PostgreSQL)] PG --> DR[daily_reports Table & RLS] PG --> OF[officers Table & RLS] ``` ```text supabase/migrations/ └── 20260917000027_create_daily_reports_table.sql # Schema, indexes, RLS policies (US-01) src/lib/ ├── supabaseClient.js # Client init with env fallback (US-02) ├── reportApi.js # CRUD operations & parallel loading (US-02) └── __tests__/ ├── schema.test.js # SQL schema & constraint tests └── reportApi.test.js # 16 unit tests for data access methods ``` ## Evidence - **Before:** No test suite configured; `loadAllShiftsForDate` executed a single table scan without parallelization or structured response. - **After:** 22 passing automated tests across schema verification and data access methods. Production build succeeds cleanly. ```text ✓ src/lib/__tests__/schema.test.js (6 tests) ✓ src/lib/__tests__/reportApi.test.js (16 tests) Test Files 2 passed (2) Tests 22 passed (22) Duration 2.13s ``` ## Merge Danger **Door:** two-way Reversible standard schema migration and client data access layer without breaking existing UI contracts. **Blast Radius:** low Internal persistence and data access layer; App.jsx consumes parallel shift loader seamlessly.
- Add SQL migration tracking daily_reports and officers tables with composite unique index and full RLS policies (US-01)
- Implement centralized Supabase client and CRUD operations in reportApi.js (US-02)
- Add loadAllShiftsForDate for parallel Day/Night shift retrieval
- Integrate parallel shift loading into App.jsx
- Add Vitest test runner with unit tests for reportApi and schema migration validation
- Enforce project-wide English comments and logging policy
Author
Owner

Code review of bde815f against base 575526f using git diff 575526f7bf4e54ae605285197a249519b261dcb4...bde815f5d116f544ec270553c7ba90889a6c8b84. Standards and Spec were reviewed independently.

Validation: 22 tests passed and production build passed on an isolated snapshot of this commit, using the locally installed dependencies. No live database validation was performed.

Standards

  • [P3] Use English names for the new shift-result variables — src/lib/reportApi.js:46–57 introduces const [diurno, nocturno] and the return properties { diurno, nocturno }; src/App.jsx:105 consumes them. AGENTS.md, Core Architecture and Coding Rules §5, requires “All internal variable names, types, and logic are in English.” Use dayReport and nightReport (including the return contract and tests), while retaining the established persisted shift values DIURNO and NOCTURNO. This is a documented naming violation, not a functional defect.

No additional actionable baseline smells were identified in the introduced changes. Existing schema/RLS behavior and existing load-error handling were not attributed to this PR.

Spec

No actionable findings against the readable acceptance criteria in issues #1 and #2. The schema includes the required report fields, indexes, personnel fields, and RLS operations. The API uses Vite configuration, local dates, parallel shift loading, atomic upserts, and unique historical dates. The sole production caller of the changed loadAllShiftsForDate return shape is updated in App.jsx.

Most schema behavior already existed at the base commit; this PR primarily documents it and adds API coverage. Some identifiers in the issue text are missing or corrupted, so exact identifier compliance cannot be established from those passages. No database migration was executed during this source review.

Summary: Standards — 1 finding, worst P3: English naming convention; Spec — 0 findings, worst: none identified.

Code review of `bde815f` against base `575526f` using `git diff 575526f7bf4e54ae605285197a249519b261dcb4...bde815f5d116f544ec270553c7ba90889a6c8b84`. Standards and Spec were reviewed independently. Validation: **22 tests passed** and **production build passed** on an isolated snapshot of this commit, using the locally installed dependencies. No live database validation was performed. ## Standards - **[P3] Use English names for the new shift-result variables** — [src/lib/reportApi.js:46–57](https://git.gaboggamer.online/gabogg/orinokia-mall-control/src/commit/bde815f5d116f544ec270553c7ba90889a6c8b84/src/lib/reportApi.js#L46) introduces `const [diurno, nocturno]` and the return properties `{ diurno, nocturno }`; `src/App.jsx:105` consumes them. AGENTS.md, Core Architecture and Coding Rules §5, requires “All internal variable names, types, and logic are in English.” Use `dayReport` and `nightReport` (including the return contract and tests), while retaining the established persisted shift values `DIURNO` and `NOCTURNO`. This is a documented naming violation, not a functional defect. No additional actionable baseline smells were identified in the introduced changes. Existing schema/RLS behavior and existing load-error handling were not attributed to this PR. ## Spec No actionable findings against the readable acceptance criteria in issues #1 and #2. The schema includes the required report fields, indexes, personnel fields, and RLS operations. The API uses Vite configuration, local dates, parallel shift loading, atomic upserts, and unique historical dates. The sole production caller of the changed `loadAllShiftsForDate` return shape is updated in `App.jsx`. Most schema behavior already existed at the base commit; this PR primarily documents it and adds API coverage. Some identifiers in the issue text are missing or corrupted, so exact identifier compliance cannot be established from those passages. No database migration was executed during this source review. Summary: Standards — **1 finding**, worst **P3: English naming convention**; Spec — **0 findings**, worst: none identified.
- Rename return properties from { diurno, nocturno } to { dayReport, nightReport }
- Retain persisted uppercase shift domain constants 'DIURNO' and 'NOCTURNO'
- Update consumption in App.jsx and corresponding Vitest test assertions
- Satisfies AGENTS.md Core Architecture and Coding Rules §5
Author
Owner

Addressed reviewer finding [P3] Use English names for the new shift-result variables: Renamed return properties in loadAllShiftsForDate to { dayReport, nightReport } in src/lib/reportApi.js, updated consumption in src/App.jsx, and aligned unit test assertions in src/lib/__tests__/reportApi.test.js in commit 45131bf. All 22 tests pass cleanly.

Addressed reviewer finding **[P3] Use English names for the new shift-result variables**: Renamed return properties in `loadAllShiftsForDate` to `{ dayReport, nightReport }` in `src/lib/reportApi.js`, updated consumption in `src/App.jsx`, and aligned unit test assertions in `src/lib/__tests__/reportApi.test.js` in commit `45131bf`. All 22 tests pass cleanly.
gabogg merged commit 2a0543f040 into main 2026-09-24 10:34:28 +00:00
Sign in to join this conversation.
No description provided.