从 Laravel 中的现有数据库为存储过程、函数和事件创建迁移

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33731109/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:41:47  来源:igfitidea点击:

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

phpmysqllaravelstored-proceduresmigration

提问by jai

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.

我正在研究 Laravel 4.1。我有一个通过其他方式创建的现成的 mysql 数据库。我已经设法从现有数据库创建迁移,如果运行,它将创建数据库中的所有表。

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.

我特别想知道如何为现有数据库中的存储过程、事件和函数创建 Laravel 迁移。

回答by Moppo

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

要在迁移中执行原始 SQL 命令(例如创建存储过程),您可以执行以下操作:

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');
}

回答by Jean Freitas

Works with DB::raw('DELIMITER $$ CREATE FUNCTION....')for me.

工程与DB::raw('DELIMITER $$ CREATE FUNCTION....')我。