I'm using Entity Framework Core and I want to use a stored procedure. I create a custom SQL to create it on a migration.
The generate scrip is as follows:
DROP PROCEDURE IF EXISTS MigrationsScript;
DELIMITER //
CREATE PROCEDURE MigrationsScript()
BEGIN
IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '20190411134055_AddGenerations_sp') THEN
DROP PROCEDURE IF EXISTS GetCurrentGeneration;
CREATE PROCEDURE GetCurrentGeneration(IN timeOut INT, IN createBy char(255))
BEGIN
-- Stored procedure body
END
END IF;
END //
DELIMITER ;
CALL MigrationsScript();
DROP PROCEDURE MigrationsScript;
DROP PROCEDURE IF EXISTS MigrationsScript;
DELIMITER //
CREATE PROCEDURE MigrationsScript()
BEGIN
IF NOT EXISTS(SELECT 1 FROM `__EFMigrationsHistory` WHERE `MigrationId` = '20190411134055_AddGenerations_sp') THEN
INSERT INTO `__EFMigrationsHistory` (`MigrationId`, `ProductVersion`)
VALUES ('20190411134055_AddGenerations_sp', '2.2.4-servicing-10062');
END IF;
END //
DELIMITER ;
CALL MigrationsScript();
DROP PROCEDURE MigrationsScript;
But I'm getting this error
Error Code: 1357. Can't drop or alter a PROCEDURE from within another stored routine