docs: schema migration plan v1.0.0 + production .env
This commit is contained in:
61
docs_v1.0/API_V1.0.0/RELEASE/SCHEMA_MIGRATION_PLAN_v1.0.0.md
Normal file
61
docs_v1.0/API_V1.0.0/RELEASE/SCHEMA_MIGRATION_PLAN_v1.0.0.md
Normal file
@@ -0,0 +1,61 @@
|
||||
# Schema Migration Plan v1.0.0
|
||||
|
||||
## Goal
|
||||
|
||||
Production server (port 3002, `target/release/momentry`) should use `public` schema.
|
||||
Dev server (port 3003, `momentry_playground`) should use `dev` schema.
|
||||
|
||||
## Steps
|
||||
|
||||
### ✅ Step 1: Copy dev → public (已完成)
|
||||
|
||||
```sql
|
||||
-- For each table in dev that isn't in public:
|
||||
CREATE TABLE public.{table} (LIKE dev.{table} INCLUDING ALL);
|
||||
INSERT INTO public.{table} SELECT * FROM dev.{table};
|
||||
|
||||
-- For tables that exist in both:
|
||||
TRUNCATE public.{table} CASCADE;
|
||||
INSERT INTO public.{table} SELECT * FROM dev.{table};
|
||||
```
|
||||
|
||||
⚠️ **教訓**: `TRUNCATE` 要在確認能成功 INSERT 之後才執行,或使用 transactional approach。
|
||||
|
||||
### ⬜ Step 2: Update sequences
|
||||
|
||||
```sql
|
||||
SELECT setval('public.chunks_id_seq', (SELECT MAX(id) FROM public.chunks));
|
||||
SELECT setval('public.face_detections_id_seq', (SELECT MAX(id) FROM public.face_detections));
|
||||
SELECT setval('public.identities_id_seq', (SELECT MAX(id) FROM public.identities));
|
||||
SELECT setval('public.pre_chunks_id_seq', (SELECT MAX(id) FROM public.pre_chunks));
|
||||
SELECT setval('public.processor_results_id_seq', (SELECT MAX(id) FROM public.processor_results));
|
||||
SELECT setval('public.videos_id_seq', (SELECT MAX(id) FROM public.videos));
|
||||
```
|
||||
|
||||
### ⬜ Step 3: Set indexes and constraints
|
||||
|
||||
pg_dump with `--schema-only` from dev, apply to public to ensure identical structure.
|
||||
|
||||
### ⬜ Step 4: Update production config
|
||||
|
||||
`.env` 移除 `DATABASE_SCHEMA=dev`(production binary 預設用 `public`)
|
||||
|
||||
### ⬜ Step 5: Restart production server
|
||||
|
||||
```bash
|
||||
kill -9 $(lsof -ti :3002)
|
||||
# launchd will auto-restart with new binary
|
||||
```
|
||||
|
||||
### ⬜ Step 6: Verify
|
||||
|
||||
```bash
|
||||
curl http://localhost:3002/api/v1/file/{uuid}/face_trace/sortby -X POST -d '{"limit":1}'
|
||||
# → should return data from public schema
|
||||
```
|
||||
|
||||
## Rollback
|
||||
|
||||
If migration fails:
|
||||
- `public` tables with data can be reverted: `TRUNCATE public.{table}; INSERT INTO public.{table} SELECT * FROM dev.{table};`
|
||||
- `.env` can be reverted to `DATABASE_SCHEMA=dev`
|
||||
Reference in New Issue
Block a user