Skip to content

CLI Commands

Complete reference for all Astroladb (alab) CLI commands.


Initialize a new project. Creates schemas/, migrations/, and types/ directories along with an alab.yaml config file.

Terminal window
alab init

Use --demo to scaffold a sample schema:

Terminal window
alab init --demo

Create a new table schema file. Takes a namespace and table name.

Terminal window
alab table auth user

This creates schemas/auth/user.js.

Start a local server for live API documentation. Useful for browsing your schema interactively.

Terminal window
alab live

Export the schema in a given format.

Terminal window
alab export -f openapi
alab export -f graphql
alab export -f typescript
alab export -f python
alab export -f go
alab export -f rust
# Include relationship fields (WithRelations variants)
alab export -f typescript --relations
FlagDescription
-fRequired. Format: openapi, graphql, typescript, go, python, rust
--relationsGenerate WithRelations type variants with relationship fields
--namespaceFilter export to a specific namespace

Generate a migration from the current schema diff. The argument is a descriptive name for the migration.

Terminal window
alab new create_users

Apply all pending migrations.

Terminal window
alab migrate

Preview the SQL without applying (shows phase-by-phase execution plan with estimates):

Terminal window
alab migrate --dry

Dry-run output includes:

  • Phase-by-phase SQL (DDL → Index → Data)
  • Row count estimates for affected tables
  • Time estimates for each phase
  • Total migration time estimate

Apply and auto-commit to git:

Terminal window
alab migrate --commit

Verify SQL checksums before applying:

Terminal window
alab migrate --verify-sql
FlagDescription
--dryShow phase-by-phase SQL with row/time estimates (no execution)
--forceSkip safety warnings and confirmation prompts
--confirm-destroyConfirm DROP operations
--commitAuto-commit migration files to git after apply
--skip-lockSkip distributed locking (use in CI)
--lock-timeoutLock acquisition timeout (default 30s)
--verify-sqlVerify SQL checksums against stored values first

Roll back the most recent migration. Pass a number to roll back multiple steps.

Terminal window
alab rollback
alab rollback 3

Validate schema files or lint migration files for safety issues.

Terminal window
# Validate all schema files
alab check
# Lint migration files for destructive operations, missing defaults, etc.
alab check --migrations
# Verify SQL determinism for applied migrations
alab check --determinism
FlagDescription
--migrationsLint migration files instead of validating schemas
--determinismRe-generate SQL for applied migrations and compare checksums

Loads all schema files through the sandbox and runs structural validation — missing primary keys, invalid column types, broken references, duplicate definitions, etc. Exits with code 1 on any error.

Scans migration operations and warns about:

RuleTriggerMessage
Drop tablem.drop_table()Will DELETE ALL DATA in table
Drop columnm.drop_column()Will DELETE DATA in column
NOT NULL without defaultm.add_column() with a NOT NULL column that has no default(), backfill(), or server_default()NOT NULL column has no default or backfill value
Reserved SQL wordTable or column name matches a SQL reserved word (user, order, type, select, etc.)Identifier is a SQL reserved word
Lock file integrityalab.lock checksum mismatchLock file is out of date or tampered

Exits with code 1 if any warnings are found. Use --force on alab migrate to proceed despite warnings.

Re-parses each applied migration, re-generates its SQL, and compares the SHA-256 hash against the sql_checksum stored in alab_migrations at apply time. Reports any migration that would produce different DDL today than it did when originally applied — catches non-deterministic migrations (e.g. those using Date.now() or environment-dependent logic).

Collapse all migrations into a single baseline migration. Useful after accumulating many migrations over time.

Terminal window
# Preview what would be squashed
alab squash --dry-run
# Squash all migrations into a baseline
alab squash

Old migration files are archived to .alab/archive/. Existing environments skip the baseline automatically; new environments apply only the baseline.


Show the schema at a specific migration revision.

Terminal window
alab schema

Show schema state, migration history, verification, and drift detection in a TUI.

Terminal window
alab status

Regenerate TypeScript definitions used for IDE autocompletion inside schema files.

Terminal window
alab types

Manage the migration lock file (alab.lock).

Terminal window
# Show lock status
alab lock status
# Verify lock file integrity
alab lock verify
# Regenerate lock file from migration files
alab lock repair
# Force-release a stuck migration lock
alab lock release --force

Run a generator file and write the output to a directory.

Terminal window
alab gen run generators/fastapi -o ./generated

The .js extension is optional.

FlagDescription
-o, --outputRequired. Output directory.

Download a shared generator from a URL into generators/.

Terminal window
alab gen add https://raw.githubusercontent.com/hlop3z/astroladb/main/examples/generators/generators/fastapi.js

See Code Generators for the full generator API and sandbox reference.