Java 如何启用DDL事务支持?

Java 如何启用DDL事务支持?,java,version-control,flyway,Java,Version Control,Flyway,我刚开始使用flywaydb,只是为了测试创建和插入查询,并启动了迁移,但它忽略了我的所有创建表脚本: 我使用-X选项进行调试,发现一行奇怪的代码 调试:支持的DDL事务:false 看来如果我真的做到了,它会成功的 是否有人面临这个问题,如果是,如何摆脱这个问题? 我已经在新模式上使用cleaninitmigrate完成了这项工作 全文如下: [ec2-user@ec2 flyway]$ ./flyway -X clean /usr/bin/tput Flyway (Command-line

我刚开始使用flywaydb,只是为了测试创建和插入查询,并启动了迁移,但它忽略了我的所有创建表脚本:

我使用-X选项进行调试,发现一行奇怪的代码 调试:支持的DDL事务:false

看来如果我真的做到了,它会成功的

是否有人面临这个问题,如果是,如何摆脱这个问题? 我已经在新模式上使用cleaninitmigrate完成了这项工作 全文如下:

[ec2-user@ec2 flyway]$ ./flyway -X clean
/usr/bin/tput
Flyway (Command-line Tool) v.3.0

DEBUG: Adding location to classpath: /home/ec2-user/installables/flyway-3.0/bin/../jars/mysql-connector-java-5.1.26.jar
Database: jdbc:mysql://0.0.0.0:3306/test (MySQL 5.5)
DEBUG: DDL Transactions Supported: false
DEBUG: Schema: test
DEBUG: Cleaning schema `test` ...
Cleaned schema `test` (execution time 00:00.025s)

[ec2-user@ec2 flyway]$ 
[ec2-user@ec2 flyway]$ ./flyway -X init
/usr/bin/tput
Flyway (Command-line Tool) v.3.0

DEBUG: Adding location to classpath: /home/ec2-user/installables/flyway-3.0/bin/../jars/mysql-connector-java-5.1.26.jar
Database: jdbc:mysql://0.0.0.0:3306/test (MySQL 5.5)
DEBUG: DDL Transactions Supported: false
DEBUG: Schema: test
DEBUG: Schema `test` already exists. Skipping schema creation.
Creating Metadata table: `test`.`schema_version`
DEBUG: Found statement at line 17: CREATE TABLE `test`.`schema_version` (
    `version_rank` INT NOT NULL,
    `installed_rank` INT NOT NULL,
    `version` VARCHAR(50) NOT NULL,
    `description` VARCHAR(200) NOT NULL,
    `type` VARCHAR(20) NOT NULL,
    `script` VARCHAR(1000) NOT NULL,
    `checksum` INT,
    `installed_by` VARCHAR(100) NOT NULL,
    `installed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `execution_time` INT NOT NULL,
    `success` BOOL NOT NULL
) ENGINE=InnoDB
DEBUG: Found statement at line 30: ALTER TABLE `test`.`schema_version` ADD CONSTRAINT `schema_version_pk` PRIMARY KEY (`version`)
DEBUG: Found statement at line 32: CREATE INDEX `schema_version_vr_idx` ON `test`.`schema_version` (`version_rank`)
DEBUG: Found statement at line 33: CREATE INDEX `schema_version_ir_idx` ON `test`.`schema_version` (`installed_rank`)
DEBUG: Found statement at line 34: CREATE INDEX `schema_version_s_idx` ON `test`.`schema_version` (`success`)
DEBUG: Executing SQL: CREATE TABLE `test`.`schema_version` (
    `version_rank` INT NOT NULL,
    `installed_rank` INT NOT NULL,
    `version` VARCHAR(50) NOT NULL,
    `description` VARCHAR(200) NOT NULL,
    `type` VARCHAR(20) NOT NULL,
    `script` VARCHAR(1000) NOT NULL,
    `checksum` INT,
    `installed_by` VARCHAR(100) NOT NULL,
    `installed_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `execution_time` INT NOT NULL,
    `success` BOOL NOT NULL
) ENGINE=InnoDB
DEBUG: Executing SQL: ALTER TABLE `test`.`schema_version` ADD CONSTRAINT `schema_version_pk` PRIMARY KEY (`version`)
DEBUG: Executing SQL: CREATE INDEX `schema_version_vr_idx` ON `test`.`schema_version` (`version_rank`)
DEBUG: Executing SQL: CREATE INDEX `schema_version_ir_idx` ON `test`.`schema_version` (`installed_rank`)
DEBUG: Executing SQL: CREATE INDEX `schema_version_s_idx` ON `test`.`schema_version` (`success`)
DEBUG: Metadata table `test`.`schema_version` created.
DEBUG: MetaData table `test`.`schema_version` successfully updated to reflect changes
Schema initialized with version: 1
[ec2-user@ec2 flyway]$ ./flyway -X migrate
/usr/bin/tput
Flyway (Command-line Tool) v.3.0

DEBUG: Adding location to classpath: /home/ec2-user/installables/flyway-3.0/bin/../jars/mysql-connector-java-5.1.26.jar
Database: jdbc:mysql://0.0.0.0:3306/test (MySQL 5.5)
DEBUG: DDL Transactions Supported: false
DEBUG: Schema: test
DEBUG: Spring Jdbc available: false
DEBUG: Validating migrations ...
DEBUG: Scanning for filesystem resources at '/home/ec2-user/installables/flyway-3.0/bin/../sql' (Prefix: 'V', Suffix: '.sql')
DEBUG: Scanning for resources in path: /home/ec2-user/installables/flyway-3.0/bin/../sql (/home/ec2-user/installables/flyway-3.0/bin/../sql)
DEBUG: Found filesystem resource: /home/ec2-user/installables/flyway-3.0/bin/../sql/V1__cr_tbl.sql
DEBUG: Found filesystem resource: /home/ec2-user/installables/flyway-3.0/bin/../sql/V2__Add_people.sql
Validated 2 migrations (execution time 00:00.032s)
DEBUG: Schema `test` already exists. Skipping schema creation.
DEBUG: Locking table `test`.`schema_version`...
DEBUG: Lock acquired for table `test`.`schema_version`
Current version of schema `test`: 1
Migrating schema `test` to version 2
DEBUG: Found statement at line 1: insert into PERSON (ID, NAME) values (1, 'Axel')
DEBUG: Found statement at line 2: insert into PERSON (ID, NAME) values (2, 'Mr. Foo')
DEBUG: Found statement at line 3: insert into PERSON (ID, NAME) values (3, 'Ms. Bar')
DEBUG: Executing SQL: insert into PERSON (ID, NAME) values (1, 'Axel')
DEBUG: Rolling back transaction...
DEBUG: Transaction rolled back
ERROR: Migration of schema `test` to version 2 failed! Please restore backups and roll back database and code!
DEBUG: MetaData table `test`.`schema_version` successfully updated to reflect changes
ERROR: Unexpected error
org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException: Error executing statement at line 1: insert into PERSON (ID, NAME) values (1, 'Axel')
    at org.flywaydb.core.internal.dbsupport.SqlScript.execute(SqlScript.java:91)
    at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.execute(SqlMigrationExecutor.java:73)
    at org.flywaydb.core.internal.command.DbMigrate$5.doInTransaction(DbMigrate.java:287)
    at org.flywaydb.core.internal.command.DbMigrate$5.doInTransaction(DbMigrate.java:285)
    at org.flywaydb.core.internal.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:72)
    at org.flywaydb.core.internal.command.DbMigrate.applyMigration(DbMigrate.java:285)
    at org.flywaydb.core.internal.command.DbMigrate.access$800(DbMigrate.java:46)
    at org.flywaydb.core.internal.command.DbMigrate$2.doInTransaction(DbMigrate.java:207)
    at org.flywaydb.core.internal.command.DbMigrate$2.doInTransaction(DbMigrate.java:156)
    at org.flywaydb.core.internal.util.jdbc.TransactionTemplate.execute(TransactionTemplate.java:72)
    at org.flywaydb.core.internal.command.DbMigrate.migrate(DbMigrate.java:156)
    at org.flywaydb.core.Flyway$1.execute(Flyway.java:864)
    at org.flywaydb.core.Flyway$1.execute(Flyway.java:811)
    at org.flywaydb.core.Flyway.execute(Flyway.java:1171)
    at org.flywaydb.core.Flyway.migrate(Flyway.java:811)
    at org.flywaydb.commandline.Main.executeOperation(Main.java:120)
    at org.flywaydb.commandline.Main.main(Main.java:88)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.PERSON' doesn't exist
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.Util.getInstance(Util.java:386)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4190)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4122)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2812)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2761)
    at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:894)
    at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:732)
    at org.flywaydb.core.internal.dbsupport.JdbcTemplate.executeStatement(JdbcTemplate.java:235)
    at org.flywaydb.core.internal.dbsupport.SqlScript.execute(SqlScript.java:89)
    ... 16 more

这仅仅意味着您的数据库不支持DDL事务。如果需要,请使用不同的方法,如PostgreSQL、DB2或SqlServer

至于为什么你的剧本没有被采纳,这是不可能从你的问题中分辨出来的


从入门教程开始,一旦成功,就将其应用于您的项目。

嗨,Axel,我正在使用mysql,这个问题是我从入门教程中得到的。如果您完全按照步骤操作,它就会起作用。发布一个飞行路线清理,然后再试一次。@alex fontaine,我按照您在中所说的做了,只是我使用的是mysql。init和clean正在工作,但对于忽略V1_ucr_tbl.sql的迁移,我已经更新了原始问题中的完整stacktrace跳过init。它仅适用于现有的dbs。仍然失败:,我发现该过程适用于H2数据库,但不适用于MySQL。