Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
How to migrate Stored procedure
3 Posts
How to migrate Stored procedure

Hi all,

I was wondering how to migrate a stored procedure by using rake db:migrate . my code is : class StoredProcedures < ActiveRecord::Migration def self.up

end end My stored procedure is DELIMITER $$

DROP PROCEDURE IF EXISTS stocks.stock_details$$ CREATE DEFINER=root@localhost PROCEDURE stock_details(IN l_stock INT,IN userid INT,OUT l_stockid INT,OUT l_stockbalance FLOAT,OUT sid INT) BEGIN SELECT stock_id,units,held_by,id INTO l_stockid,l_stockbalance,userid,sid FROM user_stock_details WHERE stock_id=l_stock AND held_by=userid; END$$

DELIMITER ;

How to add this in my migration file to create when run rake db:migrate ??

thanks, sri..

What you need is to just execute your SQL in your up and down methods, Rails has you covered with the execute method. Something like this:

class StoredProcedures < ActiveRecord::Migration

def self.up
  execute &lt;
end

end

Hi King, Thanks a lot, its working great !!!

3 Posts
Login to add your message