I have never used Liquibase before and just can't figure out how to solve this problem. The project I recently joined is a remake of an old project, so we have to stick with an old database, which has an horribly designed schema. The database uses no foreign key constraints, so there are still entries that point to an entry that does not exist anymore. In my case it is an doctor having a bank account at a bank that does not exist in the database. The way my team handled these problems so far was overriding the ID with NULL. So basically what I am trying to do is to set all bank account IDs to NULL, when the bank is non-existent. The SQL code I made to accomplish this task is as follows:
UPDATE DOCTOR SET FK_BANKID = NULL WHERE FK_BANKID NOT IN (SELECT ID FROM BANK);
I was told to integrate that fix into our Liquibase changesets, but I just cannot figure out how to do it. This is what I have done so far:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<changeSet id="remove_fk_bankid" author="v7">
<update tableName="DOCTOR">
<column name="FK_BANKID" value="NULL" />
<where>FK_BANKID NOT IN (SELECT ID FROM BANK)</where>
</update>
</changeSet>
</databaseChangeLog>
The Liquibase update runs without errors, but when I look at the database afterwards, nothing has changed. Does anyone have any pointers for me how to solve this problem?