peewee的简单迁移引擎

peewee-migrate-dev的Python项目详细描述


peewee migrate–一个简单的peewee迁移引擎

Build StatusCoveralsVersion

Requirements

  • Python2.7,3.5
  • Peewee=3.3.1

Dependency Note

对于Peewee<3.0,请使用Peewee-Migrate==0.14.0

Installation

peewee migrate应使用pip:

安装
pip install peewee_migrate

Usage

是否要Flask集成?看看Flask-PW

From shell

获取帮助:

$ pw_migrate --help

Usage: pw_migrate [OPTIONS] COMMAND [ARGS]...

Options:
    --help  Show this message and exit.

Commands:
    create   Create migration.
    migrate  Run migrations.
    rollback Rollback migration.

创建迁移:

$ pw_migrate create --help

Usage: pw_migrate create [OPTIONS] NAME

    Create migration.

Options:
    --auto                  FLAG  Scan sources and create db migrations automatically. Supports autodiscovery.
    --auto-source           TEXT  Set to python module path for changes autoscan (e.g. 'package.models'). Current directory will be recursively scanned by default.
    --database              TEXT  Database connection
    --directory             TEXT  Directory where migrations are stored
    -v, --verbose
    --help                        Show this message and exit.

运行迁移:

$ pw_migrate migrate --help

Usage: pw_migrate migrate [OPTIONS]

    Run migrations.

Options:
    --name TEXT       Select migration
    --database TEXT   Database connection
    --directory TEXT  Directory where migrations are stored
    -v, --verbose
    --help            Show this message and exit.

From python

from peewee_migrate import Router
from peewee import SqliteDatabase

router = Router(SqliteDatabase('test.db'))

# Create migration
router.create('migration_name')

# Run migration/migrations
router.run('migration_name')

# Run all unapplied migrations
router.run()

Migration files

默认情况下,迁移文件在os.getcwd()/migrations目录中查找,但可以指定自定义目录。

迁移文件按文件名升序排序和应用。

每个迁移文件必须指定migrate()函数,并且可以指定rollback()函数:

def migrate(migrator, database, fake=False, **kwargs):
    pass

def rollback(migrator, database, fake=False, **kwargs):
    pass

Bug tracker

如果您有任何建议、错误报告或 烦恼请向问题追踪者报告 在https://github.com/klen/peewee_migrate/issues

Contributors

参见作者。rst

License

根据BSD license授权。

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

推荐PyPI第三方库


热门话题
java检查整数是0还是检查变量是null更好?   java Android Kotlin(初学者)使用File(),并从ACTION\u GET\u内容返回Uri   java JavaFx在“内部场景”和根场景之间切换   spring将XMLBean配置转换为java配置   java JPA HIBERNATE映射列两次(embeddedID和POJO)   c#单态模式模型在什么情况下适用?   java请求。getRemoteUser在特定时间后返回null?   spring boot中PUT api控制器的java my单元测试用例失败   java在字符串中互换地解析和替换值   java Android JNI在应用程序中检测到错误:调用JNI GetMethodID时出现挂起异常   JavaSpringDataMongo:使用非简单键持久化映射   爪哇玻璃鱼连接被拒绝   java如何在用户注册时发送特定电子邮件id的自动回复?   Java列表:实例化时和之后的赋值之间的差异