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?

user3817928
  • 95
  • 1
  • 4

3 Answers3

6

It looks like the Peewee module does support migrations.

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

Nick Woodhams
  • 11,977
  • 10
  • 50
  • 52
  • 2
    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. – Anders E. Andersen Jun 25 '16 at 08:51
6

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

klen
  • 1,595
  • 12
  • 11
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.)

keredson
  • 3,019
  • 1
  • 17
  • 20
  • 2
    Amazing library! But I wish it worked with peewee 3.x too. Any chance you are working on an upgrade? – bman Jun 05 '18 at 04:01
  • 1
    thanks! yes: https://github.com/keredson/peewee-db-evolve/tree/peewee3 pretty much complete - looking for testers if you want to give it a whirl. @bman – keredson Jun 05 '18 at 17:38
  • unfortunately, I can't even install it. I commented in this PR: https://github.com/keredson/peewee-db-evolve/pull/27 – bman Jun 06 '18 at 00:17
  • peewee 3.x is supported (as of a year or so ago now) – keredson Oct 05 '19 at 18:08