Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

Migration engine for peewee orm

Project description

Peewee Migrations
=================

A simple and flexible migration manager for Peewee ORM.

Requirements
============

* python >= 3.5
* latest peewee


Installation
============

This package can be installed using pip:

```bash
pip install peewee-migrations
```

Usage
=====
After installation, run `pem init` in the project root.

Suppose we have `Foo` model in `models.py`

```python
class Foo(db.Model):
bar = peewee.CharField(max_length=50)
baz = peewee.IntegerField()
quux = peewee.IntegerField()
```

Add model to the watch list and create migration.
```bash
$ pem add models.Tweet
Model 'models.Foo' was added to the watch list.
$ pem watch
Migration `0001_migration_201807191008` has been created.
```

Now you can list available migrations:
```bash
$ pem list
[ ] 0001_migration_201807191008
```

Or view SQL that will be executed during migration:
```bash
$ 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:
```bash
$ pem migrate
[X] 0001_migration_201807191008
```

And now, if you change your model `Foo`
```python
class Foo(db.Model):
bar = peewee.CharField(max_length=20)
baz = peewee.IntegerField()
quux = peewee.IntegerField()
xyzzy = peewee.IntegerField()
```

Run `watch` to create new migration:
```bash
$ 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.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
peewee_migrations-0.3.6-py3-none-any.whl (15.2 kB) Copy SHA256 hash SHA256 Wheel py3
peewee-migrations-0.3.6.tar.gz (15.7 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page