byjg/migration-cli 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

byjg/migration-cli

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

byjg/migration-cli 适用场景与选型建议

byjg/migration-cli 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 26.22k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2018 年 12 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 byjg/migration-cli 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 byjg/migration-cli 我们能提供哪些服务?
定制开发 / 二次开发

基于 byjg/migration-cli 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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