Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use just migrations from rails to maintain a database schema?

Our application isn't going to use rails for any part of its final state, but migrations are a fantastic way to define schema in my experience, so I'd like to use just that one aspect of rails.

Is this a reasonable thing to do? If not, are there any tools out there than can be used to perform the same sort of job? We have a three-stage deployment environment, with test, QA, and production tiers, so this maps pretty well to the tiers that rails uses. However, we're a python shop primarily, so a pythonic equivalent would be nifty.

like image 678
Chris R Avatar asked Jan 01 '26 16:01

Chris R


1 Answers

I do not have any particular alternative to give you. But if you decide to use the migrations anyway, you must know that you do not need to use the whole rails architecture only for migrations.

As long as you have the active_record gem installed, you can do : in your Rakefile

require 'active_record'
require 'yaml'

task :default => :migrate 

In a file on the same path :

desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x"
task :migrate => :environment do
    ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
end

task :environment do
    ActiveRecord::Base.establish_connection(YAML::load(File.open('database.yml')))
    ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a'))
end

And your migrations in the db/migrate folder. You do not need the whole activeresources and all of rails base.

like image 60
Damien MATHIEU Avatar answered Jan 03 '26 12:01

Damien MATHIEU



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!