3

我越了解 flyway 如何进行数据库迁移,我就越喜欢它。

我试图让 flyway 读取从 mysqldump -d 生成的迁移,但我偶然发现了一些奇怪的行为。

在主页上它说

mysqldump 导出的 DDL 可以在 Flyway 迁移中原样使用。

我的经历有点不同。如何将mysqldump生成的文件与flyway一起使用?


我在尝试什么:

我尝试通过使用获取 DDL

mysqldump -h host --user=user -p -d --hex-blob databasename > V1__Basic.sql

这确实有效,并给了我一个看起来像这样的文件(是的,它是来自 Activiti 的数据库方案 :)):

-- MySQL dump 10.13  Distrib 5.5.28, for osx10.6 (i386)
--
-- Host: host    Database: database
-- ------------------------------------------------------
-- Server version   5.5.27-log

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `ACT_GE_BYTEARRAY`   
--

DROP TABLE IF EXISTS `ACT_GE_BYTEARRAY`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `ACT_GE_BYTEARRAY` (
  `ID_` varchar(64) COLLATE utf8_bin NOT NULL DEFAULT '',
  `REV_` int(11) DEFAULT NULL,
  `NAME_` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  `DEPLOYMENT_ID_` varchar(64) COLLATE utf8_bin DEFAULT NULL,
  `BYTES_` longblob,
  `GENERATED_` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`ID_`),
  KEY `ACT_FK_BYTEARR_DEPL` (`DEPLOYMENT_ID_`),
  CONSTRAINT `ACT_FK_BYTEARR_DEPL` FOREIGN KEY (`DEPLOYMENT_ID_`) REFERENCES     `ACT_RE_DEPLOYMENT` (`ID_`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `ACT_GE_PROPERTY`
--

DROP TABLE IF EXISTS `ACT_GE_PROPERTY`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;

等等。

我有 flyway 设置(简单的弹簧集成),它正在拾取文件。但是它什么也没做(不执行 sql):

INFO  @ 14 Mar 2013 22:34:41,646 @ com.googlecode.flyway.core.command.DbMigrate - Current version of schema "PUBLIC": << Empty Schema >>
INFO  @ 14 Mar 2013 22:34:41,647 @ com.googlecode.flyway.core.command.DbMigrate - Migrating schema "PUBLIC" to version 1
DEBUG @ 14 Mar 2013 22:34:41,649 @ com.googlecode.flyway.core.command.DbMigrate - Successfully completed and committed migration of schema "PUBLIC" to version 1
DEBUG @ 14 Mar 2013 22:34:41,651 @ com.googlecode.flyway.core.command.DbMigrate - Finished migrating schema "PUBLIC" to version 1 (execution time 00:00.002s)

但是,如果我在第一个 SQL 语句 ( DROP TABLE) 之前删除所有行,flyway 只会执行 drop 表并在之后停止。

DEBUG @ 14 Mar 2013 22:34:41,698 @ com.googlecode.flyway.core.dbsupport.SqlScript - Found statement at line 1: DROP TABLE IF EXISTS `ACT_GE_BYTEARRAY`
DEBUG @ 14 Mar 2013 22:34:41,698 @ com.googlecode.flyway.core.dbsupport.SqlScript - Executing SQL: DROP TABLE IF EXISTS `ACT_GE_BYTEARRAY`
DEBUG @ 14 Mar 2013 22:34:41,700 @ com.googlecode.flyway.core.command.DbMigrate - Successfully completed and committed migration of schema "PUBLIC" to version 1.1
DEBUG @ 14 Mar 2013 22:34:41,700 @ com.googlecode.flyway.core.command.DbMigrate - Finished migrating schema "PUBLIC" to version 1.1 (execution time 00:00.004s)

如果我删除所有到飞行路线的东西CREATE TABLE不喜欢语法

ERROR @ 14 Mar 2013 22:45:01,270 @ com.googlecode.flyway.core.command.DbMigrate - Caused by org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "CREATE TABLE ""ACT_GE_BYTEARRAY"" (
  ""ID_"" VARCHAR(64) COLLATE[*] UTF8_BIN NOT NULL DEFAULT '',

我怎样才能得到 mysqldump 的输出到 flyway 喜欢的东西?非常感谢你们!

4

1 回答 1

1

Flyway 的解析器是特定于数据库的。由于您尝试导入 H2,因此它会尝试解析 H2 语法而不是 mysql 语法。将其导入 mysql 数据库,你应该很高兴。

于 2013-03-15T07:24:36.270 回答