liquibase,maven中文教程1

系列文章目录

提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加
例如:第一章 Python 机器学习入门之pandas的使用


提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 系列文章目录
  • 前言
  • 一、maven命令说明
    • 1. mvn liquibase:changelogSync
    • 2. changelogSyncSQL
    • 3.changelogSyncToTag
    • 4.dbDoc
    • 5.update
    • 6.updateSQL
    • 7.updateTestingRollback
    • 8.tag


前言

liquibase maven 使用教程
官网地址


update 更新changelog 到数据库
generateChangeLog 把数据库的状态同步到changelog
liquibase 目前只适用与开发和测试环境

一、maven命令说明

1. mvn liquibase:changelogSync

changelogSync 更新 DATABASECHANGELOG 表以将所有未应用于数据库的更改标记为已执行

理解:

1.空的数据库,使用changelogSync|changelogSyncSql DATABASECHANGELOG如果不存在会新建DATABASECHANGELOG表,如果存在则不会做任何操作
2.如果有一些变更只在dev 环境,不会部署到测试环境,可以使用这个命令

官方原文:
changelogSync is typically used when you want to baseline a new database environment.

changelogSync 通常用于为新的数据库环境建立基线时。

An example use case for the changelogSync goal is when you have a DEV environment with a set of objects used only in DEV, and you want to use the same changelog to manage a new TEST environment.

changelogSync 目标的一个示例用例是当您有一个 DEV 环境,其中包含一组仅在 DEV 中使用的对象,并且您希望使用相同的变更日志来管理新的 TEST 环境。

The TEST environment does not have or need those DEV only objects. To avoid deploying the DEV only objects, you can run the changelogSync goal to mark those changes as executed in the DATABASECHANGELOG which tells Liquibase to treat these databases as equivalent.

TEST 环境没有或不需要那些仅限 DEV 的对象。为了避免仅部署 DEV 对象,您可以运行 changelogSync 目标以将这些更改标记为在 DATABASECHANGELOG 中执行,这告诉 Liquibase 将这些数据库视为等效的。 如果与更改关联的对象是在数据库上手动创建的

You can also use the changelogSync goal to mark a change as executed if the object associated with the change was created manually on the database. By marking the changeset as executed, it prevents the next Liquibase update from failing as it tries to create an object that already exists.

您还可以使用 changelogSync 目标将changeset 更改标记为已执行。通过将changeset 标记为已执行,它可以防止下一次 Liquibase update 在创建已存在的对象时失败。

2. changelogSyncSQL

mvn liquibase:changelogSyncSQL

changelogSyncSQL is typically used when you want to inspect the SQL Liquibase will use to baseline a new database environment and update the DATABASECHANGELOG table to mark all changes that are not applied to the database as executed.

changelogSyncSQL 通常用于检查 Liquibase 将用于建立新数据库环境基线并更新 DATABASECHANGELOG 表以将所有未应用于数据库的更改标记为已执行的 SQL

It is best practice to inspect any SQL that Liquibase would run when using the changelogSync goal so you can review any changes the goal would make to your database before running the goal.

最佳做法是检查 Liquibase 在使用 changelogSync 目标时将运行的任何 SQL,以便您可以在运行目标之前查看目标对数据库所做的任何更改

3.changelogSyncToTag

mvn liquibase:changelogSyncToTag -Dliquibase.toTag=version_2.0

You have a DEV environment with a set of objects used only in DEV, and you want to use the same changelog to manage a new TEST environment. The TEST environment does not have those DEV-only objects and needs only some of them.
To deploy the needed DEV-only objects and avoid deploying the rest, you add a tag and run the changelogSyncToTag goal to mark the changes related to that tag as executed in the DATABASECHANGELOG table.
The goal marks all changesets starting with the first changeset at the top of the DEV changelog file and moving down to the changesets up to and including the tag.
Next, you deploy the changesets that were not marked as deployed in your database. Liquibase treats your DEV and TEST databases as equivalent.

4.dbDoc

mvn dbDoc

基于现有数据库和变更日志生成文档

5.update

mvn liquibase:update

理解:跟新changelog 到数据库

6.updateSQL

mvn liquibase:updateSQL

理解:检查sql ,并不会去应用
updateSQL is typically used when you want to inspect the raw SQL before running the update goal, so you can correct any issues that may arise before running the goal. Liquibase uses the raw SQL to apply changes that you have added to the changelog file to your database.
当您想在运行更新命令之前检查原始 SQL 时,通常会使用 updateSQL,这样您就可以在运行命令之前更正可能出现的任何问题。 Liquibase 使用原始 SQL 将您添加到更改日志文件中的更改应用到数据库

7.updateTestingRollback

mvn liquibase:updateTestingRollback

updateTestingRollback is typically used when you want to test rollback functionality when deploying changesets in your changelog sequentially. Run updateTestingRollback only when all pending changelogs have been verified as ready to be deployed as you cannot specify changesets to exclude.

updateTestingRollback utilizes a multi-step operation and runs in sequential order:

update changeset1; update changeset2; update changeset3
rollback changeset3; rollback changeset2; rollback changeset1
update changeset1; update changeset2 update changeset3

8.tag

mvn liquibase:tag -Dliquibase.tag=myTag

标记标记当前数据库状态,以便您可以在将来回滚或部署更改。

你可能感兴趣的:(java自动化,maven)