Is there any easy to install/use (on unix) database migration tools like Rails Migrations? I really like the idea, but installing ruby/rails purely to manage my database migrations seems overkill.
I haven't personally done it, but it should be possible to use ActiveRecord::Migration without any of the other Rails stuff. Setting up the load path correctly would be the hard part, but really all you need is the rake
tasks and the db/migrate
directory plus whatever Rails gems they depend on, probably activerecord
, actviesupport
and maybe a couple others like railties
. I'd try it and just see what classes are missing and add those in.
At a previous company we built a tool that did essentially what ActiveRecord::Migration does, except it was written in Java as a Maven plugin. All it did was assemble text blobs of SQL scripts. It just needs to be smart about the filenames going in order and know how to update a versioning table.
Just use ActiveRecord and a simple Rakefile. For example, if you put your migrations in a db/migrate
directory and have a database.yml
file that has your db config, this simple Rakefile should work:
Rakefile:
require 'active_record'
require 'yaml'
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(STDOUT)
end
database.yml:
adapter: mysql
encoding: utf8
database: test_database
username: root
password:
host: localhost
Afterwards, you'll be able to run rake migrate
and have all the migration goodness without a surrounding rails app.
Alternatively, I have a set of bash scripts that perform a very similar function to ActiveRecord migrations, but they only work with Oracle. I used to use them before switching to Ruby and Rails. They are somewhat complicated and I provide no support for them, but if you are interested, feel free to contact me.
There's also a project called Java Database Migrations. To get the code check out the Google Code page for the project.
I see this topic is really old, but I'll chip in for future googlers.
I really like using Python's SQLAlchemy and SQLAlchemy-Migrate to manage databases that I need to version control, if you don't want to go the ActiveRecord::Migrate route.