Rebrand from Forte (music-store-specific) to LunarFront (any small business): - Package namespace @forte/* → @lunarfront/* - Database forte/forte_test → lunarfront/lunarfront_test - Docker containers, volumes, connection strings - UI branding, localStorage keys, test emails - All documentation and planning docs Generalize music-specific terminology: - instrumentDescription → itemDescription - instrumentCount → itemCount - instrumentType → itemCategory (on service templates) - New migration 0027_generalize_terminology for column renames - Seed data updated with generic examples - RBAC descriptions updated
87 lines
2.4 KiB
Markdown
87 lines
2.4 KiB
Markdown
# Database
|
|
|
|
## Setup
|
|
|
|
PostgreSQL 16. Two databases:
|
|
|
|
| Database | Port | Usage |
|
|
|----------|------|-------|
|
|
| `lunarfront` | 5432 | Development |
|
|
| `lunarfront_api_test` | 5432 | API integration tests (auto-created by test runner) |
|
|
|
|
## Migrations
|
|
|
|
Migrations are managed by Drizzle Kit and live in `packages/backend/src/db/migrations/`.
|
|
|
|
```bash
|
|
cd packages/backend
|
|
|
|
# Generate a migration from schema changes
|
|
bunx drizzle-kit generate
|
|
|
|
# Apply pending migrations
|
|
bunx drizzle-kit migrate
|
|
```
|
|
|
|
Schema files: `packages/backend/src/db/schema/`
|
|
|
|
## Multi-Tenancy
|
|
|
|
All domain tables include `company_id` (uuid FK to `company`). Every query filters by the authenticated user's company. Location-scoped tables additionally include `location_id`.
|
|
|
|
## Schema Overview
|
|
|
|
### Core
|
|
|
|
| Table | Description |
|
|
|-------|-------------|
|
|
| `company` | Tenant (tenant business) |
|
|
| `location` | Physical store location |
|
|
| `user` | Staff/admin user account |
|
|
|
|
### Accounts & Members
|
|
|
|
| Table | Description |
|
|
|-------|-------------|
|
|
| `account` | Billing entity (family, individual, business) |
|
|
| `member` | Individual person on an account |
|
|
| `member_identifier` | ID documents (DL, passport, school ID) |
|
|
| `payment_method` | Stored payment methods |
|
|
| `processor_link` | Payment processor integrations |
|
|
| `tax_exemption` | Tax exemption records |
|
|
|
|
### Inventory
|
|
|
|
| Table | Description |
|
|
|-------|-------------|
|
|
| `product` | Product catalog entry |
|
|
| `inventory_unit` | Individual serialized/non-serialized unit |
|
|
| `stock_receipt` | Incoming stock records |
|
|
| `category` | Product categories |
|
|
| `supplier` | Product suppliers |
|
|
| `inventory_unit_status` | Lookup: unit statuses |
|
|
| `item_condition` | Lookup: item conditions |
|
|
|
|
### RBAC
|
|
|
|
| Table | Description |
|
|
|-------|-------------|
|
|
| `permission` | System permissions (global, seeded) |
|
|
| `role` | Company-scoped roles (system + custom) |
|
|
| `role_permission` | Role-to-permission mapping |
|
|
| `user_role_assignment` | User-to-role mapping |
|
|
|
|
### Files
|
|
|
|
| Table | Description |
|
|
|-------|-------------|
|
|
| `file` | File metadata (path, type, size, entity reference) |
|
|
|
|
## Key Conventions
|
|
|
|
- UUIDs for all primary keys (`defaultRandom()`)
|
|
- `created_at` and `updated_at` timestamps with timezone on all tables
|
|
- Soft deletes via `is_active` boolean where applicable
|
|
- Auto-generated sequential numbers: `account_number` (6-digit), `member_number`
|
|
- Lookup tables support both system (immutable) and custom (company-scoped) values
|