0
私はliquibaseスクリプトにはあまり慣れていません。他のテーブル要素に基づいてテーブル要素を削除するLiquibaseスクリプト
- 私は2つのテーブルtableAとtableBを持っています。
- tableBには、tableA_fk値を持つ要素が含まれています。これは、tableAの要素を指していることを意味します。
- tableAには、常に2つのグループに属する要素が含まれています。要素の1つが他の要素のpkを指しています(relatedpk)。
- フィールド "someValue"がNULLで、それを指すtableBの要素がないtableAのすべての要素を削除します。
- 要素が2つのだけ
例のグループによって除去することができる。この例では
tableA:
+----+---------------------+-----------+-----------+
| pk | name | someValue | relatedpk |
+----+---------------------+-----------+-----------+
| 1 | ElementA | 1 | NULL |
| 2 | ElementA | 1 | 1 |
| 3 | ElementB | NULL | NULL |
| 4 | ElementB | NULL | 3 |
| 5 | ElementC | 3 | NULL |
| 6 | ElementC | 3 | 5 |
| 7 | ElementD | NULL | NULL |
| 8 | ElementD | NULL | 7 |
| 9 | ElementE | NULL | NULL |
| 10 | ElementE | NULL | 9 |
+----+---------------------+-----------+-----------+
tableB:
+----+------------------------------+-----------+
| pk | name | tableA_fk |
+----+------------------------------+-----------+
| 1 | Value1 | 2 |
| 2 | Value2 | 3 |
| 3 | Value3 | 9 |
+----+------------------------------+-----------+
私にtableAからPK = 7,8でElementDを削除します。
理由:
ElementAを除去することができないので
someValue != null
ElementBを除去することができないので
tableA_fk = 3 for element Value2 in tableB
ElementCを除去することができない
someValue != null
ElemのためentDを除去することができるので、
someValue=NULL
No Element from tableB point to one of this two elements from tableA.
tableA_fk = 9 for element Value3 in tableB
はそれがLiquiBaseをスクリプトでそのような気にいらを実装することが可能であるため、ElementEを削除することはできませんか?その
<changeSet id="remove-elements">
<delete tableName="tableA">
<where>ConditionToRemoveTheCorrectELements</where>
</delete>
</changeSet>