支持Peewee ORM迁移
项目描述
Peewee Migrate – 一个简单的Peewee ORM迁移引擎
要求
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
用法
从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
项目详情
下载文件
下载您平台上的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分发
peewee_migrate-1.13.0.tar.gz (17.1 kB 查看哈希值)
构建分发
peewee_migrate-1.13.0-py3-none-any.whl (19.4 kB 查看哈希值)