我是liquibase的新手,想要在生产中使用它来管理数据库。虽然这是一个小应用程序,但与其通过手动创建模式,我希望使用更专业的工具,比如liquibase。
我计划在当前生产环境下的模式和新应用程序所需的模式之间制作一个changelog。我已经按照许多教程的指导操作过了,但似乎还有些缺失。生成的changelog.xml始终导入所有模式,没有体现和现有的差异。我看到liquibase必须创建DATABASECHANGELOG表,但我在我的电脑上找不到它们。
我的操作如下:
- 将当前生产数据库转储并导入开发计算机
- 从核心项目添加了liquibase.properties,并运行以下命令:mvn clean resources:resources liquibase:generateChangeLog
- 它生成了一个包含所有模式的master.xml,但没有在数据库中创建DATABASECHANGELOG表(当注释outputChangeLogFile时会创建DATABASECHANGELOGLOCK表,并且LOCKED值为0)
- 从http://www.liquibase.org/databases.html手动创建了DATABASECHANGELOG表
- 重新运行mvn liquibase:generateChangeLog命令,但仍然没有结果
pom.xml:
<dependencies>
...
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.17</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
</dependencies>
<!-- edited build after 1st comment. Still got the problem -->
<build>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase.version}</version>
<configuration>
<promptOnNonLocalDatabase>true</promptOnNonLocalDatabase>
<changeLogFile>${project.build.directory}/classes/changelog/db.changelog-master.xml</changeLogFile>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
</configuration>
</plugin>
</plugins>
</build>
<!--- old section build, left for history purpose --->
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase.version}</version>
<configuration>
<promptOnNonLocalDatabase>true</promptOnNonLocalDatabase>
<changeLogFile>${project.build.directory}/classes/changelog/db.changelog-master.xml</changeLogFile>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
liquibase.properties :
liquibase.properties文件:url=jdbc:mysql://localhost:3306/my_db
username=user
password=pass
driver=com.mysql.jdbc.Driver
outputChangeLogFile=src/main/resources/liquibase/master.xml
NB: 在评论outputChangeLogFile时,liquibase创建了表DATABASECHANGELOGLOCK,但仅限于此表。
maven输出:
[INFO] ------------------------------------------------------------------------
[INFO] Building -CORE 0.0.2
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- liquibase-maven-plugin:3.5.3:generateChangeLog (default-cli) @ EDI-CORE ---
[INFO] ------------------------------------------------------------------------
[INFO] Parsing Liquibase Properties File
[INFO] File: src/main/resources/liquibase.properties
[INFO] 'classpath' in properties file is not being used by this task.
[INFO] ------------------------------------------------------------------------
[INFO] Executing on Database: jdbc:mysql://localhost:3306/my_db
[INFO] Generating Change Log from database root@localhost @ jdbc:mysql://localhost:3306/my_db (Default Schema: edi)
INFO 17/01/17 15:01: liquibase: src\main\resources\liquibase\master.xml exists, appending
WARNING 17/01/17 15:01: liquibase: MySQL does not support a timestamp precision of '19' - resetting to the maximum of '6'
WARNING 17/01/17 15:01: liquibase: MySQL does not support a timestamp precision of '19' - resetting to the maximum of '6'
WARNING 17/01/17 15:01: liquibase: MySQL does not support a timestamp precision of '19' - resetting to the maximum of '6'
[INFO] Output written to Change Log file, src/main/resources/liquibase/master.xml
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
<pluginManagement>
,请查看链接的问题以了解行为和修复方法。 - Tunaki