Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can flask-peewee do migration?

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?

like image 217
user3817928 Avatar asked Jul 23 '14 09:07

user3817928


People also ask

How does a Flask migration work?

The normal migration process goes as follows: You will make some changes to your models in your Python source code. You will then run flask db migrate to generate a new database migration for these changes. You will finally apply the changes to the database by running flask db upgrade .

What is peewee in Flask?

Check out flask-peewee - a flask plugin that provides a django-like Admin interface, RESTful API, Authentication and more for your peewee models.

Why do flasks migrate?

Flask migrate is defined as an extension that is used in the Flask application for handling database migrations for SQLAlchemy using Alembic. This module enables developers to quickly set up and starts the database schema migrations.


2 Answers

It looks like the Peewee module does support migrations.

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

like image 118
Nick Woodhams Avatar answered Sep 22 '22 11:09

Nick Woodhams


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.)

like image 29
keredson Avatar answered Sep 19 '22 11:09

keredson