定制 byjg/migration-cli 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

byjg/migration-cli

最新稳定版本:5.0.1

Composer 安装命令:

composer require byjg/migration-cli

包简介

Simple library in PHP for database version control. Supports Sqlite, MySql, Sql Server and Postgres.

README 文档

README

Build Status Opensource ByJG GitHub source GitHub license GitHub release

This is a simple library written in PHP for database version control. Currently supports SQLite, MySQL, SQL Server and PostgreSQL.

Database Migration can be used as:

  • Command Line Interface
  • PHP Library to be integrated in your functional tests
  • Integrated in your CI/CD independent of your programming language or framework

Important Note

This package is the command line interface of ByJG PHP Migration.

Key Points:

  • This CLI tool requires PHP to run, but your project doesn't need to be written in PHP
  • You can use this tool with any programming language or framework
  • Perfect for CI/CD pipelines and database versioning independent of your stack

For PHP API Integration: If you want to integrate migrations directly into your PHP code (e.g., for automated testing or programmatic control), use the core migration library instead:

For complete information about the migration system, architecture, and advanced usage, visit the core project documentation: https://github.com/byjg/migration

Installing

composer require 'byjg/migration-cli'

Documentation

Quick Start

The basic usage is:

vendor/bin/migrate <COMMAND> --path=<scripts> uri://connection

Connection String 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

Using Environment Variables:

export MIGRATE_CONNECTION=sqlite:///path/to/my.db
export MIGRATE_PATH=/path/to/migrate_files
vendor/bin/migrate update

Or use a .env file:

MIGRATE_CONNECTION=sqlite:///path/to/my.db
MIGRATE_PATH=/path/to/migrate_files

Available Commands

The migration tool provides the following commands:

Command Description
create Create the directory structure for migrations
install Install or upgrade the migration version table in an existing database
version Get the current database version
update Intelligently migrate up or down based on current version
up Migrate up to a newer version
down Migrate down to an older version
reset Create a fresh database from base.sql and apply all migrations

Command Options

All commands (except create) support these options:

  • --path, -p: Define the path where base.sql and migration scripts are located
  • --up-to, -u: Specify a target version for migration
  • --no-base: Skip checking for base.sql file
  • -v, -vv, -vvv: Increase verbosity level

Quick Examples

# Create migration structure
vendor/bin/migrate create /path/to/migrations

# Install version control in existing database
vendor/bin/migrate install mysql://user:pass@localhost/myapp

# Check current version
vendor/bin/migrate version mysql://user:pass@localhost/myapp

# Update to latest version
vendor/bin/migrate update mysql://user:pass@localhost/myapp

# Update to specific version
vendor/bin/migrate update --up-to=10 mysql://user:pass@localhost/myapp

# Reset database (WARNING: destructive!)
vendor/bin/migrate reset --yes mysql://user:pass@localhost/myapp

Environment Variables

Variable Description Default
MIGRATE_CONNECTION Database connection string -
MIGRATE_PATH Path to migration files Current directory
MIGRATE_TABLE Name of the migration version table migration_version
MIGRATE_DISABLE_RESET Disable the reset command false

Related Projects

Dependencies

flowchart TD
    byjg/migration-cli --> byjg/migration
    byjg/migration-cli --> symfony/console
    byjg/migration-cli --> vlucas/phpdotenv
Loading

Open source ByJG

统计信息

  • 总下载量: 23.76k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 10
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-12-15