For some reason, this problem went away: I ran into a lot of issues when trying to run the new changesets on PostgreSQL and after correcting all of the issues I was able to add the offending <dropView> without any issues.
What I did
- The error message came when I was trying to drop the userid column. Liquibase failed, because the userid colum was used by something else
- I had already dropped the fk constraints from the column to userid in the users table
- I dropped the index on the userid colum, then I got complaints from two other views using the column
-
I dropped the views (I was no longer using them anyway)
- <changeSet author="sb" id="drop-views-linking-to-account-user_id">
- <dropView viewName="wage_payments_view" />
- <dropView viewName="work_done_view" />
- </changeSet>
- I now got an error message saying that the accounts_view was still using the column
-
I put in the <dropView> that had failed earlier, and expected it to fail, except it didn't
- <changeSet author="sb" id="drop-accounts-view">
- <dropView viewName="accounts_view" />
- </changeSet>
- Now I could run the changelog on PostgreSQL without errors (including dropping the userid column from the accounts table), so I tried running it on derby, and this time removing the view didn't fail
-
So I put in a new and updated view without the userid column and this worked fine
- <changeSet author="sb" id="create-new-accountsview">
- <createView fullDefinition="false" viewName="accounts_view">
- select accounts.account_id, accounts.username, first_name, last_name, SUM(transaction_amount) as balance
- from users
- join accounts on accounts.username=users.username
- join transactions on transactions.account_id=accounts.account_id
- group by accounts.account_id, accounts.username, first_name, last_name
- </createView>
- </changeSet>
-
Now I'm trying to remove the view completely and I'm again told the view doesn't exist
- <changeSet author="sb" id="drop-accounts-view-for-good">
- <dropView viewName="accounts_view" />
- </changeSet>
- The accounts_view, with the new username column in the accounts table, obviously exists when code is running, if not, the code would have failed at an early stage
- I thought it might have something to do with transactions used by the liquibase setup (when running in derby in memory, in test situations, I always set the database up from scratch) so I tried running the <dropView> from a separate <databaseChangelog> in a different file, but I still got the accounts_view not found
-
I added a conditional to the <changeSet> removing the accounts_view
- <changeSet author="sb" id="drop-accounts-view-for-good">
- <preConditions onFail="CONTINUE" >
- <not>
- <viewExists viewName="accounts_view" />
- </not>
- </preConditions>
- <dropView viewName="accounts_view" />
- </changeSet>
- Now I didn't get any errors when running the <changeLog> in derby, but the count of sucessful changeSets stayed the same
-
I tried running the changelog in PostgreSQL again and here also it didn't fail, but I found the following in the log
- 2019-03-29T23:48:39,634 | INFO | features-1-thread-1 | liquibase | 134 - org.liquibase.core - 3.5.3 | db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-accounts-view-for-good::sb: Continuing past: db-changelog/db-changelog-1.0.0.xml::drop-accounts-view-for-good::sb despite precondition failure due to onFail='CONTINUE':
- db-changelog/db-changelog-1.0.0.xml : Not precondition failed
- I thought it might have been the other blockers for removing userid that masked <dropView> of accounts the first time I tried, but now I don't know what would be the candidates for such a masking? (I don't know why the index on the userid column and the other two views would mask accounts_view in the first place)