Creating migrations for stored procedures, functions and events from existing database in Laravel

12,002

To execute raw SQL commands in a migration (like the creation of a stored procedure) you can do:

public function up() 
{            
    DB::unprepared('CREATE PROCEDURE my_procedure( IN param INT(10) )  BEGIN  /* here your SP code */ END');
}

public function down() 
{
    DB::unprepared('DROP PROCEDURE IF EXISTS my_procedure');
}
Share:
12,002
jai
Author by

jai

Updated on June 09, 2022

Comments

  • jai
    jai almost 2 years

    I am working on laravel 4.1. I have a ready made mysql database created by other means. I have managed to create a migration from the existing database that would create all the tables in the database if run.

    I want the migration to also include the stored procedures, functions and events present in the database.

    I would specifically like to know how to create laravel migrations for stored procedures, events and functions from an existing database.

  • jai
    jai over 8 years
    I understand that. But I already have my db. I found some gist code here stackoverflow.com/questions/23514679/… which tells me how to generate a migration script for all the tables in an already existing mysql db in one shot. But this code does not tell me how to include the stored procedures, function or events present in the db which is what I need.
  • jai
    jai over 8 years
    After some looking around and consulting I have found there is no way to do what I want. We need to manually create the the above code copy/ pasting the stored procedures and the parameters in the code above.
  • Banago
    Banago over 7 years
    Thanks for this, exactly what I needed.