public
Created

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
STORED_PROCEDURE = 'find_the_id'
STORED_PROCEDURE_FILE = 'StoredProcedure.sql'
class AddStoredProcedure < ActiveRecord::Migration
def self.up
sql_directory = File.join(File.dirname(__FILE__), 'sql')
conf = Rails::Configuration.new.database_configuration[RAILS_ENV]
sql_file = File.join(sql_directory, STORED_PROCEDURE_FILE)
host = conf['host'] ? conf['host'] : 'localhost'
database = conf['database']
username = conf['username'] ? conf['username'] : 'root'
password = conf['password'] ? conf['password'] : ''
cmd_line = 'mysql5 -h ' + host + ' -D ' + database + ' -u ' + username
cmd_line += ' -p ' + password if password.nil?
cmd_line += ' < ' + sql_file.to_s
unless system(cmd_line)
raise Exception, 'Error creating stored procedure ' + STORED_PROCEDURE
end
end
 
def self.down
execute 'DROP PROCEDURE ' + STORED_PROCEDURE
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.