Last Updated: February 25, 2016
·
691
· bernardogalindo

Setting a VERSION environment var in rails... no wait!

Well this a note to myself in order to avoid rails db:migrate problem again. You know that famous saying that say "human beings are the unique creature in the world that repeat two times their mistakes" and I'm one of them. Let me show why.

In my most recent rails application which is an startup that is changing pretty quickly, I took a decision to create a environment var named VERSION, in order to setup a local version to control that code that is messy or weird or chucky. (yes I know exists a gem for thatrollout gem). Well everything works fine, I can keep my code running localy and pushing to production without problems, stash, or different branches.The problem came to scene, when we decided to create a new migration and try to run it in the normal way, everything was reverted. You can check here example of my stupid problem

Then after run several commands schema:load, dump, drop, redo, rollback,etc. When I try to run the new migration rails revert all the migrations (F**cKING rails). But wait I decided to read the code behind the rails tasks and I discover my mistake.

Well all tasks under db:migrate namespaces check an environment var named VERSION, yes the same var that I've already setted (F**UCk). And yes like you can assume my ENV['VERSION'] was setting to '0' or something that convert to_i was zero like '0.0.2'.

Then this is a reminder for me ** DON'T SET VERSION VARIABLE ENV AGAIN ** and read more the magic behind rails tasks Rails task magic

Also I noticed that rails maintenance a table with schema and last ran migration that information is in the table: "schema_migrations"