Implements the Settings foundation workspace controls. Includes: - Settings foundation UI/controls scoped to workspace context - Related onboarding/consent flow adjustments as included in branch history Testing: - `vendor/bin/sail artisan test --compact --no-ansi --filter=SettingsFoundation` Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #119
78 lines
2.3 KiB
Markdown
78 lines
2.3 KiB
Markdown
# Data Model — Settings Foundation (Workspace + Optional Tenant Override) (097)
|
|
|
|
## Entities
|
|
|
|
### SettingDefinition (code-defined)
|
|
Represents a known (domain, key) setting with validation, normalization, and a system default.
|
|
|
|
- Fields (conceptual):
|
|
- `domain` (string)
|
|
- `key` (string)
|
|
- `type` (enum-like: int|string|bool|json)
|
|
- `system_default` (mixed)
|
|
- `rules` (validation rules; code-level)
|
|
- `normalize(value) -> value` (optional)
|
|
|
|
### WorkspaceSetting (DB: workspace-owned)
|
|
A workspace-wide override for a setting.
|
|
|
|
- Table: `workspace_settings`
|
|
- Fields:
|
|
- `id`
|
|
- `workspace_id` (FK → `workspaces.id`, NOT NULL)
|
|
- `domain` (string, NOT NULL)
|
|
- `key` (string, NOT NULL)
|
|
- `value` (JSON/JSONB, NOT NULL)
|
|
- `updated_by_user_id` (FK → `users.id`, nullable)
|
|
- timestamps
|
|
- Indexes / constraints:
|
|
- UNIQUE (`workspace_id`, `domain`, `key`)
|
|
- Index (`workspace_id`, `domain`)
|
|
|
|
### TenantSetting (DB: tenant-owned; backend-ready)
|
|
A tenant-specific override for a setting.
|
|
|
|
- Table: `tenant_settings`
|
|
- Fields:
|
|
- `id`
|
|
- `workspace_id` (FK → `workspaces.id`, NOT NULL)
|
|
- `tenant_id` (FK → `tenants.id`, NOT NULL)
|
|
- `domain` (string, NOT NULL)
|
|
- `key` (string, NOT NULL)
|
|
- `value` (JSON/JSONB, NOT NULL)
|
|
- `updated_by_user_id` (FK → `users.id`, nullable)
|
|
- timestamps
|
|
- Indexes / constraints:
|
|
- UNIQUE (`tenant_id`, `domain`, `key`)
|
|
- Index (`workspace_id`, `tenant_id`)
|
|
|
|
## Relationships
|
|
|
|
- Workspace has many WorkspaceSettings.
|
|
- Workspace has many TenantSettings.
|
|
- Tenant has many TenantSettings.
|
|
|
|
## Invariants / Rules enforced by this feature
|
|
|
|
- Resolution precedence is deterministic:
|
|
- tenant override → workspace override → system default.
|
|
- Workspace isolation:
|
|
- all reads/writes must be scoped to the active workspace context.
|
|
- tenant overrides must be rejected if the tenant does not belong to the workspace.
|
|
- Unknown keys are rejected:
|
|
- writes must only be allowed for keys in the SettingsRegistry.
|
|
- Validation is centralized:
|
|
- values are validated against the SettingDefinition before persistence.
|
|
- Reset semantics:
|
|
- reset removes the persisted override row (workspace or tenant) so resolution falls back.
|
|
|
|
## Pilot Setting (v1)
|
|
|
|
- Domain: `backup`
|
|
- Key: `retention_keep_last_default`
|
|
- Type: `int`
|
|
- System default: `30`
|
|
- Validation:
|
|
- integer
|
|
- minimum 1 (defensive)
|