删除不存在的序列并创建现有用户时防止错误 [英] Prevent error when dropping not existing sequences, creating existing users

查看:124
本文介绍了删除不存在的序列并创建现有用户时防止错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆创建/删除序列,用户和其他对象的sql脚本.我正在通过liquibase运行这些脚本,但是它们失败了,因为当我尝试删除不存在的序列或创建现有用户时,oracle会抱怨.

I have a bunch of sql scripts that create / drop sequences, users and other objects. I'm running these scripts through liquibase, but they fail because oracle complains when I try to drop a non existing sequence, or create an existing user.

是否存在一种防止错误发生的预言方式?

Is there an oracle way to prevent errors from happening?

类似的东西

创建用户/序列(如果不存在)

Create User / Sequence if not exists

删除用户/安全性(如果存在)

Drop User/ Secuence if exists

据我所知,我有以下选择:

As far as I know, I have these options:

  • 编写plsql脚本
  • 使用liquibase上下文.
  • 使用liquibase前提条件,但这将意味着过多的工作.

任何想法/想法都将不胜感激.

Any thoughts / ideas will be greatly appreciated.

推荐答案

Liquibase具有failOnError属性,您可以在包含可能失败的调用的changeSet上将其设置为false.

Liquibase has a failOnError attribute you can set to false on changeSets that include a call that could fail.

<changeSet failOnError="false">
   <createSequence sequenceName="new_sequence"/>
</changeSet>

这使您可以拥有简单的创建用户,创建序列,删除用户和删除序列changeSet,并且如果该语句由于用户/序列存在/不存在而引发错误,它们仍将被标记为已运行并进行更新将继续.

This allows you to have simple create user, create sequence, drop user, and drop sequence changeSets and if the statement throws an error because they users/sequences exist/don't exist they will still be marked as ran and the update will continue.

此方法的缺点是,如果它们由于其他原因(错误的权限,连接失败,无效的SQL等)而出错,也会将它们标记为已运行并继续运行.更准确的方法是使用前提条件,例如:

The downside of this approach is that it will also mark them as ran and continue if they error for some other reason (bad permissions, connection failure, invalid SQL, etc.) The more accurate approach is to use preconditions, like this:

<changeSet>
   <preconditions onFail="MARK_RAN"><not><sequenceExists/></not></preconditions>
   <createSequence name="new_sequence"/>
</changeSet>

当前没有userExists前提条件,但是您可以创建自定义前提条件或退回到该前提条件.请参阅 http://www.liquibase.org/documentation/preconditions.html 以获取文档

There is no userExists precondition currently, but you can create custom preconditions or fall back to the precondition. See http://www.liquibase.org/documentation/preconditions.html for documentation

这篇关于删除不存在的序列并创建现有用户时防止错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆