DISCLAIMER : I am not a Ruby-on-Rails Programmer
Strictly in terms of MySQL, you basically have two ways to extract Stored Procedures (SP) and Stored Functions (SF).
Keep in mind that mysql.proc and information_schema.routines provide the housing on disk and in memory for SPs. Yet, there are 2 SQL statements to retrieve them: SHOW CREATE PROCEDURE and SHOW CREATE FUNCTION.
The first way involves collecting all SPs and SFs using mysql.proc and form them into SQL statements that expose them.
Example I have 6 SPs and 2 SFs in my test database. Here is how to generate SQL for all 8 routines:
mysql> SELECT CONCAT('SHOW CREATE ',type,' `',db,'`.`',name,'`\\G') SQLStatements FROM mysql.proc;
+-----------------------------------------------------+
| SQLStatements |
+-----------------------------------------------------+
| SHOW CREATE PROCEDURE `test`.`CreateSampleTable`\G |
| SHOW CREATE PROCEDURE `test`.`CreateSampleTables`\G |
| SHOW CREATE PROCEDURE `test`.`GetMissingIntegers`\G |
| SHOW CREATE FUNCTION `test`.`GetTestTableCounts`\G |
| SHOW CREATE PROCEDURE `test`.`ImportWeeklyBatch`\G |
| SHOW CREATE FUNCTION `test`.`InsertName`\G |
| SHOW CREATE PROCEDURE `test`.`LoadSampleTables`\G |
| SHOW CREATE PROCEDURE `test`.`MigrateColumn`\G |
+-----------------------------------------------------+
8 rows in set (0.00 sec)
You can cycle through and collect the code needed to each stored procedure and function.
Triggers must be collected separately.
In MySQL 5.x you can collect triggers using this query:
mysql> SELECT CONCAT('SHOW CREATE TRIGGER `',trigger_schema,'`.`',trigger_name,'`\\G') SQLStatements FROM information_schema.triggers;
+--------------------------------------------------+
| SQLStatements |
+--------------------------------------------------+
| SHOW CREATE TRIGGER `test`.`AddPermTempKey`\G |
| SHOW CREATE TRIGGER `test`.`DeletePermTempKey`\G |
+--------------------------------------------------+
or to save time UNION the two SQL statements
mysql> SELECT CONCAT('SHOW CREATE ',type,' `',db,'`.`',name,'`\\G') SQLStatements FROM mysql.proc UNION SELECT CONCAT('SHOW CREATE TRIGGER `',trigger_schema,'`.`',trigger_name,'`\\G') SQLStatements FROM information_schema.triggers;
+-----------------------------------------------------+
| SQLStatements |
+-----------------------------------------------------+
| SHOW CREATE PROCEDURE `test`.`CreateSampleTable`\G |
| SHOW CREATE PROCEDURE `test`.`CreateSampleTables`\G |
| SHOW CREATE PROCEDURE `test`.`GetMissingIntegers`\G |
| SHOW CREATE FUNCTION `test`.`GetTestTableCounts`\G |
| SHOW CREATE PROCEDURE `test`.`ImportWeeklyBatch`\G |
| SHOW CREATE FUNCTION `test`.`InsertName`\G |
| SHOW CREATE PROCEDURE `test`.`LoadSampleTables`\G |
| SHOW CREATE PROCEDURE `test`.`MigrateColumn`\G |
| SHOW CREATE TRIGGER `test`.`AddPermTempKey`\G |
| SHOW CREATE TRIGGER `test`.`DeletePermTempKey`\G |
+-----------------------------------------------------+
10 rows in set (0.07 sec)
The second way is the preferred way for DBAs, using mysqldump.
This will collect all table structures, SPs, SFs, and triggers in a single file.
mysqldump -h... -u... -p... --no-data --routines --triggers --all-databases > MySQLSchema.sql
This will do the same but without the CREATE TABLE stuff:
mysqldump -h... -u... -p... --no-data --no-create-info --routines --triggers --all-databases > MySQLSchema.sql
Give these a Try !!!