Migration engine for peewee orm
Project description
Peewee Migrations
A simple and flexible migration manager for Peewee ORM.
- Version: 0.3.16
- Status: Development/Alpha
- Author: Churin Andrey
Requirements
- python >= 3.5
- latest peewee
Quick start
This package can be installed using pip:
$ pip install peewee-migrations
Run pem init
in the project root.
$ pem init
Configuration file 'migrations.json' was created.
Suppose we have Foo
model in models.py
class Foo(db.Model):
bar = peewee.CharField(max_length=50)
baz = peewee.IntegerField()
quux = peewee.IntegerField()
Add this model to the watch list and create migration.
$ pem add models.Foo
Model 'models.Foo' was added to the watch list.
$ pem watch
Migration `0001_migration_201807191008` has been created.
Now you can list available migrations:
$ pem list
[ ] 0001_migration_201807191008
Or view SQL that will be executed during migration:
$ pem show
[ ] 0001_migration_201807191008:
SQL> CREATE TABLE "foo" ("id" SERIAL NOT NULL PRIMARY KEY, "bar" VARCHAR(50) NOT NULL, "baz" INTEGER NOT NULL, "quux" INTEGER NOT NULL) []
PY> set_done('0001_migration_201807191008')
Use migrate
to run migrations:
$ pem migrate
[X] 0001_migration_201807191008
Change model Foo
class Foo(db.Model):
bar = peewee.CharField(max_length=20)
baz = peewee.IntegerField()
quux = peewee.IntegerField()
xyzzy = peewee.IntegerField()
and run watch
to create new migration:
$ pem watch
Migration `0002_migration_201807191036` has been created.
$ pem show
[ ] 0002_migration_201807191036:
SQL> ALTER TABLE "foo" ADD COLUMN "xyzzy" INTEGER []
SQL> ALTER TABLE "foo" RENAME COLUMN "bar" TO "old__bar" []
SQL> ALTER TABLE "foo" ADD COLUMN "bar" VARCHAR(20) []
SQL> UPDATE "foo" SET "xyzzy" = %s WHERE ("xyzzy" IS %s) [0, None]
SQL> UPDATE "foo" SET "bar" = SUBSTRING("old__bar", %s, %s) WHERE ("old__bar" IS NOT %s) [1, 20, None]
SQL> ALTER TABLE "foo" DROP COLUMN "old__bar" []
SQL> ALTER TABLE "foo" ALTER COLUMN "xyzzy" SET NOT NULL []
SQL> ALTER TABLE "foo" ALTER COLUMN "bar" SET NOT NULL []
PY> set_done('0002_migration_201807191036')
For more information on using the commands see --help.
migrations.json
{
"prerun": "some code here", // some code to run before executing any command
"directory": "migrations", // folder to hold migrations
"history": "migratehistory", // table to hold migration history
"models": [ // list of models to watch
"module1.Model1",
"module2.Model2"
]
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for peewee_migrations-0.3.17-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94689474553e56a977cb9e68859b08d1573092a5192fe7ac355d43fb04dce249 |
|
MD5 | 063ce536a01170c5c97d16f9311192b9 |
|
BLAKE2b-256 | 954aa4be2e8515b8c43e3600b277d04ce2947e50bd5172acc8b757ad0a61db5d |