ɳSelfɳSELFDOCS

Sync Commands

The nself sync command synchronizes databases, files, and configuration between environments. Enhanced in v0.4.7 with auto-sync and watch mode.

Updated for ɳSelf v0.4.8

Enhanced in v0.4.7: Sync Features

  • - Auto-sync: Configure automatic synchronization service
  • - Watch mode: Continuous synchronization with file watching
  • - Full sync: Sync database, files, and config in one command
  • - Sync history: Track all synchronization operations

Basic Sync Commands

nself sync db

Synchronize database between environments.

nself sync db <environment>

# Examples
nself sync db staging                  # Sync database to staging
nself sync db production               # Sync database to production

nself sync files

Synchronize files/uploads between environments.

nself sync files <environment>

# Examples
nself sync files staging               # Sync files to staging
nself sync files production            # Sync files to production

nself sync config

Synchronize configuration between environments.

nself sync config <environment>

# Examples
nself sync config staging              # Sync config to staging

nself sync full

Full synchronization (database, files, and configuration).

nself sync full <environment>

# Examples
nself sync full staging                # Full sync to staging
nself sync full production             # Full sync to production

Auto-Sync (v0.4.7+)

nself sync auto

Configure automatic synchronization service.

nself sync auto --setup                # Configure auto-sync service
nself sync auto --stop                 # Stop auto-sync service

# Auto-sync runs in the background and keeps
# environments synchronized automatically

Watch Mode (v0.4.7+)

nself sync watch

Continuously sync changes between environments using file watching.

nself sync watch                       # Watch all changes
nself sync watch --path <dir>          # Watch specific path
nself sync watch --interval <seconds>  # Set polling interval

# Examples
nself sync watch --path ./uploads
nself sync watch --interval 30

# Press Ctrl+C to stop watching

Sync Status and History

nself sync status

Check synchronization status.

nself sync status

# Output:
# Sync Status
# ===========
# Environment: staging
# Last Sync: 2026-01-23 10:30:00
#
# Database:
#   Tables synced: 24
#   Rows synced: 15,432
#   Status: up-to-date
#
# Files:
#   Files synced: 1,234
#   Size: 2.3GB
#   Status: 3 files pending
#
# Config:
#   Status: up-to-date

nself sync history

View synchronization history.

nself sync history

# Output:
# Sync History
# ============
# DATE                  TYPE      TARGET   STATUS
# 2026-01-23 10:30:00   database  staging  success
# 2026-01-23 09:15:00   files     staging  success
# 2026-01-22 18:00:00   full      staging  success
# 2026-01-22 14:00:00   config    prod     success

Cross-Environment Migration

For full cross-environment migration, use the nself migrate command:

nself migrate

Migrate schema, data, and configuration between environments.

nself migrate <source> <target> [options]

# Options:
#   --dry-run          Preview migration without changes
#   --schema-only      Migrate only database schema
#   --data-only        Migrate only data (no schema changes)
#   --config-only      Migrate only configuration
#   --force            Skip confirmation prompts
#   --watch            Continuous sync mode

# Examples
nself migrate local staging --dry-run  # Preview migration
nself migrate staging prod             # Migrate staging to production
nself migrate local staging --schema-only  # Schema only

nself migrate diff

Show differences between environments.

nself migrate diff <source> <target>

# Examples
nself migrate diff local staging       # Compare local vs staging
nself migrate diff staging prod        # Compare staging vs production

nself migrate sync

Keep environments continuously in sync.

nself migrate sync <source> <target>
nself migrate sync staging prod --watch  # Continuous sync

# Press Ctrl+C to stop

nself migrate rollback

Rollback the last migration.

nself migrate rollback                 # Undo last migration

Migration Process

When running a migration, ɳSelf follows this process:

  1. Validation - Source and target environments are validated
  2. Safety Check - Production migrations require confirmation
  3. Backup - Target environment is backed up automatically
  4. Checkpoint - Migration checkpoint is saved for rollback
  5. Migration - Schema, data, and/or config are migrated
  6. Verification - Migration is verified

Components

Migrations can include:

ComponentDescriptionFlag
SchemaDatabase tables, indexes, constraints--schema-only
DataDatabase records--data-only
ConfigEnvironment variables, service settings--config-only

Environments

EnvironmentAliasDescription
localdevLocal development environment
staging-Staging environment
prodproductionProduction environment

Production Safety

When migrating to production:

  • Confirmation is required (type 'yes')
  • Use --force to skip confirmation (CI/CD use)
  • Automatic backup is created before migration
  • Consider --dry-run first
# Safe production migration workflow
nself migrate staging prod --dry-run   # Preview
nself migrate staging prod             # Execute with confirmation

Checkpoints

Each migration creates a checkpoint in .ɳSelf/migrations/. Checkpoints allow you to rollback if needed.

# View checkpoints
ls .ɳSelf/migrations/

# Rollback using checkpoint
nself migrate rollback

Configuration Files

Migration uses these configuration sources:

EnvironmentConfig Files
local.env, .env.local, .env.dev
staging.env.staging, .environments/staging/server.json
production.env.prod, .environments/prod/server.json

Sync Workflows

Development Workflow

# Pull latest staging data to local
nself sync db staging

# Work locally...

# Push changes back
nself migrate local staging

Staging Reset Workflow

# Reset staging with fresh data
nself sync full staging

# Verify
nself sync status

Continuous Sync Workflow

# Start watching for changes
nself sync watch --path ./uploads

# Or use auto-sync
nself sync auto --setup

Options Reference

OptionDescription
--dry-runPreview without making changes
--schema-onlyMigrate only database schema
--data-onlyMigrate only data
--config-onlyMigrate only configuration
--forceSkip confirmation prompts
--watchContinuous sync mode
--jsonOutput in JSON format

Next Steps

  • Database Commands - Database management
  • Deployment Commands - Deployment workflows
  • Environment Commands - Environment management