HOCO B2B
Team tasksAnis

SRV-02 — Database schema v1 — Prisma models, migrations & reference seeds

Implement the data-model baseline as multi-file Prisma schema; first migration; seeds for wilayas/communes, brands, categories, roles/permissions, settings and reference lists.

FieldDetails
Task codeSRV-02
PhaseP0 — Foundations (cadrage, UX/UI, architecture & contract)
Product scopeV1
StatusDone (Sun 18 Oct 2026)
StartSun 18 Oct 2026
DueSun 18 Oct 2026
ResponsibleAnis — Full-stack developer
Co-responsible—
Effort1.5 person-day(s) planned · 6 from scratch · size S
Area · appServer · server
Depends onSRV-01, PRJ-03
UnblocksSRV-03, OPS-01
Milestones—

Summary

Implement the data-model baseline as multi-file Prisma schema; first migration; seeds for wilayas/communes, brands, categories, roles/permissions, settings and reference lists.

Description

Step 2: the data model in the SRS (database design) becomes an executable Prisma 7 schema on PostgreSQL 17, split into one .prisma file per module as frozen in SRV-01, with the first migration and the reference seeds every environment needs (GEO-01, ADM-04, ADM-05, AUD-02). It encodes the 17 Oct decisions: ProductVariant carries priceSuperGros, priceDemiGros, priceDetail (integer centimes, HT), vatRate, recommendedPrice and the restricted purchasePrice; Reseller.customerType is required; AttributeDefinition/VariantAttributeValue, SupportRegion/SupportRegionWilaya, ReturnRequest/ReturnItem and CreditNote are V1; PriceList, PriceListItem and QuantityTier are not created. Integrity lives in the database where possible: unique normalised reseller phone, unique business numbers per sequence, non-negative stock checks, history tables (OrderStatusChange, OrderChange, StockMovement, PriceChange). Out of scope: business logic and endpoints. OPS-01 (demo seed) and SRV-03 (contract shapes) depend on it.

Note

Step 2. Source: SRS › Database design.

Subtasks

#SubtaskOwner
1Multi-file schema packages/db/prisma/schema/<module>.prisma for the 24 modules with UUIDv7 ids generated app-sideAnis
2Catalog and pricing models: ProductVariant three prices + vatRate + recommendedPrice + purchasePrice, AttributeDefinition (type, unit, allowed values, per category), VariantAttributeValue, PriceChangeAnis
3Ordering, returns and finance models: Order/OrderItem snapshots, OrderStatusChange, OrderChange, ReturnRequest/ReturnItem, Invoice, Payment, PaymentAllocation, CreditAccount, CreditNoteAnis
4Constraints and indexes: unique normalised phone, unique business numbers, CHECK physical ≥ 0 and reserved ≥ 0 on StockLevel, partial indexes for order queues and catalog search (pg_trgm)Anis
5Platform tables: AuditLog, Setting, NumberSequence, IdempotencyRecord, OutboxEvent, ExportJob, ImportJob, AppVersionPolicy, ReferenceItemAnis
6First migration and migration workflow (prisma migrate dev / deploy, review of generated SQL in PRs)Anis
7Reference seeds: official wilayas and communes (FR/AR), brands HOCO/ACEFAST/BOROFONE, category tree, starter attribute definitions (power W, connector, cable length, colour, capacity mAh, Bluetooth version)Anis
8Access seeds: 8 roles, permission catalogue (18 modules × 7 actions), default role matrixAnis
9Settings defaults (stock.reserveOn=VALIDATED, stock.deductOn=SHIPPED, orders.assistedConfirmationHours=72, orders.cancelAllowedStatuses, GPS 150 m/100 m), reference lists (8 list keys), number sequences, default support regionAnis
10Schema review against the API contract needs as first consumerImad

Deliverables

  • packages/db/prisma/schema/*.prisma (one file per module) and packages/db/prisma.config.ts
  • packages/db/prisma/migrations/0001_init
  • packages/db/src/seed/{geo,catalog,access,settings,reference-lists,support-regions}.ts
  • Generated ER diagram linked from /docs/srs/database-design

Acceptance criteria

  • prisma migrate deploy on an empty PostgreSQL 17 database succeeds and pnpm db:seed is idempotent (second run changes nothing)
  • No PriceList, PriceListItem or QuantityTier table exists in the V1 migration; ProductVariant has the three price columns (PRC-01)
  • Inserting a second reseller with the same normalised phone fails on the unique constraint (CRM-03)
  • A StockLevel update that makes physical or reserved negative is rejected by the database
  • All 8 roles and the full permission catalogue are seeded; reference lists contain the 8 list keys of AUTHORING §3
  • Every entity of the service catalogue exists with its canonical name

Requirements covered

RequirementTitleRelease
GEO-01Official wilaya and commune reference (FR/AR names) used by addresses, zones and filtersV1
ADM-04Unique human-readable numbers for resellers, orders, invoices, tours, visits, tickets and returnsV1
ADM-05Reference lists: business types, potentials, visit types, not-done reasons, issue tags, ticket types, carriersV1
AUD-02Entity histories: order changes, status changes, stock movements and price changes are kept and viewable in contextV1

Test measures

  • DB test suite against a real Postgres (Testcontainers or the compose service): constraints for phone uniqueness, stock non-negativity, business number uniqueness
  • Seed idempotency test (run twice, compare row counts)
  • Migration drift check in CI (prisma migrate diff against the schema)

Risks

  • Integer overflow on large order/invoice totals in centimes — store totals and aggregates as BigInt and expose them as numbers in the contract (safe up to 2^53)
  • Official wilaya/commune list changes (new wilayas) — seed from a versioned source file and keep codes stable so addresses are not broken

KPI

  • Delivered by Sun 18 Oct 2026 within 1.5 person-day(s).
  • Every acceptance criterion above demonstrated before hand-off; linked requirements' acceptance criteria pass.
  • Zero open critical defects, permission gaps or data-integrity regressions at sign-off.

Generated from content/plan/tasks.json by scripts/generate-team-tasks.mjs. Dates are computed by the scheduler (Sunday–Thursday weeks, holidays excluded) — change the plan, not this page.

On this page