I have a play framework 2.2.2 scala application and use play-flyway 1.0.3.
The following migration should be run by flyway:
ALTER TABLE `user_visits` ADD `FirstSiteRequestTime` DATETIME NOT NULL ;
UPDATE `user_visits` SET `FirstSiteRequestTime`=(SELECT `Time` FROM `user_siterequests` WHERE `user_siterequests`.`Visit`=`user_visits`.`ID` ORDER BY `Time` ASC LIMIT 1) ;
So I add a column to a table and then programatically fill it using an update statement.
The first line executes fine, but the update statemens fails with
FlywaySqlScriptException: Error executing statement at line 2: UPDATE `user_visits` SET `FirstSiteRequestTime`=(SELECT `Time` FROM `user_siterequests` WHERE `user_siterequests`.`Visit`=`user_visits`.`ID` ORDER BY `Time` ASC LIMIT 1)
com.googlecode.flyway.core.command.FlywaySqlScriptException: Error executing statement at line 2: UPDATE `user_visits` SET `FirstSiteRequestTime`=(SELECT `Time` FROM `user_siterequests` WHERE `user_siterequests`.`Visit`=`user_visits`.`ID` ORDER BY `Time` ASC LIMIT 1)
com.googlecode.flyway.core.dbsupport.SqlScript.execute(SqlScript.java:92)
com.googlecode.flyway.core.resolver.sql.SqlMigrationExecutor.execute(SqlMigrationExecutor.java:72)
com.googlecode.flyway.core.command.DbMigrate$2.doInTransaction(DbMigrate.java:243)
com.googlecode.flyway.core.command.DbMigrate$2.doInTransaction(DbMigrate.java:241)
com.googlecode.flyway.core.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:72)
However, when I take the migration SQL code and run it using phpmyadmin, it works fine (although it takes 2-5 seconds to run, the tables are quite big).
My mysql.log looks like
128 Query SET autocommit=0
128 Query ALTER TABLE `user_visits` ADD `FirstSiteRequestTime` DATETIME NOT NULL
140412 4:40:43 128 Query UPDATE `user_visits` SET `FirstSiteRequestTime`=(SELECT `Time` FROM `user_siterequests` WHERE `user_siterequests`.`Visit`=`user_visits`.`ID` ORDER BY `Time` ASC LIMIT 1)
140412 4:40:44 128 Query rollback
128 Query SET autocommit=1
Is flyway having some kind of timeout? The log file shows it sends the query to the mysql server but then rolls back. Why? As stated before, the query is correct. It works when I run it manually.
edit:
After running the migration, the ALTER TABLE statement was executed and committed (the table is altered), although the mysql.log says it was rolled back. The second command was really rolled back.
I also tried splitting the two SQL commands in two migrations. Then the first one (ALTER TABLE) runs fine and the second one fails.
edit2:
It might be some kind of timeout problem. Making it execute faster (by only updating some of the rows)
ALTER TABLE `user_visits` ADD `FirstSiteRequestTime` DATETIME NOT NULL ;
UPDATE `user_visits` SET `FirstSiteRequestTime`=(SELECT `Time` FROM `user_siterequests` WHERE `user_siterequests`.`Visit`=`user_visits`.`ID` ORDER BY `Time` ASC LIMIT 1) WHERE user_visits.id<1000;
runs correctly, also in flyway.