| sidebar_position | 1 |
|---|
This is a simple library written in PHP for database version control. Currently supports SQLite, MySQL, SQL Server and PostgreSQL.
:::info CLI vs PHP API
This package (byjg/migration-cli) is the command line interface for database migrations. While it requires PHP to run, your project doesn't need to be written in PHP. You can use this CLI tool with any programming language or framework.
If you need to integrate migrations programmatically into your PHP code (for automated testing, custom workflows, etc.), use the core library instead: byjg/migration :::
Install via Composer:
composer require 'byjg/migration-cli'Database Migration can be used as:
- Command Line Interface (this package) - Run migrations from the terminal with any technology stack
- PHP Library (byjg/migration) - Integrate migrations directly in your PHP code
- CI/CD Integration - Independent of your programming language or framework
The basic usage is:
vendor/bin/migrate <COMMAND> --path=<scripts> uri://connectionThe connection string is a URI that represents the database connection. Examples:
- SQLite:
sqlite:///path/to/my.db - MySQL:
mysql://user:password@server/database - PostgreSQL:
pgsql://user:password@server/database - SQL Server:
dblib://user:password@server/database
For more information about connection strings, see the anydataset-db documentation.
You can configure the migration tool using environment variables:
Defines the database connection string. This allows you to omit the connection parameter from commands.
export MIGRATE_CONNECTION=sqlite:///path/to/my.dbSpecifies where the base.sql and migration scripts are located. Defaults to the current directory.
export MIGRATE_PATH=/path/to/migrate_filesDefines the name of the migration version table. Defaults to migration_version.
export MIGRATE_TABLE=my_migration_versionDisables the reset command to prevent accidental data loss in production environments.
export MIGRATE_DISABLE_RESET=trueYou can also define these variables in a .env file in your project root:
MIGRATE_CONNECTION=sqlite:///path/to/my.db
MIGRATE_PATH=/path/to/migrate_files
MIGRATE_TABLE=migration_version
MIGRATE_DISABLE_RESET=falseThe package will automatically discover and load these variables.