Laizy CMS
CLI

laizy sync

Sync your local schema with the database — preview changes, review migration plans, and apply updates safely.

laizy sync

The sync command compares your local .laizy schema file against the current database state and applies the necessary changes. It shows a migration plan with impact analysis before executing, giving you full visibility into what will change.

Usage

pnpm laizy sync              # Interactive sync with confirmations
pnpm laizy sync --dry-run    # Preview changes without applying
pnpm laizy sync --force      # Skip confirmation prompts

Flags

FlagDescription
--dry-runShow the migration plan without executing any changes
--forceSkip all confirmation prompts (useful for CI/CD)

How It Works

When you run laizy sync, the command:

  1. Reads your local schema from the path configured in ~/.laizyrc (default: laizy/schema.laizy)
  2. Fetches the current remote schema from the Laizy API for your linked project
  3. Computes a diff identifying models to create, update, or delete
  4. Generates a migration plan with impact classifications (safe, warning, destructive)
  5. Enriches with content impact showing how many entries are affected per model
  6. Asks for confirmation if the plan contains warning or destructive changes
  7. Executes the migration and shows updated model status

Example Output

No changes needed

Laizy CMS Schema Sync

Found schema file: ./laizy/schema.laizy
Parsed 3 models
Analysis complete

Schema is already up to date!

Creating new models

Laizy CMS Schema Sync

Found schema file: ./laizy/schema.laizy
Parsed 3 models
Analysis complete

Migration Plan:

  Operation       Model          Impact    Description
  ────────────    ────────       ──────    ───────────
  create_model    BlogPost       safe      Create new content model "BlogPost" with 4 fields (no existing content)
  create_model    Author         safe      Create new content model "Author" with 3 fields (no existing content)

Executing migration...
Migration completed successfully

Updated Models:

  Model       Fields    Entries    Last Updated
  ────────    ──────    ───────    ────────────
  BlogPost    4         0          just now
  Author      3         0          just now

Destructive changes

When the plan includes destructive changes, the CLI shows explicit warnings:

Migration Plan:

  Operation       Model       Impact         Description
  ────────────    ────────    ──────         ───────────
  update_model    BlogPost    warning        Update model "BlogPost" (1 field changes) (15 entries affected)
  delete_model    OldPage     destructive    Delete content model "OldPage" and all associated content (3 entries affected)

DESTRUCTIVE: Deleting model "OldPage" will permanently remove all content data (3 content entries will be affected)

? Are you absolutely sure you want to continue? This cannot be undone. (y/N)

Dry Run Mode

Use --dry-run to preview the migration plan without making changes:

pnpm laizy sync --dry-run

This runs the full analysis pipeline -- parsing, diffing, planning, and content impact analysis -- but stops before execution. Use this to review changes before committing to them.

Migration Plan:

  Operation       Model          Impact    Description
  ────────────    ────────       ──────    ───────────
  create_model    Product        safe      Create new content model "Product" with 4 fields

Dry run complete - no changes made

Always run --dry-run before applying schema changes in production. It is the safest way to verify that your schema modifications will produce the expected migration plan.

Force Mode

Use --force to skip all confirmation prompts:

pnpm laizy sync --force

This is designed for CI/CD pipelines and automated scripts where interactive prompts are not possible. The migration executes immediately regardless of impact level.

The --force flag bypasses all safety confirmations, including for destructive changes that permanently delete data. Only use this when you have already reviewed the migration plan via --dry-run.

Project Context

The sync command requires a linked project. It reads the project ID from .laizy/project.json, which is created by laizy init or laizy link.

If no project is linked, the command will fail with:

Error: No project linked to this directory
Run laizy link to connect to a project

Post-Sync Status

After a successful migration, the CLI displays updated model status:

Updated Models:

  Model       Fields    Entries    Last Updated
  ────────    ──────    ───────    ────────────
  BlogPost    4         15         just now
  Author      3         8          just now
  Product     5         0          just now

View in dashboard: https://laizycms.com/dashboard/content-model

Error Handling

Schema parsing errors

If your schema file has syntax errors, the CLI reports them with line numbers:

Schema parsing failed
Error: Line 5: Expected ":" after field name

Authentication errors

If your API token is invalid or expired:

Analysis failed
Error: unauthorized

This might be an authentication issue.
Try running laizy init to update your credentials.

Migration execution errors

If a migration operation fails, the CLI reports the error and exits with a non-zero status code. Operations that completed before the failure are not rolled back.

Next Steps

After syncing your schema:

  1. Generate the client: Run pnpm laizy generate to create a TypeScript client
  2. Create content: Use pnpm laizy content create to add entries
  3. Check status: Run pnpm laizy status to see your current schema state

On this page