Liquibase - common columns?

我是研究僧i 提交于 2020-01-04 10:35:06

问题


In my db every table has 4 common columns - DATE_CREATED, USER_CREATED, DATE_MODIFIED, USER_MODIFIED, and I want to propagate this rule to all new tables implicitly.

Is it possible to do it without having to generate liquibase script manually?


回答1:


This is not possible using liquibase (as far as I know).

The reason for this is simple:

What if you change your mind and add/remove one of the default columns later? If you want to change all tables then this is not possible with liquibase as this would mean changing all changesets, which is not allowed.

Use a DSL to generate your liquibase scripts then you can add a certain set of columns to every entity but an automatic way would be difficult with the way liquibase works.




回答2:


There is nothing built into Liquibase to support this.

Your easiest option would be to use XML document entities which is purely XML-level and therefore transparent to Liquibase. They would allow you to attach common XML into your changelog files.

A more complex approach would be to use the Liquibase extension system (http://liquibase.org/extensions) which allows you to redefine the logic to convert changeSets into SQL. That would allow you to inject any logic you want, including common data types, standard columns, or anything else.




回答3:


I do not think so.

My suggesion, Dont add above mentioned 4 columns in all tables because there are possible to keep null values in all table for existing entries.

please create a table like Primary key id, table or entity name and your four column name.



来源:https://stackoverflow.com/questions/25840467/liquibase-common-columns

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!