Vix.cpp v2.6.0 is here Read the blog
Skip to content

vix db

vix db inspects and manages project database state.

Use it when you want to check database configuration, inspect SQLite storage status, apply migrations, or create a local database backup.

bash
vix db
1

Overview

vix db is the database utility command for Vix projects.

It can:

  • inspect database configuration
  • detect SQLite usage
  • check whether the storage directory exists
  • check whether the storage directory is writable
  • check whether the database file exists
  • show SQLite WAL and SHM sidecar paths
  • check whether migration files exist
  • apply file-based SQL migrations
  • create timestamped SQLite backups
  • copy SQLite WAL and SHM sidecar files when present
  • print status as JSON for scripts and CI

The command is currently focused on SQLite project workflows.

MySQL can be detected from configuration, but migration and backup actions currently support SQLite only.

Usage

bash
vix db [action] [options]
1

Actions

ActionPurpose
statusInspect database and storage status. This is the default action.
migrateApply pending file-based SQL migrations.
backupCreate a SQLite database backup.

Basic examples

bash
# Inspect database status
vix db

# Same as vix db
vix db status

# Print status as JSON
vix db status --json

# Apply migrations
vix db migrate

# Create a database backup
vix db backup

# Show verbose diagnostics
vix db status --verbose
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

Default action

If no action is passed, Vix runs:

bash
vix db status
1

So these are equivalent:

bash
vix db
vix db status
1
2

Configuration source

vix db reads database configuration from:

txt
vix.json
1

under:

txt
database
1

Example:

json
{
  "name": "PulseGrid",
  "database": {
    "engine": "sqlite",
    "sqlite": {
      "path": "storage/PulseGrid.db"
    },
    "storage": "storage",
    "migrations": "migrations"
  }
}
1
2
3
4
5
6
7
8
9
10
11

Database config fields

FieldPurpose
database.engineDatabase engine. Supported values: sqlite, mysql.
database.sqlite.pathSQLite database file path.
database.sqlite_pathFlat alternative for SQLite path.
database.storageStorage directory.
database.migrationsMigrations directory.

Default configuration

If no database configuration exists, Vix uses SQLite defaults based on the project name.

For a project named:

txt
PulseGrid
1

the defaults are:

txt
engine: sqlite
database: storage/PulseGrid.db
storage: storage
migrations: migrations
wal: storage/PulseGrid.db-wal
shm: storage/PulseGrid.db-shm
1
2
3
4
5
6

Project name is detected from:

txt
vix.json name
*.vix file name
current directory name
1
2
3

SQLite config example

json
{
  "name": "PulseGrid",
  "database": {
    "engine": "sqlite",
    "sqlite": {
      "path": "storage/PulseGrid.db"
    },
    "storage": "storage",
    "migrations": "migrations"
  }
}
1
2
3
4
5
6
7
8
9
10
11

Flat SQLite path example

You can also use the flat sqlite_path field:

json
{
  "name": "PulseGrid",
  "database": {
    "engine": "sqlite",
    "sqlite_path": "storage/PulseGrid.db",
    "storage": "storage",
    "migrations": "migrations"
  }
}
1
2
3
4
5
6
7
8
9

MySQL config detection

Vix can parse:

json
{
  "database": {
    "engine": "mysql"
  }
}
1
2
3
4
5

But current migrate and backup actions support SQLite only.

If you run migration with MySQL configured, Vix reports:

txt
vix db migrate currently supports SQLite only.
Fix: set database.engine to sqlite
1
2

If you run backup with MySQL configured, Vix reports:

txt
vix db backup currently supports SQLite only.
Fix: set database.engine to sqlite before using vix db backup
1
2

Status

Run:

bash
vix db status
1

or:

bash
vix db
1

This prints the database status.

Example output shape:

txt
Database
Project: PulseGrid
Engine: sqlite
Path: storage/PulseGrid.db
Storage: storage
Database exists: yes
Storage exists: yes
Storage writable: yes

SQLite
Detected: yes
WAL path: storage/PulseGrid.db-wal
WAL file: not present
SHM path: storage/PulseGrid.db-shm
SHM file: not present

Migrations
Directory: migrations
Exists: yes

Status
Result: ok
database status looks good
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

What status checks

vix db status checks:

CheckMeaning
engineWhether the database engine is known.
SQLite detectionWhether the project looks like a SQLite project.
storage directoryWhether the storage directory exists.
storage writableWhether Vix can write into the storage directory.
database fileWhether the database file exists.
WAL fileWhether the SQLite WAL sidecar file exists.
SHM fileWhether the SQLite SHM sidecar file exists.
migrations directoryWhether the migrations directory exists.

Status levels

vix db status can produce three statuses:

StatusMeaningExit code
okDatabase status looks good.0
warningSomething is missing, but it may be normal.0
errorA required condition failed.1

A missing database file is a warning because the database may not exist before the first migration.

A missing storage directory is an error because migrations and backups need it.

JSON status

Use:

bash
vix db status --json
1

Example output shape:

json
{
  "project": "PulseGrid",
  "engine": "sqlite",
  "status": "ok",
  "database": {
    "path": "storage/PulseGrid.db",
    "exists": true
  },
  "storage": {
    "path": "storage",
    "exists": true,
    "writable": true
  },
  "sqlite": {
    "detected": true,
    "wal_path": "storage/PulseGrid.db-wal",
    "wal_exists": false,
    "shm_path": "storage/PulseGrid.db-shm",
    "shm_exists": false
  },
  "migrations": {
    "path": "migrations",
    "exists": true
  },
  "warnings": [],
  "errors": []
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

Use JSON output for:

  • CI
  • scripts
  • deployment checks
  • dashboards
  • automated diagnostics

Migrations

Run:

bash
vix db migrate
1

This applies file-based SQL migrations from the configured migrations directory.

Example config:

json
{
  "database": {
    "engine": "sqlite",
    "sqlite": {
      "path": "storage/PulseGrid.db"
    },
    "storage": "storage",
    "migrations": "migrations"
  }
}
1
2
3
4
5
6
7
8
9
10

Expected output shape:

txt
Database Migrations
Engine: sqlite
Database: storage/PulseGrid.db
Directory: migrations
migrations applied successfully
1
2
3
4
5

Migration requirements

vix db migrate requires:

txt
database.engine = sqlite
storage directory exists
migrations directory exists
Vix CLI built with db module support
1
2
3
4

If the CLI was built without database support, Vix reports:

txt
vix db migrate is not available in this build.
Fix: rebuild the Vix CLI with the db module enabled
1
2

Migration files

Migrations are loaded from the configured migrations directory.

Default:

txt
migrations
1

A typical structure can look like:

txt
migrations/
├── 001_create_users.up.sql
├── 002_create_posts.up.sql
└── 003_add_indexes.up.sql
1
2
3
4

The migrator expects .up.sql migration files.

Create storage and migrations folders

Before running migrations, create the required directories:

bash
mkdir -p storage migrations
1

Then add migration files:

bash
touch migrations/001_init.up.sql
1

Then run:

bash
vix db migrate
1

Backup

Run:

bash
vix db backup
1

This creates a timestamped SQLite backup under:

txt
backups/
1

Example output shape:

txt
Database Backup
Database: storage/PulseGrid.db
Backup: backups/PulseGrid-20260528-120501.db
WAL copied: yes
SHM copied: yes
database backup created
1
2
3
4
5
6

Backup file naming

Backup files use the database filename and a timestamp.

For:

txt
storage/PulseGrid.db
1

Vix creates a backup like:

txt
backups/PulseGrid-20260528-120501.db
1

If the database has no extension, Vix uses:

txt
.db
1

WAL and SHM backups

SQLite may create sidecar files:

txt
storage/PulseGrid.db-wal
storage/PulseGrid.db-shm
1
2

When present, vix db backup copies them too.

For a backup:

txt
backups/PulseGrid-20260528-120501.db
1

the sidecar backups become:

txt
backups/PulseGrid-20260528-120501.db-wal
backups/PulseGrid-20260528-120501.db-shm
1
2

If WAL or SHM files are not present, Vix simply reports:

txt
WAL copied: no
SHM copied: no
1
2

That is not automatically an error.

Backup requirements

vix db backup requires:

txt
database.engine = sqlite
database file exists
1
2

If the database file does not exist, Vix reports:

txt
database file not found: storage/PulseGrid.db
Fix: run vix db migrate or create the database before backing it up
1
2

Full SQLite workflow

bash
mkdir -p storage migrations
1

Create a migration:

sql
-- migrations/001_init.up.sql
CREATE TABLE IF NOT EXISTS users (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  name TEXT NOT NULL,
  created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);
1
2
3
4
5
6

Check status:

bash
vix db status
1

Apply migrations:

bash
vix db migrate
1

Check again:

bash
vix db status
1

Create a backup:

bash
vix db backup
1

Full vix.json example

json
{
  "name": "PulseGrid",
  "database": {
    "engine": "sqlite",
    "sqlite": {
      "path": "storage/PulseGrid.db"
    },
    "storage": "storage",
    "migrations": "migrations"
  },
  "production": {
    "service": {
      "name": "pulsegrid",
      "health_local": "http://127.0.0.1:8080/"
    },
    "health": {
      "service": "pulsegrid.service",
      "local": "http://127.0.0.1:8080/"
    },
    "logs": {
      "service": "pulsegrid",
      "lines": 120
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

Relationship with vix build

Some projects need database support at build time.

For SQLite support:

bash
vix build --with-sqlite
1

For MySQL support:

bash
vix build --with-mysql
1

For scripts:

bash
vix run main.cpp --with-sqlite
1

or:

bash
vix dev main.cpp --with-sqlite
1

Relationship with vix service

In production, the service should run with the same database path expected by your project.

Before installing or restarting the service:

bash
vix db status
vix db migrate
vix build --preset release --with-sqlite
vix service restart
1
2
3
4

Relationship with vix health

Database problems often appear as app health failures.

If health fails:

bash
vix health local
vix logs app --errors
vix db status
1
2
3

Relationship with vix logs

When migrations fail or the app cannot open the database, inspect logs:

bash
vix logs app --errors
1

If production errors repeat:

bash
vix logs errors --repeated
1

Relationship with vix doctor production

vix doctor production checks broader production readiness.

vix db focuses on database readiness.

Before deployment:

bash
vix db status
vix db backup
vix doctor production
1
2
3

Options

OptionDescription
--jsonPrint supported output as JSON. Currently useful for status.
--verboseShow verbose diagnostic output.
-vAlias for --verbose.
-h, --helpShow help.

Commands reference

CommandDescription
vix dbSame as vix db status.
vix db statusInspect database and storage status.
vix db status --jsonPrint status as JSON.
vix db migrateApply pending file-based SQL migrations.
vix db backupCreate a SQLite backup.
vix db --helpShow help.

Common workflows

Inspect database status

bash
vix db
1

Inspect database status as JSON

bash
vix db status --json
1

Prepare SQLite folders

bash
mkdir -p storage migrations
1

Apply migrations

bash
vix db migrate
1

Create backup before deployment

bash
vix db backup
1

Deploy with SQLite

bash
vix db status
vix db backup
vix build --preset release --with-sqlite
vix service restart
vix health local
1
2
3
4
5
bash
vix health local
vix logs app --errors
vix db status
1
2
3

Common mistakes

Running migrate before creating storage directory

Wrong:

bash
vix db migrate
1

when storage/ does not exist.

Correct:

bash
mkdir -p storage
vix db migrate
1
2

Running migrate before creating migrations directory

Wrong:

bash
vix db migrate
1

when migrations/ does not exist.

Correct:

bash
mkdir -p migrations
vix db migrate
1
2

Running backup before database exists

Wrong:

bash
vix db backup
1

before the database file exists.

Correct:

bash
vix db migrate
vix db backup
1
2

Expecting backup to support MySQL

Current backup support is SQLite-only.

For MySQL, use your database server’s backup tools until Vix adds native MySQL backup support.

Expecting migrate to support MySQL

Current migration support is SQLite-only.

For MySQL, use an external migration workflow until Vix adds native MySQL migration support.

Ignoring WAL and SHM files

If your SQLite database uses WAL mode, sidecar files may exist.

vix db backup copies them when present.

Do not manually copy only the .db file while the database is actively writing unless you understand SQLite backup safety.

Running from the wrong directory

Wrong:

bash
cd ~
vix db status
1
2

Correct:

bash
cd /path/to/myapp
vix db status
1
2

vix db reads vix.json from the current project directory.

Troubleshooting

Unknown database engine

Check:

json
{
  "database": {
    "engine": "sqlite"
  }
}
1
2
3
4
5

Supported parsed values are:

txt
sqlite
mysql
1
2

Any other value is treated as unknown.

Storage directory is missing

Create it:

bash
mkdir -p storage
1

Then run:

bash
vix db status
1

Storage directory is not writable

Check permissions:

bash
ls -ld storage
1

Fix ownership or permissions:

bash
sudo chown -R "$USER":"$USER" storage
1

Then run:

bash
vix db status
1

Database file does not exist yet

This can be normal before the first migration.

Run:

bash
vix db migrate
1

or create the database from your app.

Migrations directory is missing

Create it:

bash
mkdir -p migrations
1

Add .up.sql files, then run:

bash
vix db migrate
1

Migration support is unavailable

If Vix reports:

txt
vix db migrate is not available in this build.
1

rebuild the Vix CLI with the database module enabled.

Migration failed

Inspect the SQL error, then check the migration file.

Run status again:

bash
vix db status
1

If the app is running in production, inspect logs:

bash
vix logs app --errors
1

Backup failed

Check:

bash
vix db status
1

Make sure:

  • engine is SQLite
  • database file exists
  • backups/ can be created
  • current user can read the database file
  • current user can write to the project directory

Best practices

Keep database configuration in vix.json.

Use SQLite for simple local-first and small production apps.

Create storage/ explicitly.

Keep migrations in migrations/.

Use .up.sql migration files.

Run vix db status before migrations.

Run vix db backup before production deployments.

Run vix db status --json in CI when useful.

Use vix build --with-sqlite for apps that need SQLite support.

Use vix logs app --errors when database errors appear in production.

CommandPurpose
vix build --with-sqliteBuild with SQLite support.
vix build --with-mysqlBuild with MySQL support.
vix run --with-sqliteRun a script or app with SQLite support.
vix dev --with-sqliteDevelop with SQLite support.
vix serviceManage the production app service.
vix healthCheck whether the app responds.
vix logsInspect app and production errors.
vix doctor productionInspect production readiness.

Next step

Inspect production logs.

Open the logs guide

Released under the MIT License.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.