Created
February 3, 2009 22:35
-
-
Save MarkMenard/57805 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require_gem 'activerecord' | |
MIGRATIONS_PATH="#{File.dirname(__FILE__)}/db/migrate/" | |
# Set up ActiveRecord::Base.connection | |
# Migrate | |
database_type = ARGV[0] | |
# if database_type.nil? | |
# database_type = 'custom' | |
# database_yaml = <<-YAML | |
# #{database_type}: | |
# adapter: oracle | |
# database: database.andrewbeacock.com/beacock01 | |
# username: my_schema | |
# password: my_schema | |
# YAML | |
# else | |
# if you have a Rails project then place your scripts in db/script | |
database_yaml = IO.read("File.dirname(__FILE__)/config/database.yml") | |
# end | |
class MyTable < ActiveRecord::Base; set_table_name :my_table; end | |
class Script < ActiveRecord::Migration | |
def self.run | |
execute('update my_table set updated = true') | |
pp MyTable.find(:all) | |
end | |
end | |
databases = YAML::load(database_yaml) | |
ActiveRecord::Base.establish_connection(databases[database_type]) | |
Script.run | |
Migrator.migrate(MIGRATIONS_PATH, '200902031725') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment