NoBrainerORM / nobrainer

Ruby ORM for RethinkDB
http://nobrainer.io/
Other
386 stars 49 forks source link

Implements migration scripts #268

Open zedtux opened 4 years ago

zedtux commented 4 years ago

This PR adds support for migration scripts with nobrainer, heavily inspired from the ActiveRecord Migration Script concept (meaning familiar to RoR people that we are).

Migration script is really helpful in the data migration concern. Fix wrongly created data, deleting old data and more, can be easily done with migration scripts. It is especially true as I've implemented the Capistrano integration too, exactly as AR is doing.

I've added a very basic generator which generates a migration script file named the same way as AR does. The migration scripts are inheriting from the new NoBrainer::Migration class which holds the logic of running up then down if up failed.

Finally the new NoBrainer::Migrator class contains the heart of this PR and take care of:

The migrator supports both migrating all non executed scripts, and rollbacking the last script only.

So it's a very minimal implementation with tests everywhere AFAIK.

I'm using this branch for a production project at work and it works pretty well. I really hope you'll accept it 🙏. I'm of course ready to fix all the things that would need it.