python 3.5的迁移工具+

mongrations的Python项目详细描述


混合

alt text python 3.6+的迁移工具。Mongurations最初是作为MongoDB迁移工具启动的,但引入了MySQL&Postgres 作为Mongurations工具的兼容服务器。

入门

一。生成迁移文件

mongrations -C true --name insert-into-members

2.生成的迁移文件(import和类定义的内容是 为迁移文件自动生成-up()和down()的内容由用户定义

frommongrationsimportMongrations,Databasefrompydotenvimportload_envload_env()# This is a MongoDB example. Go to /examples directory# for more examplesclassMongration(Database):def__init__(self):super(Database,self).__init__()defup(self):collection=self.db['members']data={'accountId':1,'username':'admin','email':'admin@able.digital','firstName':'Site','lastName':'Owner'}collection.insert_one(data)defdown(self):collection=self.db['members']collection.delete_one({'username':'admin'})Mongrations(Mongration,'sync')

三。运行迁移

mongrations -M true

安装

pip install --upgrade mongrations

或在本地安装

python setup.py build
sudo python setup.py install

使用

mongurations提供了一个cli工具以及一个pythonic迁移方法的类。pymongo、pymysql和psycopg2用于 引擎盖,跟着PyMongoPyMySQLPsycopg2的文档 有关如何创建迁移的说明。对于此应用程序中使用的环境变量工具,请执行以下操作 this repo(它也与此软件包一起安装)。

有关详细信息,请参阅mongurationsdocumentation

cli

Usage: mongrations [OPTIONS]

Options:
  -M, --migrate BOOLEAN  Run migrations
  -C, --create BOOLEAN   Create new migration
  -N, --name TEXT        Name for newly created migration
  -F, --file_path TEXT   File path for newly created migration
  -U, --undo BOOLEAN     Undo last migration
  -D, --down BOOLEAN     Revert database
  --version              Show the version and exit.
  --help                 Show this message and exit.

cli示例

mongrations -C true --name [migration_name]# create new migration
mongrations -M true# run migrations
mongrations -D true# tear down migrations
mongrations -U true# undo last migration

mongurations类

frommongrationsimportMongrationsClimigrations=MongrationsCli()migrations.create(directory='migrations',name='file_name')migrations.migrate()migrations.down()migrations.undo()

在examples/folder中运行示例迁移

问题

请将所有问题报告给回购。

注释

您可以通过setup.py develop build从源代码安装psycopg2,也可以参考它们的repo。

下一个

单元测试。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java多项式逆算法   特定于java的ID不接受RestFB for Facebook中的我的访问令牌   单线程java中的多线程多可运行   java为什么即使在添加setJMenubar()方法后,Jmenubar在我的Jframe中也不可见?   当字段为LOB时,java无法从字符串转换为Long类型   java内存与同步互斥不一致   如何在Java中以位级精度读写文件   rest如何在java中对jersey客户端使用SSL客户端证书   在安卓 emulator中访问google api时发生java运行时错误   在Java中,如何确定一个日期是否介于两个日期之间?   运行简单spring应用程序时出现java错误   运行java jar和java cp时,spring boot没有主清单属性错误