question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot migrate stored procedure

See original GitHub issue

I’m submitting a…

  • Bug report
  • Feature request
  • Question

Current behavior

When created a stored procedure it’s necessary to change the delimiter e.g. DELIMITER $$

However, when using a SQL-file it returns ER_PARSE_ERROR:

Expected behavior

Be able to change the delimiter, create the SP and return delimiter back to standard ;

Minimal reproduction of the problem with instructions

DELIMITER // CREATE PROCEDURE testProc() BEGIN SELECT 1; END // DELIMITER ;

What is the motivation / use case for changing the behavior?

Cannot create or migrate stored procedures

Environment


db-migrate version: 0.11.5
db-migrate-mysql with versions: 1.1.10

Additional information:
- Node version: 8.12.0  
- Platform:  Mac

Others:

<bountysource-plugin>

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
tabroughtoncommented, Jun 1, 2020

after further tests I can see that this isn’t actually an issue for me at all. I have my connection config set to multipleStatements true and can indeed run multiple statements with stored procedures in the same sql file such as this one:


CREATE TABLE `foo` (`id` INT(11) NOT NULL AUTO_INCREMENT, `bar` VARCHAR(5), PRIMARY KEY (`id`));

CREATE PROCEDURE `insert_foo` (IN `@baz` VARCHAR(5))
BEGIN
  INSERT INTO `foo`(`bar`) VALUES(`@baz`);
END;

no need for a delimiter change at all

1reaction
lasergoatcommented, Aug 7, 2020

using mysql I can confirm, with multipleStatements set to true in the database.json and no delimiters, I was able to have a migration like:

  await db.runSql(`
    CREATE PROCEDURE reprocess_merchant(IN merchant_id VARCHAR(255))
    BEGIN
      DECLARE exit handler for SQLEXCEPTION
      BEGIN
      GET DIAGNOSTICS CONDITION 1 @sqlstate = RETURNED_SQLSTATE, 
      @errno = MYSQL_ERRNO, @text = MESSAGE_TEXT;
      SET @full_error = CONCAT("ERROR ", @errno, " (", @sqlstate, "): ", @text);
      SELECT @full_error, @mid, @mid_count, @transaction_count;
      END;

      # gather numeric MID
      SELECT m.mid INTO @mid FROM merchants m
      WHERE m.id = merchant_id
      AND m.mid REGEXP '^[0-9]+$';

      -- rest of proc here

      END
  `);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Stored procedure can not be parsed during migration
I'm using the api of flyway 1.7 for migrating a hsql database. I have some problems with stored procedures. The following script works...
Read more >
Unable to migrate views, routines and stored procedures from ...
I tried migrating the data from MSSQL server database(Windows) to mariadb(Linux) using Mysql Workbench. Workbench migrated few tables but ...
Read more >
Migrate stored procedures using SCT
We will now migrate some stored procedures using SCT, directly to Aurora (MySQL) · Navigate to Settings in the menu, and click Mapping...
Read more >
SSMA - error when converting function and stored procedure
I can able to migrate table and the data from Oracle to MS SQL using the SSMA tool, I have problem when migrating...
Read more >
Migrate SQL server database to mysql with store procedure
Either find a better tool, or migrate the stored procedures manually: MySQL :: MySQL 8.0 Reference Manual :: 13.1.17 CREATE PROCEDURE and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found