python中用于迁移的通用工具。
link-migration的Python项目详细描述
链路迁移
用于架构和数据迁移的通用工具。
这个库的主要灵感来自alembic、django和hibernate/liquibase。最终目标是允许将轻量级迁移框架部署到任何技术堆栈中。目前,这在很大程度上依赖于用户来实现,但是随着时间的推移,越来越多的集成将添加到默认集。
版本
0.0.12
安装
如果您的系统上有PIP,只需键入:
pip install link-migration
如果您已经有旧版本的链接迁移,并且要升级,请使用:
pip install --upgrade link-migration
使用说明
首先需要定义conf.py文件并指定其位置:link_migration -c "path_to_file/conf.py"
下面是conf.py中定义的最低要求。这里的重要步骤是指定迁移文件夹存在的地方,以便检测它们,并指定在哪里存储和获取执行迁移的版本。
import os
import requests
import json
ROOT_DIR = 'link_migration.example_migrations'
MIGRATIONS_ABS_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__)))
MIGRATIONS_DIR = 'link_migration.example_migrations'
def get_current_version():
path = "%s/current_version.txt" % MIGRATIONS_ABS_PATH
with open(path, "r+") as f:
content = f.read()
return int(content)
def set_current_version(version):
path = "%s/current_version.txt" % MIGRATIONS_ABS_PATH
with open(path, "w") as f:
content = f.write(f'{version}')
return int(content)
链接迁移使用version信息跟踪迁移架构并 决定脚本的执行顺序。链接迁移将经历所有.py 目录中的文件并执行所有这些文件的version顺序。
迁移到特定版本
如果需要,可以通过以下方式将数据库架构迁移到特定版本 通知--to(或-t)参数。迁移的属性version 文件将用作唯一标识符:
$ link-migration --to=57
如果不指定任何版本,使用--up或--down,则链接迁移将迁移 迁移目录中可用的最新版本的架构 在配置文件中指定。