# mig-way **Repository Path**: towardly/mig-way ## Basic Information - **Project Name**: mig-way - **Description**: 基于 Python3 编写的数据库迁移工具 - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-04-26 - **Last Updated**: 2024-06-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # mig-way --- `mysql` 数据库迁移工具。 ## 配置 工具支持通过两种形式的配置, 一种是环境变量配置 `.env`、一种是配置文件 `config.ini` ### `.env` ```shell # 数据库连接地址, 也可以通过 MYSQL_HOST,MYSQL_PORT,MYSQL_USER,MYSQL_PASSWORD,MYSQL_DB MYSQL_URL=mysql://x:x@x:6002/x # 是否启用迁移, 默认为: True MIG_WAY_ENABLED=True # 迁移文件目录, 默认为: migrations MIG_WAY_LOCATION=migrations # 初始忽略的版本,只会迁移比此版本大的版本 MIG_WAY_BASE_LINE=20230315231601 # 迁移记录历史表, 默认为: (项目目录).replace('-', '_').lower()_migway_schema_history MIG_WAY_TABLE= ``` ### `config.ini` ``` ; mysql 配置 [mysql] url=mysql://chatgpt:ajyRDS5CK7dHacN2@47.108.162.98:6002/chatgpt [mig_way] enabled=True location=migrations base_line= table= ``` > mysql 连接配置, 除了可以使用 `url` 配置外, 也可以通过 `user`、`password`、`db`、`host` 配置; 例如: 如果是在 `.env` 中可以通过 `MYSQL_HOST,MYSQL_PORT,MYSQL_USER,MYSQL_PASSWORD,MYSQL_DB` 配置; 如果是在 `config.ini` 中则可以通过 `[mysql] user=x` 等的形式配置 配置项说明: 1. `MYSQL_URL`: 数据库连接地址 2. `MIG_WAY_ENABLED`: 是否启用 `Mysql` 版本迁移, 默认为: `True` 3. `MIG_WAY_LOCATION`: 迁移文件目录, 默认为: `migrations` 4. `MIG_WAY_BASE_LINE`: 初始忽略的版本,初始只会迁移比此版本大的版本 5. `MIG_WAY_TABLE`: 迁移记录历史表的名称, 默认: 项目目录; 最终的表名为: `配置名称.replace('-', '_').lower()_migway_schema_history` ## 运行 ### 执行数据库迁移: `./run.sh migration` 实际执行的是: `python mig_way.py` ### 更新代码: `./run.sh pull` 实际执行的是: `git pull origin master:master` ### 部署: `./run.sh` 实际就是先执行更新代码, 再执行数据库迁移 ```shell # 1. 更新代码 git pull origin master:master # 2. 数据库迁移 python mig_way.py ```