Skip to content

Instantly share code, notes, and snippets.

@abruzzi
Forked from andyvanee/Rakefile
Created July 26, 2014 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abruzzi/975d076c33bbdbfc510f to your computer and use it in GitHub Desktop.
Save abruzzi/975d076c33bbdbfc510f to your computer and use it in GitHub Desktop.

Rake migrate without rails

This is a very barebones database migration setup. All that's needed is what's required in the Rakefile and Ruby, of course.

adapter: mysql
encoding: utf8
database: database_name
username: root
password:
class TestMigration < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.column :name, :string, :null => false
end
end
def self.down
drop_table :users
end
end
require 'active_record'
require 'yaml'
require 'mysql'
require 'logger'
task :default => :migrate
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('config/database.yml')))
ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a'))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment