Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.