Skip to main content

Migrations

The Divinux API is the only app with TypeORM migration scripts. The Platform API (core / situations) applies idempotent DDL on boot and tracks the rest manually in core.migrations.

Generating Migrations

# After modifying entities
npm run migration:generate:divinux

Running Migrations

npm run migration:run:divinux

Reverting Migrations

npm run migration:revert:divinux

Showing Migration Status

npm run migration:show:divinux

SQL Migrations

For core schema or complex changes, use SQL files in migrations/:

-- migrations/009_create_users_table.sql
BEGIN;
CREATE TABLE IF NOT EXISTS core.users (...);
COMMIT;

Apply manually:

psql -h <host> -U statux_admin -d statux -f migrations/009_create_users_table.sql

Best Practices

  • Test migrations locally before deploying
  • Create database snapshot before production migrations
  • Keep migrations idempotent (IF NOT EXISTS, ON CONFLICT DO NOTHING)