Tuesday, 17 July 2012

A First Look at Flask-Evolution

While poking around in Flask-Ahoy this morning I came across Flask-Evolution which I hadn't previous noticed. It offers the Django idea of migrations to the Flask community and so I thought I'd give it a go and see how it shapes up.

So let's set up a virtual environment and get the basics in place.
Now the contents of the two files you touched. First the "hello world" Flask app goes in the myapp.py file:

Next we we take the tutorial Flask-Script manage.py file and adapt it very slightly:

Now we are ready to create a simple migration for a Post model for a blog:

and you get the template file which looks like this:

In the file put your Post model and modfy "up" and "down":

Our First Migration

Our Second Migration
Now if we want to modify that Post model we can again do:

modify your model and modfy "up" and "down", I've left some comments so you can see what I did:

and run it again.

You should also play around with the "redo" and "undo" commands. That's about it really.

This is only version 0.6 of Flask-Evolution and it's got a way to go, but I can see some use in using it, but it's far from seamless and it's a long way from South.

Documentation is woeful and I'm not convinced the developer Adam Patterson has the time to do the job he'd like to.

You could always offer to give him a hand!

If you see anything wrong with what I've written here or if you spot spelling or other mistakes then please let me know.

Good luck fellow traveller.

1 comment:

  1. I need some help on how to write a migration file.
    In the up function its written in comments
    "MyModel.__table__.create()" I tried doing the same by importing the model but it says :

    sqlalchemy.exc.UnboundExecutionError: The Table 'replies' is not bound to an Engine or Connection. Execution can not proceed without a database to execute against. Either execute with an explicit connection or assign this Table's .metadata.bind to enable implicit execution.

    Am also not able to do redo or undo. I get error saying IrreversibleMigration is not defined.

    I think a screenshots of the migration file are missing in your post.

    Thanks a lot!