承接 zimzat/db-changeset-manager 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

zimzat/db-changeset-manager

Composer 安装命令:

composer require zimzat/db-changeset-manager

包简介

Automate the process of applying SQL files (changesets) to databases of different environments or users.

README 文档

README

Automate the process of applying SQL files (changesets) to databases of different environments or users.

Create versioned directories where developers can drop SQL files to be applied to other environments through the release process and back to other developers to ensure that everyone stays synced with database changes. This project doesn't try to force specific syntax, verbose declarations, or provide automated conflict resolution or detection; just a simple process of applying changes between environments.

A typical changeset directory would look something like this:

changesets
├── v1.0
│   ├── 20150102_create-user.sql
│   └── 20150103_track-user-actions.sql
├── v1.1
│   └── 20150103_track-user-action-date.sql
├── v1.3
│   ├── 2015-01-15_create-user-profile.sql
│   ├── 2015-01-16_blogs.sql
│   └── 2015-01-17_user-roles.sql
├── v1.3.1
│   └── 2015-01-20_add-user-roles.sql
└── v1.5
    ├── 2015-01-15_long-awaited-feature.sql
    ├── 2015-02-01_index-blogs.sql
    ├── 2015-02-03_add-reporting.sql
    └── 2015-02-10_blog-tags.sql

Changes are applied to the database in order of version number and then sorted numerically by file name, thus upgrading from 1.0 to 1.3 would apply 'track-user-actions' before 'track-user-action-date' even though they're the same date prefix.

By default directories should be prefixed with 'v' however this can be changed or eliminated by specifying the versionPrefix in the db.ini. The versioning scheme should otherwise follow the standard set out by version_compare().

Files must be suffixed with .sql and must be uniquely named between all versions but otherwise can be named anything. A natural sort (2 before 10) is done to the list of files before being applied to the database.

Restrictions

  • No SELECT statements.
  • No CREATE DATABASE, DROP DATABASE, or USE DATABASE statements.

Requirements

  • PDO
  • MySQL

Install

The supported method to install the utility is through Composer.

composer install zimzat/db-changeset-manager

Command Line Usage

Once installed a php shell file can be used to apply changes from the command line.

ln -s ./vendor/bin/dbChangeManager.php .
./dbChangeManager.php

The command line tool expects a configuration file to be defined specifying the access name and permissions.

host = localhost
dbname = test
username = root
; password = secret
changesetPath = changesets
; versionPrefix = v

The available commands, which can also be seen by running the command without any options, are:

./bin/dbChangeManager.php -h
./bin/dbChangeManager.php -s [-c db.ini]
./bin/dbChangeManager.php -t <version> [-a | -n | -i | -o <file>] [-c db.ini]

Specify an action:
  -h           Display this help message.
  -s           Display the current version of the database
  -t version   Specify new version to target upgrade to

Set a run mode:
  -a           Apply: Execute all changesets and tracking against the database immediately
  -n           No Op: Run as normal but perform no modifying operations against the database.
  -i           Interactive: Provide interactive confirmation prompts before applying changes.
  -o file      File: Output all SQL commands to a file which can be run separately.

Other options:
  -c file      Specify the db config file to use, defaults to db.ini

PHP Usage

The utility can also be invoked directly from a PHP script by instantiating the \DbVcs\ChangeManager object with its dependencies.

$changeManager = new \DbVcs\ChangeManager(
	'changesets',
	new \PDO(
		'mysql:host=localhost;dbname=test',
		'root',
		null, [
			\PDO::ATTR_EMULATE_PREPARES => false,
			\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
		]
	),
	new \DbVcs\Processor\NoOp(),
	new \DbVcs\Output()
);

Note: The \DbVcs\Output class should be extended to send results where and how desired (log file, browser, database, etc).

zimzat/db-changeset-manager 适用场景与选型建议

zimzat/db-changeset-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 91 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 04 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 zimzat/db-changeset-manager 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 91
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-18