feat: add DBML schema files and relspecgo migration generation
- Add schema/*.dbml covering all existing tables (001-019) - Wire relspecgo via make generate-migrations target - Add make check-schema-drift for CI drift detection - Add schema/README.md documenting the DBML-first workflow Closes #19
This commit is contained in:
35
schema/README.md
Normal file
35
schema/README.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Schema workflow
|
||||
|
||||
The `schema/*.dbml` files are the database schema source of truth.
|
||||
|
||||
## Generate SQL migrations
|
||||
|
||||
Run:
|
||||
|
||||
```bash
|
||||
make generate-migrations
|
||||
```
|
||||
|
||||
This uses `relspec` to convert the DBML files into PostgreSQL SQL and writes the generated schema migration to:
|
||||
|
||||
- `migrations/020_generated_schema.sql`
|
||||
|
||||
## Check schema drift
|
||||
|
||||
Run:
|
||||
|
||||
```bash
|
||||
make check-schema-drift
|
||||
```
|
||||
|
||||
This regenerates the SQL from `schema/*.dbml` and compares it with `migrations/020_generated_schema.sql`.
|
||||
If the generated output differs, the command fails so CI can catch schema drift.
|
||||
|
||||
## Workflow
|
||||
|
||||
1. Update the DBML files in `schema/`
|
||||
2. Run `make generate-migrations`
|
||||
3. Review the generated SQL
|
||||
4. Commit both the DBML changes and the generated migration
|
||||
|
||||
Existing handwritten migrations stay in place. Going forward, update the DBML first and regenerate the SQL from there.
|
||||
Reference in New Issue
Block a user