Migrations
Schema migrations with branching, rollback, and CI/CD integration
Overview
Run schema migrations safely using database branches. Test changes in isolation before applying to production.
Workflow
The migration API is a three-step loop: register, plan, apply (or rollback). Registering is bookkeeping only. Apply is what runs your SQL.
1. Register a migration
curl -X POST https://api.scalix.world/api/v1/tenants/$TENANT_ID/migrations \
-H "Authorization: Bearer $SCALIX_API_KEY" \
-d '{
"name": "create orders",
"up_sql": "CREATE TABLE orders (id SERIAL PRIMARY KEY, total DECIMAL(10,2))",
"down_sql": "DROP TABLE orders"
}'The version is assigned by the server: the next sequential number for the
project, starting at 1. Do not send one: the body is strict
(name/up_sql/down_sql only) and a version field is rejected. The response
returns the assigned version plus a checksum of up_sql; that version is what
you pass to apply and rollback.
2. Check the plan
curl https://api.scalix.world/api/v1/tenants/$TENANT_ID/migrations/plan \
-H "Authorization: Bearer $SCALIX_API_KEY"Shows which registered migrations are still pending.
3. Apply
curl -X POST https://api.scalix.world/api/v1/tenants/$TENANT_ID/migrations/1/apply \
-H "Authorization: Bearer $SCALIX_API_KEY"Apply executes up_sql against your database and marks the migration applied
(rollback executes down_sql the same way). If the SQL fails, the migration is
not marked applied. Applying an already-applied version is an error, not a
no-op.
4. Create a branch (test first)
Create a branch via the API to isolate your migration:
5. Apply migrations on the branch
scalix-cloud db query "CREATE TABLE orders (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
total DECIMAL(10,2),
created_at TIMESTAMPTZ DEFAULT NOW()
)"6. Test
Run your application against the branch to verify everything works.
7. Merge
Apply the same migration to production:
scalix-cloud db query "CREATE TABLE orders (...)"8. Clean up
Delete the branch via the API when done.
CI/CD Integration
Use branches in your CI pipeline:
# .github/workflows/test.yml
jobs:
test:
steps:
- name: Create test branch
run: |
curl -X POST https://api.scalix.world/api/v1/tenants/$TENANT_ID/timelines/$TIMELINE_ID/branch \
-H "Authorization: Bearer $SCALIX_API_KEY"
- name: Run migrations
run: scalix-cloud db query "CREATE TABLE orders (...)"
- name: Run tests
run: npm testMigration from Other Platforms
Import data from existing databases:
scalix-cloud migrate db import --source postgres://user:pass@host:5432/mydbImports from a live PostgreSQL source (via pg_dump → pg_restore). The
--source must be a reachable PostgreSQL connection string.
MySQL sources and standalone SQL dump files are not supported. The importer
only connects to a running PostgreSQL server. To load a dump file, restore it
into a PostgreSQL instance first, or apply it directly with psql/pg_restore
against your Scalix connection string.