如何扩展Liquibase以使用存储过程,函数和触发器生成更改日志? [英] How to extend Liquibase to generate change logs with stored procedures, functions and triggers?
问题描述
当前,当您尝试在现有数据库上生成更改日志时,Liquibase有一些限制.它不会导出以下类型的对象:
Currently Liquibase has some limitations when you try to generate change logs on an existing database. It does not export the following types of objects:
- 存储过程,函数,程序包
- 触发器
- 类型
参考: http://www.liquibase.org/documentation/generating_changelogs.html
据我了解,我需要开发自己的liquibase.snapshot.SnapshotGenerator
实现.我知道如何从Oracle获取这些类型的对象,但是我对如何从Liquibase实现此类接口有些迷惑.
As far as I understand I need to develop my own liquibase.snapshot.SnapshotGenerator
implementation. I know how to obtain these types of objects from Oracle but I'm a bit lost on how to implement such interface from Liquibase.
理想情况下,我想还应该扩展liquibase.database.Database
接口以添加以下额外方法:
Ideally I guess the liquibase.database.Database
interface should be also extended to add the following extra methods:
-
public abstract boolean supportsPackages();
-
public abstract boolean supportsFunctions();
-
public abstract boolean supportsStoredProcedures();
-
public abstract boolean supportsTriggers();
-
public abstract boolean supportsTypes();
public abstract boolean supportsPackages();
public abstract boolean supportsFunctions();
public abstract boolean supportsStoredProcedures();
public abstract boolean supportsTriggers();
public abstract boolean supportsTypes();
推荐答案
您正确的总体策略是创建一个实现SnapshotGenerator的新类,但是您还需要执行其他几个步骤.常规快照过程为:
You are right that the general strategy is to create a new class that implements SnapshotGenerator, but there are a couple other steps you need to do as well. The general snapshot process is:
- Liquibase搜索SnapshotGenerator的实现,并为其在数据库中找到的每个对象调用addTo().对于您的类型,您可能需要快速的如果已通过架构的对象实例",因为它们是架构的一部分.
- 您将需要创建实现DatabaseObject的新Package,StoredProcedure等对象.它们将是liquibase.structure.core.Table类,并捕获对象的状态.它们是在您的SnapshotGenerator.addsTo()方法中创建的,可以被识别(名称,架构等)
- 然后,通过addTo()方法添加的所有对象都将通过您的SnapshotGenerator.snapshotObject()方法运行,该方法将提取您最初未获取的任何其他元数据,例如存储过程文本等.
- 一旦liquibase有一个包含您的对象的快照,它将快照与另一个快照(在generateChangeLog情况下为空快照)进行比较,以确定第二个快照中哪些对象丢失,意外和更改.然后,它将查找MissingObjectChangeGenerator,UnexpectedObjectChangeGenerator和ChangedObjectChangeGenerator的实现.对于generateChangeLog,只有丢失"的对象,因此您将实现MissingTriggerChangeGenerator,MissingPackagedChangeGenerator等.它们的工作是创建Change实例以创建丢失的对象
- Msising * ChangeGenerator类可以返回RawSqlChange实例,也可以创建Change的新实现,例如CreateTriggerChange.
这篇关于如何扩展Liquibase以使用存储过程,函数和触发器生成更改日志?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!