为什么在未指定更新时执行所有上下文?
Why are all contexts executed when non specified on update?
我正在使用 Liquibase 3.3.5 更新我的数据库。拥有上下文是一种只执行更改日志的特定部分的好方法。但我不明白,为什么在更新时没有提供上下文时执行所有变更集。考虑以下示例:
- 变更集 A:上下文=测试
- 变更集 B:无上下文
- 变更集 C: context=prod
所以
- 使用 context=test 执行更新,将执行变更集 A+B。
- 使用 context=prod 执行更新,将执行变更集 B+C。
- 在没有上下文的情况下执行更新,将执行变更集 A+B+C。
对我来说,这根本没有意义:)。
我希望只有变更集 B 会被执行,因为它没有定义特定的上下文。
在 Liquibase 上下文示例中:http://www.liquibase.org/documentation/contexts.html ("Using Contexts for Test Data") 他们说,应该使用 "test" 标记要测试的变更集,并通过提供上下文 [=] 来执行它们50=] 应用测试数据。很好-有道理。但是
"When it comes time to migrate your production database, don’t include the “test" 上下文,并且您的测试数据未包含在内。 “
因此,如果我在执行生产更新时不指定 "test" 上下文,它 也会 执行 "test" 变更集,因为我没有根本不指定上下文。
同样,我希望在更新执行时不进行测试,只会执行常规变更集 而没有 测试变更集。
或者我在这里遗漏了什么 :)?
这就是 Liquibase 的工作方式 - 如果您进行更新但未指定上下文,则所有变更集都将被视为适用于该更新操作。
有几种方法可以实现,开发团队必须选择一种。
- 如果您在更新操作期间未指定上下文,则
不考虑变更集。
- 如果您不指定上下文,则会考虑所有变更集。
- 如果您不指定上下文,则仅考虑没有上下文的变更集。
- 如果您没有指定上下文并且 none 的变更集有上下文,那么所有变更集都会被考虑,但如果一些变更集确实有上下文,请转到选项 1、2,或以上 3 个。
团队本可以选择选项 3(符合您的期望),但很久以前就决定选择选项 2,因为这在当时看起来像是 'best' 方式。那时我不在队里,所以我不知道更多。
对于@javg 来说可能为时已晚,但这可能会让未来的读者受益。
此要求可以通过以下方式实现:
changeset A: context=test
changeset B: context=all
changeset C: context=prod
所以
executing update with "context=test,all" will execute changeset A+B.
executing update with "context=all,prod" will execute changeset B+C.
executing update with "context=all" will only execute changeset B as you expect.
我将添加我的解决方案(从我的角度来看,默认的 Liquibase 行为不直观)。在我们处理 "problem" 的项目中,我们以这种方式配置了 liquibase 上下文:
liquibase.setChangeLog("classpath*:liquibase/master.xml");
contexts = StringUtils.isBlank(contexts) ? "none" : contexts;
liquibase.setContexts(contexts);
这导致 liquibase 将 运行 所有具有上下文的变更集 'none' 和所有默认变更集(没有上下文的变更集)- 是的,这就是它的工作方式。
所以 select 你的团队中没有人不会使用的名称('none' 在我们的例子中)作为上下文名称,然后 运行 默认情况下使用该上下文的 liquibase(看看例子)。使用这种方法,您将 运行 没有任何上下文的更改集我认为应该是默认方法!
I just mark the development changeSets as "dev" [or "test"] and don't specify a context on the changesets that run in both. When I do an update on production, I will specify contexts=prod in the update even though there are no changesets marked as prod. That will make it skip all the dev [or "test"] context ones but will still execute all the non-context-ed changeSets. You are also then set up for some point in the future where you need to make a context="prod" changeSet that ... only runs in prod.
来源:http://forum.liquibase.org/topic/using-context-for-development-only-and-production-changesets
如果您或您的管理员忘记指定上下文会怎样?是的,它会执行A+B+C,在一个产品上它可以破坏很多东西,让你的生活不那么幸福。
我正在寻找一种在这些情况下有益的解决方案,并在开始时中止 liquibase 执行(当您 运行 没有任何上下文的 liquibase 时)。
如果 liquibase 有一个 属性(在 liquibase.properties
中)来限制 运行 with/without 上下文,那就太好了...
作为解决方案,您可以将 contexts=default,contexts,of,your,project
添加到 liquibase.properties
文件。
我正在使用 Liquibase 3.3.5 更新我的数据库。拥有上下文是一种只执行更改日志的特定部分的好方法。但我不明白,为什么在更新时没有提供上下文时执行所有变更集。考虑以下示例:
- 变更集 A:上下文=测试
- 变更集 B:无上下文
- 变更集 C: context=prod
所以
- 使用 context=test 执行更新,将执行变更集 A+B。
- 使用 context=prod 执行更新,将执行变更集 B+C。
- 在没有上下文的情况下执行更新,将执行变更集 A+B+C。
对我来说,这根本没有意义:)。
我希望只有变更集 B 会被执行,因为它没有定义特定的上下文。
在 Liquibase 上下文示例中:http://www.liquibase.org/documentation/contexts.html ("Using Contexts for Test Data") 他们说,应该使用 "test" 标记要测试的变更集,并通过提供上下文 [=] 来执行它们50=] 应用测试数据。很好-有道理。但是
"When it comes time to migrate your production database, don’t include the “test" 上下文,并且您的测试数据未包含在内。 “
因此,如果我在执行生产更新时不指定 "test" 上下文,它 也会 执行 "test" 变更集,因为我没有根本不指定上下文。
同样,我希望在更新执行时不进行测试,只会执行常规变更集 而没有 测试变更集。
或者我在这里遗漏了什么 :)?
这就是 Liquibase 的工作方式 - 如果您进行更新但未指定上下文,则所有变更集都将被视为适用于该更新操作。
有几种方法可以实现,开发团队必须选择一种。
- 如果您在更新操作期间未指定上下文,则 不考虑变更集。
- 如果您不指定上下文,则会考虑所有变更集。
- 如果您不指定上下文,则仅考虑没有上下文的变更集。
- 如果您没有指定上下文并且 none 的变更集有上下文,那么所有变更集都会被考虑,但如果一些变更集确实有上下文,请转到选项 1、2,或以上 3 个。
团队本可以选择选项 3(符合您的期望),但很久以前就决定选择选项 2,因为这在当时看起来像是 'best' 方式。那时我不在队里,所以我不知道更多。
对于@javg 来说可能为时已晚,但这可能会让未来的读者受益。 此要求可以通过以下方式实现:
changeset A: context=test
changeset B: context=all
changeset C: context=prod
所以
executing update with "context=test,all" will execute changeset A+B.
executing update with "context=all,prod" will execute changeset B+C.
executing update with "context=all" will only execute changeset B as you expect.
我将添加我的解决方案(从我的角度来看,默认的 Liquibase 行为不直观)。在我们处理 "problem" 的项目中,我们以这种方式配置了 liquibase 上下文:
liquibase.setChangeLog("classpath*:liquibase/master.xml");
contexts = StringUtils.isBlank(contexts) ? "none" : contexts;
liquibase.setContexts(contexts);
这导致 liquibase 将 运行 所有具有上下文的变更集 'none' 和所有默认变更集(没有上下文的变更集)- 是的,这就是它的工作方式。
所以 select 你的团队中没有人不会使用的名称('none' 在我们的例子中)作为上下文名称,然后 运行 默认情况下使用该上下文的 liquibase(看看例子)。使用这种方法,您将 运行 没有任何上下文的更改集我认为应该是默认方法!
I just mark the development changeSets as "dev" [or "test"] and don't specify a context on the changesets that run in both. When I do an update on production, I will specify contexts=prod in the update even though there are no changesets marked as prod. That will make it skip all the dev [or "test"] context ones but will still execute all the non-context-ed changeSets. You are also then set up for some point in the future where you need to make a context="prod" changeSet that ... only runs in prod.
来源:http://forum.liquibase.org/topic/using-context-for-development-only-and-production-changesets
如果您或您的管理员忘记指定上下文会怎样?是的,它会执行A+B+C,在一个产品上它可以破坏很多东西,让你的生活不那么幸福。
我正在寻找一种在这些情况下有益的解决方案,并在开始时中止 liquibase 执行(当您 运行 没有任何上下文的 liquibase 时)。
如果 liquibase 有一个 属性(在 liquibase.properties
中)来限制 运行 with/without 上下文,那就太好了...
作为解决方案,您可以将 contexts=default,contexts,of,your,project
添加到 liquibase.properties
文件。