peewee的简单迁移引擎
peewee-migrate-dev的Python项目详细描述
peewee migrate–一个简单的peewee迁移引擎
内容
Usage
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
Contributing
在github开发起动机:https://github.com/klen/peewee_migrate
Contributors
参见作者。rst
License
根据BSD license授权。