1

我一直在关注这个家伙页面,以获取 Liquibase 设置(http://bytefilia.com/managing-database-schema-changes-liquibase-existing-schema/),至少包含我的基表和数据。我已经成功运行

./liquibase --driver=com.mysql.jdbc.Driver \
--classpath=lib/mysql-connector-java-5.1.34-bin.jar \
--changeLogFile="../data/database/boot.json" \
--url="jdbc:mysql://localhost/tester" \
--username=root \
--password=password \
--logLevel=debug \
generateChangeLog

我这样做了两次,一次用于表结构,一次用于数据。

./liquibase --driver=com.mysql.jdbc.Driver \
--classpath=lib/mysql-connector-java-5.1.34-bin.jar \
--changeLogFile="../data/database/base-data.json" \
--url="jdbc:mysql://localhost/tester" \
--username=root \
--password=password \
--logLevel=debug \
--diffTypes="data"  
generateChangeLog

它生成文件 boot.json 和 base-data.json。这些文件似乎很好,至少将它们与其他网站和 liquibase 文件进行比较。我发现的唯一问题是数据文件的日期时间戳会生成一个关于 ":" 的错误,但是如果我将它们包装在引号中,liquibase 运行并 syas 它成功地做到了。虽然当我检查数据库时,我只有 2 个表。

DATABASECHANGELOG
DATABASECHANGELOGLOCK

如果我查看 DATABASECHANGELOG 内部,它会在运行同步命令后包含来自两个文件的所有提交。但它没有我需要的任何表格,当然也没有数据。我想也许它不会显示作为版本控制的表,所以我尝试了一个常规的选择语句。

select * from ua_auth_user;
ERROR 1146 (42S02): Table 'tester.ua_auth_user' doesn't exist

任何帮助都很棒。我需要做什么才能让 liquibase 使用我导出的数据从新数据库中生成我的模式。如果我在获取数据和表结构时做错了什么,我会更改它。在尝试主要开发之前,我只是按照说明启动并运行一个工作示例。

---更新(根据 Nathan Voxland 的建议)

我删除了除了一张桌子以外的所有桌子。我删除了数据库并创建了一个全新的数据库。然后我运行下面的命令。

引导.json

{ "databaseChangeLog": [
  {
    "changeSet": {
      "id": "1",
      "author": "lumberjacked",
      "changes": [
        {
          "createTable": {
            "columns": [
              {
                "column": {
                  "autoIncrement": true,
                  "constraints": {
                  "constraints": {
                      "primaryKey": true
                }
              },
              "name": "id",
              "type": "INT"
            }
          },
          {
            "column": {
              "name": "subject_category_id",
              "type": "INT"
            }
          },
          {
            "column": {
              "name": "subject",
              "type": "VARCHAR(50)"
            }
          },
          {
            "column": {
              "name": "label",
              "type": "VARCHAR(50)"
            }
          }]
        ,
        "tableName": "common__subjects"
      }
    }]

    }
  }

]}

命令

➜  liquibase-bin git:(test) ✗ ./liquibase
   --driver=com.mysql.jdbc.Driver 
   --classpath=lib/mysql-connector-java-5.1.34-bin.jar 
   --changeLogFile="../data/database/boot.json" 
   --url="jdbc:mysql://localhost/tester" 
   --username=root 
   --password=password 
   --logLevel=debug update

错误信息

Unexpected error running Liquibase:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Incorrect
table definition; there can be only one auto column and it must be
defined as a key

SEVERE 1/18/15 4:05 PM: liquibase:
../data/database/boot.json::1::lumberjacked:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Incorrect
table definition; there can be only one auto column and it must be
defined as a key       
4

2 回答 2

2

您需要检查正在生成的文件。由于某种原因,liquibase 错误地生成了您的 json。查看您的文件后,您需要执行以下操作:

原来的

"column": {
    "autoIncrement": true,
    "constraints": {
        "constraints": {
            "primaryKey": true
        }
    }
} 

更正

"column": {
    "autoIncrement": true,
    "constraints": {
        "primaryKey": true
    }
}
于 2015-01-19T14:27:20.180 回答
1

当我出于某种原因导出数据时,liquibase 生成了错误的 json,但它并非无效的 json 只是错误并包装了两次约束。我不知道它是否应该是这种方式,但在删除第二个约束后它生成了所有表。在去除底部的唯一和外部约束后,我的表格文件大约有 4000 行。所以我不完全确定json中没有更多错误。

生成错误

"column": {
    "autoIncrement": true,
    "constraints": {
        "constraints": {
            "primaryKey": true
        }
    } 

更正

"column": {
    "autoIncrement": true,
    "constraints": {
        "primaryKey": true
    }
}
于 2015-01-19T03:11:19.577 回答