2

I am deploying regular updates for my Rails application with Capistrano and I keep a version number as a string in a global constant.

I would like to be a able to deploy/run a simple script only once for a specific update, that will perform some operations on the database (I am using mongoid, and I have modified the schema a bit)

Let's say I am under version 0.1.25 and upgrading to 0.1.26, I'd like to run this custom script only once for servers that are 0.1.25 or below (the script won't be ran again for next updates like 0.1.26 to 0.1.27)

MyModel.all.each do |instance|
  instance.new_field_with_v26 = somefunction
end

I believe this can be implemented as a Capistrano task, but how do I retrieve the previous value of that constant ? (Application::VERSION_NUMBER)

Cyril Duchon-Doris
  • 12,964
  • 9
  • 77
  • 164

1 Answers1

1

You might be able to do this using a migrations system, which Capistrano can then run. For example: https://github.com/adacosta/mongoid_rails_migrations

At a bare minimum, something like this might serve as a template:

  • Store the schema version in the database.
  • When you make a change to the schema, increment the schema version in the code.
  • Write a Rake task to run the pertinent migrations.

I hope this is helpful.

will_in_wi
  • 2,623
  • 1
  • 16
  • 21