Updating rows in Liquibase with the complex WHERE clause

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 the old project, so we must stick to the old database, which has a terribly designed schema. The database does not use foreign key restrictions, so there are records pointing to a record that no longer exists. In my case, this is a doctor who has a bank account in a bank that is not in the database. So far, my team has dealt with these issues by overriding the identifier with NULL. So basically I try to set all bank account identifiers to NULL when the bank does not exist. The SQL code that I executed to complete 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 this patch into our Liquibase change lists, but I just can't figure out how to do this. 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>

Updating Liquibase is error-free, but when I look at the database afterwards, nothing has changed. Does anyone have pointers to me how to solve this problem?

+5
source share
1 answer

- , . . Liquibase , , . Liquibase , , , . , , , , SQL: UPDATE DOCTOR SET FK_BANKID = NULL WHERE FK_BANKID NOT IN (SELECT ID FROM BANK);. , , , , . Liquibase , . . , .

, , Liquibase . , :

<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>
        <rollback>
        </rollback>
    </changeSet>
</databaseChangeLog>
+7

All Articles