Can flask-peewee do migration?
Asked Answered
T

3

6

I want to use flask peewee as ORM for a relational db (MySQL) but my problem is changes in structure of models... like adding new attributes for a model (this means columns in db). I want to know if I can do this automatically without writing SQL manually?

Thrash answered 23/7, 2014 at 9:24 Comment(0)
R
6

It looks like the Peewee module does support migrations.

http://peewee.readthedocs.org/en/latest/peewee/playhouse.html#schema-migrations

Reentry answered 23/7, 2014 at 17:43 Comment(1)
Depends on what you want from a migration tool. Some migration tools handle data versioning for you and automatically applies the correct migrations to update the database to match the current schemas. The build-in peewee migration module does not do that. It just adds or removes columns, according to what your tell it to do.Groark
H
6

I've wrote a simple migration engine for Peewee https://github.com/klen/peewee_migrate

Heartwhole answered 14/12, 2014 at 10:58 Comment(1)
Thanks, Kirill, it's really great! Hope you'll implement versioning feature anytime soon.Taegu
K
6

We developed https://github.com/keredson/peewee-db-evolve for our company's use that sounds like it may be helpful for you.

Rather than manually writing migrations, db-evolve calculates the diff between the existing schema and your defined models. It then previews and applies the non-destructive SQL commands to bring your schema into line. We've found it to be a much more robust model for schema management. (For example, switching between arbitrary branches with different schema changes is trivial this way, vs. virtually impossible w/ manually authored migrations.)

Example:

enter image description here

Think of it as a non-destructive version of Peewee's create_tables(). (In fact we use it for exactly that all the time, to build the schema from scratch in tests.)

Knowhow answered 23/11, 2016 at 19:41 Comment(4)
Amazing library! But I wish it worked with peewee 3.x too. Any chance you are working on an upgrade?Gulgee
thanks! yes: github.com/keredson/peewee-db-evolve/tree/peewee3 pretty much complete - looking for testers if you want to give it a whirl. @GulgeeKnowhow
unfortunately, I can't even install it. I commented in this PR: github.com/keredson/peewee-db-evolve/pull/27Gulgee
peewee 3.x is supported (as of a year or so ago now)Knowhow

© 2022 - 2024 — McMap. All rights reserved.