Synopsis
Description
Executes database schema migrations on the PostgreSQL metadata database. This command requires the--config parameter to be set, which should point to a configuration file containing the metadata database connection details.
Migrations are applied automatically and cannot be rolled back through this command. The command runs to completion and exits (unlike other ampd subcommands that run continuously).
Key Concepts
Metadata Database
Metadata Database
PostgreSQL database storing job state, worker registrations, dataset definitions, and table revisions. Required for all ampd operational modes.
Schema Migration
Schema Migration
Automatic application of pending DDL changes to bring the database schema up to date with the current ampd version.
One-Shot Command
One-Shot Command
Unlike other ampd subcommands,
migrate runs to completion and exits. It does not run continuously.Configuration
The command requires a valid metadata database URL in the configuration file:Configuration Fields
PostgreSQL connection string for the metadata database.Can also be set via the
AMP_CONFIG_METADATA_DB__URL environment variable.Environment Override
When to Run Migrations
Examples
Basic Usage
Using Environment Variable
Remote Database
CI/CD Pipeline Example
Auto-Migration Alternative
In non-production environments, you can enable automatic migrations on service startup:auto_migrate = true, services automatically apply migrations on startup, making the explicit migrate command unnecessary.
Solo mode defaults: In solo mode,
auto_migrate defaults to true for convenience.When to Use Auto-Migration
Use Auto-Migration For
Use Auto-Migration For
- Local development with solo mode
- Testing environments
- CI/CD ephemeral databases
- Quick prototyping
Do NOT Use Auto-Migration For
Do NOT Use Auto-Migration For
- Production deployments (explicit control preferred)
- Shared staging environments
- Long-running production databases
- Scenarios requiring migration approval
Migration Safety
Idempotent Operations
Migrations are idempotent - runningmigrate multiple times is safe:
Version Tracking
The metadata database tracks which migrations have been applied. This information is stored in the schema migrations table.Rollback
Migrations cannot be rolled back through themigrate command. If you need to revert schema changes:
- Restore from a database backup
- Or manually reverse the schema changes using SQL
Troubleshooting
Connection Failed
Permission Denied
Migration Conflict
- Restore the original migration files
- Or reset the database and re-run all migrations
Exit Codes
Migrations completed successfully
Error occurred during migration or configuration is invalid
See Also
- ampd overview - Command overview and global options
- ampd solo - Solo mode with auto-migration enabled