Skip to content

CLI ​

The asc db sync command compares your .as definitions against the live database and applies changes. It is part of the @atscript/typescript CLI.

Basic Usage ​

bash
npx asc db sync

This will:

  1. Compile your .as files
  2. Connect to the database using your config
  3. Show a detailed plan of what will change
  4. Ask for confirmation before applying destructive changes
  5. Apply changes and show the result

If the schema hash is unchanged since the last sync, the command exits after a quick hash comparison — no schema introspection, no DDL, no locking.

Flags ​

FlagDescription
--dry-runShow the plan without applying any changes
--yesSkip the confirmation prompt (CI mode)
--forceRe-sync even if the schema hash matches
--safeSkip destructive operations (column drops, table drops, type changes)
-c, --configPath to atscript.config.mts (auto-resolved if omitted)

--dry-run ​

Shows exactly what would change without touching the database. Use this to preview changes before applying:

bash
npx asc db sync --dry-run

--yes ​

Skips the interactive confirmation prompt. Non-destructive changes are always applied without prompting; --yes extends this to destructive changes as well:

bash
npx asc db sync --yes

--force ​

Bypasses the hash-based change detection. The command will introspect the database and diff against your .as definitions regardless of whether the stored hash matches:

bash
npx asc db sync --force

--safe ​

Suppresses all destructive operations (column drops, table drops, type changes requiring recreation). Only additive changes are applied. See Safe Mode for details.

bash
npx asc db sync --safe

Output Format ​

The CLI displays a structured plan grouped by tables and views. Each entry shows a status indicator:

SymbolColorMeaning
+GreenNew table/column/FK will be created
~CyanExisting table will be modified
-RedTable/column/FK will be dropped
!RedType change or destructive operation
✓GreenAlready in sync
✗RedError (rename conflict, missing sync method)

Example output ​

Tables:
  + users — create
      + id (number) PK — add
      + name (string) — add
      + email (string) — add

  ~ posts — alter
      + published_at (number) — add
      ~ title_text → title — rename
      - old_column — drop

  ✓ comments — in sync

Views:
  + active_users — create
  ✓ [V] user_stats — in sync

After applying changes, the result summary shows what was actually done:

Schema synced successfully. Hash: a1b2c3d4

Tables:
  + users — created
      + id — added
      + name — added
      + email — added

  ~ posts — altered
      + published_at — added
      ~ title_text — renamed
      - old_column — dropped

Examples ​

Preview changes without applying:

bash
npx asc db sync --dry-run

Auto-approve for CI/CD pipelines:

bash
npx asc db sync --yes

Safe mode — only additive changes:

bash
npx asc db sync --safe

Force a full re-sync, ignoring the stored hash:

bash
npx asc db sync --force

Use a specific config file:

bash
npx asc db sync -c ./config/atscript.config.mts

Combine flags for CI with safe mode:

bash
npx asc db sync --yes --safe

Error Handling ​

The CLI exits with a non-zero code when:

  • No db config — the atscript.config.mts has no db field
  • Schema errors — rename conflicts, type changes without @db.sync.method, or external view validation failures
  • Adapter not found — the specified adapter package is not installed

When errors are detected in the plan, the CLI prints the errors and exits without applying any changes.

Exit Codes ​

CodeMeaning
0Success — sync completed, was up-to-date, or --dry-run printed
Non-0Schema errors, connection failure, missing config, or user abort

asc exposes --help and --version from the underlying @atscript/typescript CLI; both exit with 0.

Next Steps ​

Released under the MIT License.