Generation Workflow
Modify Entity
Edit JSON file Fields, types, indexes
Sonamu UI
Generate button Auto compare and generate
Review Migration
src/migrations/*.ts Review up/down
Execute
pnpm sonamu migrate Apply to DB
Generating in Sonamu UI
1. Modify Entity
First, modify the Entity JSON file:2. Open Sonamu UI
Start the API dev server and open it in a browser. Sonamu UI is served from the API server’s/sonamu-ui path, without a separate port.

3. Click Generate Button
Click the Generate button in the Entity tab.
4. Review Migration
Review the automatically generated Migration file:Sonamu compares Entity with the current DB schema and generates migrations only for differences.
Generated Migration Types
New Table Creation
Adding Entity:Adding Column
Entity Change:Dropping Column
Entity Change:Changing Column Type
Entity Change:Adding Index
Entity Change:where is a raw SQL predicate used directly as a PostgreSQL partial index condition. Do not combine it
with user input — only declare stable column conditions. Even when PostgreSQL introspection returns
the predicate wrapped in parentheses, Sonamu treats it as the same condition in migration diffs.
Adding Foreign Key
Entity Change:Composite Changes
Multiple changes result in multiple migrations: Entity Changes:Sonamu separates migrations by change type for easier management.
Migration Filename Convention
- timestamp:
YYYYMMDDHHmmss - action:
create,alter,foreign,drop - table_name: underscore-separated
- number:
add1,add2, etc. when multiple of the same action
Pre-generation Checklist
1. Verify DB Connection
2. Check Existing Migration Status
3. Sync Entities
Manual Modification
You can manually modify auto-generated migrations:Special Cases
Generated Columns
Data Migration
Conditional Execution
Next Steps
Running Migrations
Apply with migrate run
Rolling Back
Undo changes
How It Works
Understanding auto-generation
Strategies
Safe migration practices