0

I've a project in GO that check if there are new migrations to apply when the app starts (I'm using library https://github.com/mattes/migrate).

Now the problem is that I have a stored procedure to create in one of this migration (because this will be called later, and I need to create it in a migration otherwise the test suite will fail of course).

An example can be this one:

DELIMITER @@
    CREATE PROCEDURE get_value(my_id BIGINT(20), OUT out_value DOUBLE)
       BEGIN
         SELECT CASE
            WHEN o.financial_status = "test" THEN 0
            ELSE 1
            END
            INTO out_value
          FROM `order` o
          LEFT JOIN `my_table_2` io ON io.field_2 = o.id
          LEFT JOIN `my_table_3` ip ON io.field_3 = ip.id
          WHERE o.id = my_id;
END @@
DELIMITER ;

As far as I read, this might not be possible because sql driver for go does not support multi statement (we're using mysql 5.6).

There are any other way to do that? Thanks!

Alessio
  • 2,018
  • 25
  • 26
  • Did you take a look at mymysl? http://stackoverflow.com/questions/28548559/does-a-go-mysql-driver-exist-that-supports-multiple-statements-within-a-single-s – Alexey Soshin Sep 08 '16 at 19:14

1 Answers1

1

I ran into the same situation, actually. The way I ran it is I removed all delimiter declarations and ran it. Since you don't need a delimiter within the migration, it will auto terminate (or realistically denominate) and the migration should run.

grepsedawk
  • 3,324
  • 2
  • 26
  • 49