feat: add core database schema and demo seed data for Freelancer OS MVP

This commit is contained in:
Poyraz Avsever
2026-06-01 11:51:43 +03:00
parent 53a225594a
commit c0d25a87e8
8 changed files with 698 additions and 0 deletions
@@ -0,0 +1,72 @@
# 0002 Freelancer OS Core Tables
SQL file: `supabase/migrations/0002_add_freelancer_os_core_tables.sql`
## Purpose
Adds the database model required for the Freelancer OS MVP.
This migration keeps the existing baseline from `supabase/schema.sql` and extends it instead of replacing it. The existing `tasks` table is reused and enriched with freelancer-specific fields.
## What It Creates
- `clients`
- `projects`
- `calendar_events`
- `finance_transactions`
- `daily_logs`
- `app_settings`
- `set_updated_at()` trigger function
- updated-at triggers for the new tables
- indexes for common dashboard/report queries
- RLS policies for every new table
## What It Changes
The existing `tasks` table gets these additional columns:
- `client_id`
- `project_id`
- `priority`
- `due_at`
- `estimated_minutes`
- `actual_minutes`
This lets a task belong to a client and/or project while preserving the earlier journal/task prototype schema.
## MVP Coverage
This migration supports:
- client management
- client projects
- side projects
- task planning
- calendar planning
- income and expense tracking
- daily mood/energy logging
- app and AI provider settings
## RLS Model
Every new table has `user_id`.
Policies follow the same pattern:
- users can select their own rows
- users can insert rows only for themselves
- users can update their own rows
- users can delete their own rows
## Notes
`app_settings.api_key` exists for compatibility with the current prototype flow. For production-grade use, provider credentials should be encrypted or moved to a safer secret-management strategy.
`daily_logs` is the new MVP-oriented replacement for the earlier `journals` concept. The old `journals` table remains available until the UI migration is complete.
## Execution
Run this after `supabase/schema.sql`.
Do not add this file to `query-log.md` until it has actually been executed against a database.
+9
View File
@@ -15,7 +15,11 @@ The project currently starts with `supabase/schema.sql` as the first database qu
## Current Files
- `supabase/schema.sql`: Initial legacy schema. It creates the current auth/profile, journal, task, chat, and avatar storage structure.
- `supabase/migrations/0002_add_freelancer_os_core_tables.sql`: Freelancer OS MVP core schema.
- `supabase/seeds/0001_demo_freelancer_os_data.sql`: Optional local/demo data for the MVP schema.
- `docs/database/0001-initial-schema.md`: Explanation for the initial schema.
- `docs/database/0002-freelancer-os-core-tables.md`: Explanation for the MVP schema migration.
- `docs/database/seed-0001-demo-freelancer-os-data.md`: Explanation for the demo seed file.
- `docs/database/query-order.md`: Canonical order of SQL files.
- `docs/database/query-log.md`: Manual execution log for SQL files that were run against an environment.
@@ -33,3 +37,8 @@ Example:
supabase/migrations/0002_add_freelancer_os_core_tables.sql
```
Use this pattern for future seed files:
```text
supabase/seeds/0002_short_description.sql
```
+7
View File
@@ -5,6 +5,8 @@ This file is the canonical order of SQL files for database setup and migration.
| Order | SQL file | Documentation | Status |
| --- | --- | --- | --- |
| 0001 | `supabase/schema.sql` | `docs/database/0001-initial-schema.md` | Baseline registered |
| 0002 | `supabase/migrations/0002_add_freelancer_os_core_tables.sql` | `docs/database/0002-freelancer-os-core-tables.md` | Pending execution |
| seed-0001 | `supabase/seeds/0001_demo_freelancer_os_data.sql` | `docs/database/seed-0001-demo-freelancer-os-data.md` | Optional demo seed, pending execution |
## How To Add The Next Query
@@ -14,3 +16,8 @@ This file is the canonical order of SQL files for database setup and migration.
4. Register both files in this table.
5. After running the SQL, add an entry to `query-log.md`.
## Seed Files
Seed files are optional and should live under `supabase/seeds/`.
They must also be documented and registered in this file, but they should only be run in local/demo environments unless explicitly approved.
@@ -0,0 +1,43 @@
# Seed 0001 Demo Freelancer OS Data
SQL file: `supabase/seeds/0001_demo_freelancer_os_data.sql`
## Purpose
Adds demo data for local development and dashboard testing after the Freelancer OS core tables are created.
## What It Inserts
- demo clients
- demo projects and one side project
- demo tasks
- demo calendar events
- demo finance transactions
- demo daily mood/energy logs
- demo `app_settings`
## Required Manual Step
Before running the file, replace this placeholder with a real `auth.users.id`:
```sql
'00000000-0000-0000-0000-000000000000'::uuid
```
Use a user id from your Supabase Auth users table.
## Environment
This seed is intended for local and demo environments only.
Do not run it on production data.
## Execution
Run after:
1. `supabase/schema.sql`
2. `supabase/migrations/0002_add_freelancer_os_core_tables.sql`
After running it, add an entry to `docs/database/query-log.md`.