vix orm
vix orm provides database migration and schema management tooling.
Use it when you want to apply migrations, roll back migrations, inspect migration status, or generate migration files from schema changes.
vix orm is a CLI wrapper around the Vix database migrator tool. It resolves your project, finds the migrations directory, locates the migrator executable, then forwards the command to the database migration engine.
Usage
vix orm migrate [options]
vix orm rollback --steps <n> [options]
vix orm status [options]
vix orm makemigrations --new <schema.json> [options]2
3
4
Subcommands
| Subcommand | Purpose |
|---|---|
migrate | Apply pending migrations. |
rollback | Roll back applied migrations. |
status | Show migration status. |
makemigrations | Generate migration files from schema changes. |
Basic usage
vix orm migrate --db blog_db --dir ./migrations
vix orm status --db blog_db
vix orm rollback --steps 1 --db blog_db
vix orm makemigrations --new ./schema.new.json2
3
4
More complete makemigrations example:
vix orm makemigrations \
--new ./schema.new.json \
--snapshot ./schema.json \
--dir ./migrations \
--name create_users \
--dialect mysql2
3
4
5
6
What it does
vix orm helps manage database schema changes.
It can:
apply migration files
roll back migration files
inspect migration state
generate .up.sql and .down.sql files from schema JSON diffs
reuse environment defaults
detect the current project root
detect common migration directories
call the installed Vix database migrator tool2
3
4
5
6
7
8
Project detection
vix orm tries to detect the project root automatically.
It looks upward from the current directory and prefers:
a Vix repository root
an application root with CMakePresets.json
an application root with src/ and CMakeLists.txt
a directory with CMakeLists.txt2
3
4
If detection fails, pass the root manually:
vix orm migrate --project-dir /path/to/project --db blog_dbMigration directory detection
If --dir is not provided, Vix tries common migration locations:
migrations
db/migrations
database/migrations
sql/migrations
db/sql
migrations/mysql
migrations/sqlite2
3
4
5
6
7
If none exists, Vix falls back to:
migrationsFor migrate, rollback, and status, the migrations directory must already exist.
For makemigrations, Vix creates the migrations directory if it is missing.
Migrator tool resolution
vix orm calls the Vix database migrator executable.
The preferred tool name is:
vix_db_migratorTool resolution order:
VIX_DB_TOOL
VIX_ORM_TOOL
installed libexec paths
same directory as the vix binary
development build paths
vix_db_migrator from PATH2
3
4
5
6
VIX_ORM_TOOL is kept for backward compatibility.
Prefer VIX_DB_TOOL for new setups.
VIX_DB_TOOL=/path/to/vix_db_migrator vix orm migrate --db blog_dbMigrate
vix orm migrate --db blog_db --dir ./migrationsmigrate applies all pending migration files from the migrations directory.
With environment defaults:
VIX_ORM_DB=blog_db \
VIX_ORM_USER=root \
VIX_ORM_PASS=secret \
vix orm migrate --dir ./migrations2
3
4
Rollback
vix orm rollback --steps 1 --db blog_db --dir ./migrationsRollback requires --steps.
vix orm rollback --steps 2 --db blog_db--steps must be greater than or equal to 1.
Status
vix orm status --db blog_db --dir ./migrationsstatus checks the migration setup and prints migration information.
The current implementation prints the migrations directory and a status message from the migrator.
Makemigrations
vix orm makemigrations --new ./schema.new.jsonmakemigrations compares a previous schema snapshot with a new schema JSON file.
Default previous snapshot:
schema.jsonDefault migration name:
autoDefault dialect:
mysqlComplete example:
vix orm makemigrations \
--new ./schema.new.json \
--snapshot ./schema.json \
--dir ./migrations \
--name create_users \
--dialect mysql2
3
4
5
6
This generates files like:
migrations/2026_05_28_130501_create_users.up.sql
migrations/2026_05_28_130501_create_users.down.sql2
It also updates the snapshot file with the new schema.
Schema workflow
A typical schema workflow looks like this:
# 1. Edit or generate a new schema file
vim schema.new.json
# 2. Generate migration files
vix orm makemigrations \
--new ./schema.new.json \
--snapshot ./schema.json \
--dir ./migrations \
--name add_users \
--dialect mysql
# 3. Apply migrations
vix orm migrate --db blog_db --dir ./migrations
# 4. Check status
vix orm status --db blog_db --dir ./migrations
# 5. Validate the project
vix check --tests2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Dialects
Accepted dialect values:
mysql
sqlite2
Current implementation note:
makemigrations currently generates SQL for mysql only.If --dialect sqlite is passed to makemigrations, the CLI accepts the value, but the generator can still fail because SQLite SQL generation is not implemented yet.
Use MySQL for migration generation today:
vix orm makemigrations \
--new ./schema.new.json \
--dialect mysql2
3
Database drivers
The migrator uses the database drivers enabled when the tool was built.
If MySQL support is enabled, the migrator uses the MySQL driver.
If SQLite support is enabled instead, the migrator uses the SQLite driver.
If no database driver is enabled, the migrator reports that it was built without DB drivers.
Common options
| Option | Description |
|---|---|
--db <name> | Database name. Overrides VIX_ORM_DB. |
--dir <path> | Migrations directory. Overrides VIX_ORM_DIR. |
--host <uri> | MySQL URI. Default is tcp://127.0.0.1:3306. |
--user <name> | Database user. Default is root. |
--pass <pass> | Database password. |
--project-dir <path> | Force project root detection. |
--tool <path> | Override migrator executable path. |
-h, --help | Show command help. |
Makemigrations options
| Option | Description | |
|---|---|---|
--new <path> | New schema JSON file. Required. | |
--snapshot <path> | Previous snapshot. Default is schema.json. | |
--name <label> | Migration label. Default is auto. | |
| `--dialect <mysql | sqlite>` | SQL dialect. Default is mysql. |
Rollback options
| Option | Description |
|---|---|
--steps <n> | Roll back the last N applied migrations. Required. |
Environment variables
| Variable | Description |
|---|---|
VIX_ORM_HOST | Default database host. Default is tcp://127.0.0.1:3306. |
VIX_ORM_USER | Default database user. Default is root. |
VIX_ORM_PASS | Default database password. |
VIX_ORM_DB | Default database name. Default is vixdb. |
VIX_ORM_DIR | Default migrations directory. |
VIX_DB_TOOL | Preferred migrator executable path. |
VIX_ORM_TOOL | Legacy migrator executable path. |
Common workflows
Run migrations
vix orm migrate --db blog_db --dir ./migrationsCheck migration status
vix orm status --db blog_db --dir ./migrationsRoll back one migration
vix orm rollback --steps 1 --db blog_db --dir ./migrationsGenerate a MySQL migration
vix orm makemigrations \
--new ./schema.new.json \
--snapshot ./schema.json \
--dir ./migrations \
--name create_users \
--dialect mysql2
3
4
5
6
Use environment defaults
VIX_ORM_DB=blog_db \
VIX_ORM_USER=root \
VIX_ORM_PASS=secret \
vix orm migrate --dir ./migrations2
3
4
Use a custom migrator tool
VIX_DB_TOOL=./build/db_build/vix_db_migrator \
vix orm migrate --db blog_db --dir ./migrations2
Force project root
vix orm migrate \
--project-dir /home/me/apps/blog \
--db blog_db \
--dir ./migrations2
3
4
Recommended migration workflow
# 1. Generate a migration
vix orm makemigrations \
--new ./schema.new.json \
--snapshot ./schema.json \
--dir ./migrations \
--name add_users \
--dialect mysql
# 2. Review generated SQL
cat ./migrations/*.up.sql
cat ./migrations/*.down.sql
# 3. Apply migrations
vix orm migrate --db blog_db --dir ./migrations
# 4. Check migration status
vix orm status --db blog_db --dir ./migrations
# 5. Validate the project
vix check --tests2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
CI usage
vix install
vix orm migrate --db blog_db --dir ./migrations
vix check --tests2
3
With environment variables:
VIX_ORM_HOST=tcp://127.0.0.1:3306 \
VIX_ORM_USER=root \
VIX_ORM_PASS=secret \
VIX_ORM_DB=blog_db \
vix orm migrate --dir ./migrations2
3
4
5
Common mistakes
Forgetting --steps during rollback
Wrong:
vix orm rollback --db blog_dbCorrect:
vix orm rollback --steps 1 --db blog_dbForgetting --new during makemigrations
Wrong:
vix orm makemigrations --name create_usersCorrect:
vix orm makemigrations --new ./schema.new.json --name create_usersExpecting makemigrations to connect to the database
makemigrations does not need database connection arguments.
It compares schema files and writes migration files.
vix orm makemigrations --new ./schema.new.jsonExpecting SQLite migration generation to be complete
The CLI accepts:
vix orm makemigrations --new ./schema.new.json --dialect sqliteBut SQL generation is currently implemented for MySQL.
Use:
vix orm makemigrations --new ./schema.new.json --dialect mysqlPassing passwords directly in shell history
Avoid this when possible:
vix orm migrate --db blog_db --user root --pass secretPrefer environment variables:
VIX_ORM_PASS=secret vix orm migrate --db blog_dbRunning outside a project
If project detection fails, use:
vix orm migrate \
--project-dir /path/to/project \
--db blog_db \
--dir ./migrations2
3
4
Forgetting to create migrations directory
For migrate, rollback, and status, the directory must exist.
mkdir -p migrations
vix orm migrate --db blog_db --dir ./migrations2
makemigrations can create the directory automatically.
Troubleshooting
Migrator tool not found
Use:
VIX_DB_TOOL=/path/to/vix_db_migrator \
vix orm migrate --db blog_db --dir ./migrations2
Or pass it directly:
vix orm migrate \
--tool /path/to/vix_db_migrator \
--db blog_db \
--dir ./migrations2
3
4
Project directory not detected
Use:
vix orm migrate \
--project-dir /path/to/project \
--db blog_db2
3
Migrations directory not found
Create it:
mkdir -p migrationsThen run:
vix orm migrate --db blog_db --dir ./migrationsDatabase driver missing
If the migrator says it was built without DB drivers, rebuild Vix with the required database driver enabled.
For MySQL:
vix build --with-mysqlFor SQLite:
vix build --with-sqliteRelated commands
| Command | Purpose |
|---|---|
vix db | Database checks, migrations, and SQLite backup tooling. |
vix build --with-mysql | Build with MySQL support. |
vix build --with-sqlite | Build with SQLite support. |
vix check | Validate the project after migrations. |
vix task | Automate migration workflows. |
vix env check | Validate project environment files. |
Next step
Continue with peer-to-peer nodes.