Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 356
jai Avatar asked Nov 16 '15 08:11

jai


1 Answers

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');
}
like image 90
Moppo Avatar answered Sep 21 '22 22:09

Moppo