跳转到主要内容

支持Peewee ORM迁移

项目描述

Peewee Migrate – 一个简单的Peewee ORM迁移引擎

Tests Status Build Status PYPI Version Python Versions

要求

  • peewee >= 3.8

依赖项注意

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

  • 对于 Python 3.0-3.6 请使用 Peewee-Migrate==1.1.6

  • 对于 Python 3.7 请使用 Peewee-Migrate==1.6.6

  • 对于 Python 3.8+ 请使用 Peewee-Migrate>=1.12.1

安装

Peewee Migrate 应使用pip安装

pip install peewee-migrate

用法

您想要Flask集成吗?请查看Flask-PW

从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.

回滚迁移

$ pw_migrate rollback --help

Usage: pw_migrate rollback [OPTIONS]

    Rollback a migration with given steps --count of last migrations as integer number

Options:
    --count INTEGER   Number of last migrations to be rolled back.Ignored in
                        case of non-empty name

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

从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()

迁移文件

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

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

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

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

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

错误跟踪器

如果您有任何建议、错误报告或烦恼,请通过 https://github.com/klen/peewee_migrate/issues 的 issue tracker 报告。

贡献

起始器开发在 github 上进行:https://github.com/klen/peewee_migrate

项目详情


发布历史 发布通知 | RSS 源

下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分发

peewee_migrate-1.13.0.tar.gz (17.1 kB 查看哈希值)

上传

构建分发

peewee_migrate-1.13.0-py3-none-any.whl (19.4 kB 查看哈希值)

上传 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面