refactor: update environment configuration, enhance installation script, and add migration scripts for database setup

This commit is contained in:
Poyraz Avsever
2026-06-13 21:10:21 +03:00
parent a47e39455c
commit 17ff60faea
12 changed files with 400 additions and 74 deletions
+22
View File
@@ -0,0 +1,22 @@
# 0004 - Business OS Tables
SQL file: `supabase/migrations/0004_add_business_os_tables.sql`
## Purpose
Adds business document and recurring cost tables used by the freelancer business layer.
## What It Creates
- `proposals`
- `contracts`
- `invoices`
- `subscriptions`
## RLS
Every table has `user_id` and row level security policies that allow users to select, insert, update, and delete only their own rows.
## Execution
Run after `0003_add_project_planning_assets.sql`.
+28
View File
@@ -0,0 +1,28 @@
# 0005 - Advanced CRM Tables
SQL file: `supabase/migrations/0005_add_advanced_crm_tables.sql`
## Purpose
Extends client management with pipeline and activity tracking fields.
## What It Changes
The `clients` table receives:
- `pipeline_stage`
- `next_follow_up_date`
- `last_contact_date`
- `client_value_score`
## What It Creates
- `client_activities`
## RLS
`client_activities` is user-scoped through `user_id` and has select, insert, update, and delete policies for the owning user.
## Execution
Run after `0004_add_business_os_tables.sql`.
@@ -0,0 +1,25 @@
# 0006 - pgvector And Embeddings
SQL file: `supabase/migrations/0006_add_pgvector_and_embeddings.sql`
## Purpose
Adds vector storage for future retrieval augmented generation features.
## What It Creates
- `vector` extension
- `document_embeddings`
- `match_documents()`
## RLS
Embeddings are scoped by `user_id`; users can manage only their own embedding rows.
## Notes
The migration expects the target Postgres/Supabase environment to support the `vector` extension.
## Execution
Run after `0005_add_advanced_crm_tables.sql`.
@@ -0,0 +1,25 @@
# 0007 - Client Portal Tables
SQL file: `supabase/migrations/0007_add_client_portal_tables.sql`
## Purpose
Adds client portal access and revision request support.
## What It Changes
- Adds `profiles.role`
- Adds `clients.client_auth_id`
- Adds `tasks.is_public_to_client`
## What It Creates
- `project_revisions`
## RLS
Freelancers manage revisions for their own projects. Clients can view their linked client record, related projects, public project tasks, project planning sections, and their own revision requests.
## Execution
Run after `0006_add_pgvector_and_embeddings.sql`.
@@ -0,0 +1,29 @@
# 0008 - Project Progress And Quota
SQL file: `supabase/migrations/0008_add_project_progress_and_quota.sql`
## Purpose
Adds project progress mode and revision quota support.
## What It Changes
The `projects` table receives:
- `progress_type`
- `revision_quota`
## What It Creates
- `update_project_progress_on_task_change()`
- `trigger_update_project_progress`
- `update_project_progress_on_type_change()`
- `trigger_update_project_progress_type`
## Notes
Automatic progress mode calculates progress from tasks with status `done`.
## Execution
Run after `0007_add_client_portal_tables.sql`.
+15
View File
@@ -7,6 +7,11 @@ This file is the canonical order of SQL files for database setup and migration.
| 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 |
| 0003 | `supabase/migrations/0003_add_project_planning_assets.sql` | `docs/database/0003-project-planning-assets.md` | Pending execution |
| 0004 | `supabase/migrations/0004_add_business_os_tables.sql` | `docs/database/0004-business-os-tables.md` | Pending execution |
| 0005 | `supabase/migrations/0005_add_advanced_crm_tables.sql` | `docs/database/0005-advanced-crm-tables.md` | Pending execution |
| 0006 | `supabase/migrations/0006_add_pgvector_and_embeddings.sql` | `docs/database/0006-pgvector-and-embeddings.md` | Pending execution |
| 0007 | `supabase/migrations/0007_add_client_portal_tables.sql` | `docs/database/0007-client-portal-tables.md` | Pending execution |
| 0008 | `supabase/migrations/0008_add_project_progress_and_quota.sql` | `docs/database/0008-project-progress-and-quota.md` | Pending execution |
| 0009 | `supabase/migrations/0009_lock_registration_after_first_admin.sql` | `docs/database/0009-lock-registration-after-first-admin.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 |
@@ -23,3 +28,13 @@ This file is the canonical order of SQL files for database setup and migration.
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.
## Applying The Ordered SQL
Use the migration helper from the repository root:
```bash
DATABASE_URL='postgresql://postgres:password@host:5432/postgres' bash ./scripts/apply-migrations.sh
```
The helper applies `0001` through `0009` in the order listed above. It uses local `psql` when available, otherwise it runs `psql` through Docker.