https://github.com/imiphp/imi-migration
imi 框架的数据库迁移组件
https://github.com/imiphp/imi-migration
Last synced: about 1 year ago
JSON representation
imi 框架的数据库迁移组件
- Host: GitHub
- URL: https://github.com/imiphp/imi-migration
- Owner: imiphp
- License: gpl-2.0
- Created: 2022-09-22T08:11:37.000Z (over 3 years ago)
- Default Branch: 2.1
- Last Pushed: 2023-07-03T00:54:26.000Z (almost 3 years ago)
- Last Synced: 2024-05-23T01:33:09.594Z (about 2 years ago)
- Language: PHP
- Homepage:
- Size: 39.1 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# imi-migration
[](https://packagist.org/packages/imiphp/imi-migration)
[](https://secure.php.net/)
[](https://github.com/swoole/swoole-src)
[](https://github.com/imiphp/imi-migration/blob/master/LICENSE)
## 介绍
此项目是 imi 框架的数据库迁移组件。
> 正在测试阶段,使用时请先确认 SQL 无误后再执行,本项目不对删库删数据负责。
## 安装
`composer require imiphp/imi-migration:~2.1.0`
## 使用说明
### 模型同步到表结构
#### 同步表结构
将数据库中的数据表结构升级为模型中定义的结构。
```shell
vendor/bin/imi-swoole migration/patch -f
```
#### 生成同步结构 SQL 语句
**输出到命令行:**
```shell
vendor/bin/imi-swoole migration/patch
```
**保存到文件:**
```shell
vendor/bin/imi-swoole migration/patch -f "文件名"
```
### 数据库迁移
#### 配置
`@app.beans`:
```php
[
\Imi\Migration\Service\MigrationService::class => [
'handler' => \Imi\Migration\Handler\FileMigrationHandler::class, // 迁移处理器
'onGenerateModel' => true, // 是否在生成模型时自动生成迁移文件
],
]
```
> 上述配置是默认配置,不配置时自动启用。
#### 目录
`.migration` 是存放数据库迁移文件和版本信息的目录,请勿将 `.migration/version` 提交到版本控制系统。
#### 执行数据库迁移
**执行前询问:**
```shell
vendor/bin/imi-swoole migration/migrate
```
**强制执行:**
```shell
vendor/bin/imi-swoole migration/migrate -f
```
> 请谨慎操作
### 执行数据库回滚
**执行前询问:**
```shell
vendor/bin/imi-swoole migration/rollback
```
**强制执行:**
```shell
vendor/bin/imi-swoole migration/rollback -f
```
> 请谨慎操作
### 通用参数
#### 指定连接池
```shell
vendor/bin/imi-swoole migration/命令 --poolName "连接池名"
```
> 不指定时使用默认连接池
#### 指定连接参数
```shell
vendor/bin/imi-swoole migration/命令 --driver "PdoMysqlDriver" --options "host=127.0.0.1&port=3306&username=root&password=root"
```
## 免费技术支持
QQ群:17916227 [](https://jq.qq.com/?_wv=1027&k=5wXf4Zq),如有问题会有人解答和修复。
## 运行环境
* [PHP](https://php.net/) >= 7.4
* [Composer](https://getcomposer.org/) >= 2.0
* [Swoole](https://www.swoole.com/) >= 4.8.0
* [imi](https://www.imiphp.com/) >= 2.1
## 版权信息
`imi-migration` 依赖 [phpmyadmin/sql-parser](https://github.com/phpmyadmin/sql-parser),所以开源协议受到污染,必须是 GPL-2.0,所有基于本项目的代码都要开源。
建议仅将此组件作为独立工具安装使用,不要在项目中调用此项目中的任意代码,这样就不受开源协议污染了!
## 捐赠

开源不求盈利,多少都是心意,生活不易,随缘随缘……