@@ -273,3 +273,47 @@ func testMysqlNotAllowed(t *testing.T, dsn string, createPostfix string, driverN
273273 }
274274 }
275275}
276+
277+ func TestMigrationWithDelimiter (t * testing.T ) {
278+ options , cleanup := lstesting .FakeSchema (t , "" )
279+
280+ t .Log ("Doing migrations in database/schema" , options .SchemaOverride )
281+
282+ t .Log ("We will error on unknown migrations" )
283+
284+ options .DebugLogging = true
285+ t .Log ("No opening the database..." )
286+ db , err := sql .Open ("mysql" , dsn )
287+ require .NoError (t , err , "open database" )
288+ defer func () {
289+ assert .NoError (t , db .Close ())
290+ }()
291+ defer cleanup (db )
292+
293+ s := libschema .New (context .Background (), options )
294+ dbase , _ , err := driverNew (t , "test" , s , db )
295+ require .NoError (t , err , "libschema NewDatabase" )
296+
297+ dbase .Migrations ("L1" ,
298+ lsmysql .Script ("SP" , `
299+ DELIMITER //
300+ CREATE PROCEDURE charge_account(id BIGINT, amount DECIMAL(18,4)) AS
301+ DECLARE
302+ balance_tbl QUERY(bal DECIMAL(18,4)) =
303+ SELECT remaining_balance
304+ FROM account_balance
305+ WHERE account_id = id;
306+ balance DECIMAL(18,4) = SCALAR(balance_tbl);
307+ updated_balance DECIMAL(18,4) = balance - amount;
308+ BEGIN
309+ IF balance > amount THEN
310+ UPDATE account_balance
311+ SET remaining_balance = updated_balance
312+ WHERE account_id = id;
313+ END IF;
314+ END //
315+ DELIMITER ;
316+ ` ))
317+ err = s .Migrate (context .Background ())
318+ assert .NoError (t , err )
319+ }
0 commit comments