executeCommand - Oracle 'sqlplus'
Functions, Stored Proc, and the Like
We are using the best practice approach where we have one master changelog file per schema and from there we reference a new changelog file per new release.
```
It occurs to me that maybe the right approach for having an individual sqlFile per function/stored proc would be to have a single include that would look something like this:
```
And in there, I'd have a bunch of changeSets that reference the individual sqlFiles and then any time one of the referenced sqlFiles changes, the changeSet would be reapplied. Is that how it would work?
```
<?xml version="1.0" encoding="UTF-8"?>
Unable to (view not found)
- SEVERE 3/23/19 11:12 PM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-existing-accountsview::sb: Change Set db-changelog/db-changelog-1.0.0.xml::drop-existing-accountsview::sb failed. Error: Table/View 'APP.ACCOUNTS_VIEW' does not exist. [Failed SQL: DROP VIEW APP.accounts_view]
- <?xml version="1.0" encoding="UTF-8" standalone="no"?>
- <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">
- <!-- Copyright 2016-2019 Steinar Bang -->
- <!-- -->
- <!-- Licensed under the Apache License, Version 2.0 (the "License"); -->
- <!-- you may not use this file except in compliance with the License. -->
- <!-- You may obtain a copy of the License at -->
- <!-- http://www.apache.org/licenses/LICENSE-2.0 -->
- <!-- Unless required by applicable law or agreed to in writing, -->
- <!-- software distributed under the License is distributed on an "AS IS" BASIS, -->
- <!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
- <!-- See the License for the specific language governing permissions and limitations -->
- <!-- under the License. -->
- <changeSet author="sb" id="ukelonn-1.0.0">
- <createTable tableName="users">
- <column autoIncrement="true" name="user_id" type="INTEGER">
- <constraints primaryKey="true" primaryKeyName="SQL170518210719000"/>
- </column>
- <column name="username" type="VARCHAR(64)">
- <constraints nullable="false"/>
- </column>
- <column name="password" type="VARCHAR(64)">
- <constraints nullable="false"/>
- </column>
- <column name="salt" type="VARCHAR(64)">
- <constraints nullable="false"/>
- </column>
- <column name="email" type="VARCHAR(64)">
- <constraints nullable="false"/>
- </column>
- <column name="first_name" type="VARCHAR(256)">
- <constraints nullable="false"/>
- </column>
- <column name="last_name" type="VARCHAR(256)">
- <constraints nullable="false"/>
- </column>
- </createTable>
- <createTable tableName="transaction_types">
- <column autoIncrement="true" name="transaction_type_id" type="INTEGER">
- <constraints primaryKey="true" primaryKeyName="SQL170518210719080"/>
- </column>
- <column name="transaction_type_name" type="VARCHAR(256)">
- <constraints nullable="false"/>
- </column>
- <column name="transaction_amount" type="DOUBLE"/>
- <column defaultValueBoolean="false" name="transaction_is_work" type="BOOLEAN">
- <constraints nullable="false"/>
- </column>
- <column defaultValueBoolean="false" name="transaction_is_wage_payment" type="BOOLEAN">
- <constraints nullable="false"/>
- </column>
- </createTable>
- <createTable tableName="administrators">
- <column autoIncrement="true" name="administrator_id" type="INTEGER">
- <constraints primaryKey="true" primaryKeyName="SQL170518210719121"/>
- </column>
- <column name="user_id" type="INTEGER">
- <constraints nullable="false"/>
- </column>
- </createTable>
- <createIndex indexName="SQL170518210719120" tableName="administrators">
- <column name="user_id"/>
- </createIndex>
- <addForeignKeyConstraint baseColumnNames="user_id" baseTableName="administrators" constraintName="SQL170518210719120" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="user_id" referencedTableName="users"/>
- <createTable tableName="accounts">
- <column autoIncrement="true" name="account_id" type="INTEGER">
- <constraints primaryKey="true" primaryKeyName="SQL170518210719041"/>
- </column>
- <column name="user_id" type="INTEGER"/>
- </createTable>
- <createIndex indexName="SQL170518210719040" tableName="accounts">
- <column name="user_id"/>
- </createIndex>
- <addForeignKeyConstraint baseColumnNames="user_id" baseTableName="accounts" constraintName="SQL170518210719040" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="user_id" referencedTableName="users"/>
- <createTable tableName="transactions">
- <column autoIncrement="true" name="transaction_id" type="INTEGER">
- <constraints primaryKey="true" primaryKeyName="SQL170518210719092"/>
- </column>
- <column name="account_id" type="INTEGER">
- <constraints nullable="false"/>
- </column>
- <column name="transaction_type_id" type="INTEGER">
- <constraints nullable="false"/>
- </column>
- <column name="transaction_time" type="TIMESTAMP" defaultValueComputed="CURRENT_TIMESTAMP">
- <constraints nullable="false"/>
- </column>
- <column name="transaction_amount" type="DOUBLE">
- <constraints nullable="false"/>
- </column>
- </createTable>
- <createIndex indexName="SQL170518210719090" tableName="transactions">
- <column name="account_id"/>
- </createIndex>
- <createIndex indexName="SQL170518210719091" tableName="transactions">
- <column name="transaction_type_id"/>
- </createIndex>
- <addForeignKeyConstraint baseColumnNames="account_id" baseTableName="transactions" constraintName="SQL170518210719090" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="account_id" referencedTableName="accounts"/>
- <addForeignKeyConstraint baseColumnNames="transaction_type_id" baseTableName="transactions" constraintName="SQL170518210719091" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="transaction_type_id" referencedTableName="transaction_types"/>
- <createView fullDefinition="false" viewName="accounts_view">select accounts.account_id, users.user_id, username, first_name, last_name, SUM(transaction_amount) as balance
- from users
- join accounts on accounts.user_id=users.user_id
- join transactions on transactions.account_id=accounts.account_id
- group by accounts.account_id, users.user_id, username, first_name, last_name</createView>
- <createView fullDefinition="false" viewName="administrators_view">select administrators.administrator_id, users.user_id, username, first_name, last_name
- from users
- join administrators on administrators.user_id=users.user_id
- group by administrators.administrator_id, users.user_id, username, first_name, last_name</createView>
- <createView fullDefinition="false" viewName="wage_payments_view">select accounts.account_id, users.user_id, username, transaction_time, transaction_type_name, ABS(transactions.transaction_amount) as transaction_amount
- from users
- join accounts on accounts.user_id=users.user_id
- join transactions on transactions.account_id=accounts.account_id
- join transaction_types on transaction_types.transaction_type_id=transactions.transaction_type_id and transaction_is_wage_payment
- order by transaction_time desc</createView>
- <createView fullDefinition="false" viewName="work_done_view">select accounts.account_id, users.user_id, username, transaction_time, transaction_type_name, transactions.transaction_amount
- from users
- join accounts on accounts.user_id=users.user_id
- join transactions on transactions.account_id=accounts.account_id
- join transaction_types on transaction_types.transaction_type_id=transactions.transaction_type_id and transaction_is_work
- order by transaction_time desc</createView>
- </changeSet>
- <changeSet author="sb" id="add-username-to-account-table">
- <addColumn tableName="accounts">
- <column name="username" type="VARCHAR(64)" />
- </addColumn>
- </changeSet>
- <changeSet author="sb" id="insert-usernames-in-accounts-table">
- <sql>update accounts set username=(select u.username from users u join accounts a on u.user_id=a.user_id)</sql>
- </changeSet>
- <changeSet author="sb" id="give-users-username-an-uniqueness-constraint">
- <addUniqueConstraint tableName="users" columnNames="username" />
- </changeSet>
- <changeSet author="sb" id="add-foreign-key-constraint-from-accounts-to-users">
- <addForeignKeyConstraint baseTableName="accounts" baseColumnNames="username" constraintName="fk_account_username" referencedColumnNames="username" referencedTableName="users" />
- </changeSet>
- <changeSet author="sb" id="drop-old-foreign-key-constraint-from-accounts-to-users">
- <dropForeignKeyConstraint baseTableName="accounts" constraintName="SQL170518210719040" />
- </changeSet>
- <changeSet author="sb" id="drop-column-userid-from-accounts">
- <dropColumn tableName="accounts" columnName="user_id" />
- </changeSet>
- <changeSet author="sb" id="drop-existing-accountsview">
- <dropView viewName="accounts_view" />
- </changeSet>
- <changeSet author="sb" id="create-new-accountsview">
- <createView fullDefinition="false" viewName="accounts_view">
- select accounts.account_id, users.user_id, 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, users.user_id, username, first_name, last_name
- </createView>
- </changeSet>
- </databaseChangeLog>
State of liquibase cassandra
Re : State of liquibase cassandra
Re : Unable to (view not found)
- 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)
Re : Unable to (view not found)
- INFO 3/30/19 11:26 AM: liquibase: Successfully acquired change log lock
- INFO 3/30/19 11:26 AM: liquibase: Creating database history table with name: APP.DATABASECHANGELOG
- INFO 3/30/19 11:26 AM: liquibase: Reading from APP.DATABASECHANGELOG
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: Table users created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: Table transaction_types created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: Table administrators created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: Index SQL170518210719120 created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: Foreign key constraint added to administrators (user_id)
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: Table accounts created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: Index SQL170518210719040 created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: Foreign key constraint added to accounts (user_id)
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: Table transactions created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: Index SQL170518210719090 created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: Index SQL170518210719091 created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: Foreign key constraint added to transactions (account_id)
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: Foreign key constraint added to transactions (transaction_type_id)
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: View accounts_view created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: View administrators_view created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: View wage_payments_view created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: View work_done_view created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::ukelonn-1.0.0::sb ran successfully in 76ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::add-username-to-account-table::sb: Columns username(VARCHAR(64)) added to accounts
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::add-username-to-account-table::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::add-username-to-account-table::sb ran successfully in 36ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::add-username-index-to-accounts-table::sb: Index accounts-username-index created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::add-username-index-to-accounts-table::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::add-username-index-to-accounts-table::sb ran successfully in 3ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::insert-usernames-in-accounts-table::sb: Custom SQL executed
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::insert-usernames-in-accounts-table::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::insert-usernames-in-accounts-table::sb ran successfully in 5ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::give-users-username-an-uniqueness-constraint::sb: Unique constraint added to users(username)
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::give-users-username-an-uniqueness-constraint::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::give-users-username-an-uniqueness-constraint::sb ran successfully in 7ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::add-foreign-key-constraint-from-accounts-to-users::sb: Foreign key constraint added to accounts (username)
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::add-foreign-key-constraint-from-accounts-to-users::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::add-foreign-key-constraint-from-accounts-to-users::sb ran successfully in 7ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-old-foreign-key-constraint-from-accounts-to-users::sb: Foreign key SQL170518210719040 dropped
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-old-foreign-key-constraint-from-accounts-to-users::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::drop-old-foreign-key-constraint-from-accounts-to-users::sb ran successfully in 7ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-old-index-from-accounts-userid-to-users::sb: Index SQL170518210719040 dropped from table accounts
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-old-index-from-accounts-userid-to-users::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::drop-old-index-from-accounts-userid-to-users::sb ran successfully in 3ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-views-linking-to-account-user_id::sb: View wage_payments_view dropped
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-views-linking-to-account-user_id::sb: View work_done_view dropped
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-views-linking-to-account-user_id::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::drop-views-linking-to-account-user_id::sb ran successfully in 6ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-accounts-view::sb: View accounts_view dropped
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-accounts-view::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::drop-accounts-view::sb ran successfully in 2ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-column-userid-from-accounts::sb: Column accounts.user_id dropped
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-column-userid-from-accounts::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::drop-column-userid-from-accounts::sb ran successfully in 6ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::create-new-accountsview::sb: View accounts_view created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::create-new-accountsview::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::create-new-accountsview::sb ran successfully in 5ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::add-username-column-to-administrators-table::sb: Columns username(VARCHAR(64)) added to administrators
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::add-username-column-to-administrators-table::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::add-username-column-to-administrators-table::sb ran successfully in 3ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::add-username-index-to-administrators-table::sb: Index administrators-username-index created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::add-username-index-to-administrators-table::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::add-username-index-to-administrators-table::sb ran successfully in 2ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::add-foreign-key-constraint-from-administrators-to-users::sb: Foreign key constraint added to administrators (username)
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::add-foreign-key-constraint-from-administrators-to-users::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::add-foreign-key-constraint-from-administrators-to-users::sb ran successfully in 6ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::insert-usernames-in-administrators-table::sb: Custom SQL executed
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::insert-usernames-in-administrators-table::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::insert-usernames-in-administrators-table::sb ran successfully in 7ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-administrators-view::sb: View administrators_view dropped
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-administrators-view::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::drop-administrators-view::sb ran successfully in 1ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-old-foreign-key-constraint-from-administrators-to-users::sb: Foreign key SQL170518210719120 dropped
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-old-foreign-key-constraint-from-administrators-to-users::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::drop-old-foreign-key-constraint-from-administrators-to-users::sb ran successfully in 2ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-old-index-from-administrators-userid-to-users::sb: Index SQL170518210719120 dropped from table administrators
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-old-index-from-administrators-userid-to-users::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::drop-old-index-from-administrators-userid-to-users::sb ran successfully in 2ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-column-userid-from-administrators::sb: Column administrators.user_id dropped
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-column-userid-from-administrators::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::drop-column-userid-from-administrators::sb ran successfully in 4ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::create-new-administratorsview::sb: View administrators_view created
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::create-new-administratorsview::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::create-new-administratorsview::sb ran successfully in 4ms
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-accounts-view-for-good::sb: View accounts_view dropped
- INFO 3/30/19 11:26 AM: liquibase: db-changelog/db-changelog-1.0.0.xml: db-changelog/db-changelog-1.0.0.xml::drop-accounts-view-for-good::sb: ChangeSet db-changelog/db-changelog-1.0.0.xml::drop-accounts-view-for-good::sb ran successfully in 3ms
- INFO 3/30/19 11:26 AM: liquibase: Successfully released change log lock
- INFO 3/30/19 11:26 AM: liquibase: Successfully acquired change log lock
- INFO 3/30/19 11:26 AM: liquibase: Reading from APP.DATABASECHANGELOG
- INFO 3/30/19 11:26 AM: liquibase: sql/data/db-changelog.xml: sql/data/example_transaction_types.sql::example_transaction_types::sb: Custom SQL executed
- INFO 3/30/19 11:26 AM: liquibase: sql/data/db-changelog.xml: sql/data/example_transaction_types.sql::example_transaction_types::sb: ChangeSet sql/data/example_transaction_types.sql::example_transaction_types::sb ran successfully in 16ms
- INFO 3/30/19 11:26 AM: liquibase: sql/data/db-changelog.xml: sql/data/example_users.sql::example_users::sb: Custom SQL executed
- INFO 3/30/19 11:26 AM: liquibase: sql/data/db-changelog.xml: sql/data/example_users.sql::example_users::sb: ChangeSet sql/data/example_users.sql::example_users::sb ran successfully in 11ms
- INFO 3/30/19 11:26 AM: liquibase: sql/data/db-changelog.xml: sql/data/example_administrators.sql::example_administrators::sb: Custom SQL executed
- INFO 3/30/19 11:26 AM: liquibase: sql/data/db-changelog.xml: sql/data/example_administrators.sql::example_administrators::sb: ChangeSet sql/data/example_administrators.sql::example_administrators::sb ran successfully in 6ms
- INFO 3/30/19 11:26 AM: liquibase: sql/data/db-changelog.xml: sql/data/example_accounts.sql::example_accounts::sb: Custom SQL executed
- INFO 3/30/19 11:26 AM: liquibase: sql/data/db-changelog.xml: sql/data/example_accounts.sql::example_accounts::sb: ChangeSet sql/data/example_accounts.sql::example_accounts::sb ran successfully in 9ms
- INFO 3/30/19 11:26 AM: liquibase: sql/data/db-changelog.xml: sql/data/example_transactions.sql::example_transactions::sb: Custom SQL executed
- INFO 3/30/19 11:26 AM: liquibase: sql/data/db-changelog.xml: sql/data/example_transactions.sql::example_transactions::sb: ChangeSet sql/data/example_transactions.sql::example_transactions::sb ran successfully in 84ms
- INFO 3/30/19 11:26 AM: liquibase: Successfully released change log lock
Re : Unable to (view not found)
- // Test the database by making a query using a view
- try(Connection connection = provider.getConnection()) {
- PreparedStatement statement = connection.prepareStatement("select * from accounts_view where username=?");
- statement.setString(1, "jad");
- ResultSet onAccount = statement.executeQuery();
- assertNotNull(onAccount);
- assertTrue(onAccount.next());
- int account_id = onAccount.getInt("account_id");
- String username = onAccount.getString("username");
- String first_name = onAccount.getString("first_name");
- String last_name = onAccount.getString("last_name");
- assertEquals(4, account_id);
- assertEquals("jad", username);
- assertEquals("Jane", first_name);
- assertEquals("Doe", last_name);
- }
Running a Liquibase change log from within a change set?
There are multiple microservices, each runs using Spring Boot. Data is persisted in a common database, with each microservice having it's own schema. Over time as the tables for a microservice evolve, Liquibase is used for maintenance. In a brand new install of the product, Liquibase would create new tables as the service starts.
For a variety of reasons we need to combine microservices. Let's say service P (primary) and service S (secondary) are to be combined with all the tables under ONE schema (P's in this case). One of the requirements is that the changesets in the combined microservice should be able to handle a back-level migration. Let's say that both services are now at version 4 and a customer at version 2 wants to "upgrade". In the old model of non-combined services, when the version 4 of services P and S run for the first time both services schemas would be upgraded to V 4 (assuming there were changes in V3 and V4).
The combines service needs to handle the same upgrade scenario. I believe I can handle this if I can find a way to upgrade the secondary schemas from a changelog. Upgrading the Primary is what normally would happen and it not the issue. Typically, a change log runs "driven" by the corresponding databaseChangeLog table. I say "driven" because the entry for a changeset in the table determines whether the changeset needs to be executed in a succeeding invocation of the service. The change log for the new combined service will need to be enhanced to upgrade any existing schema for S before the tables are copied over using a custom sql task. I see the existing schema upgrade as a different custom task which sets up a new Liquibase environment and runs a change log for S against its schema. The code below is from the upgrade custom task's execute() method and in it "originalSchema" is the schema of S which needs to be upgraded.
public void execute(Database database) throws CustomChangeException {
LOGGER.debug("Updating Schema " + originalSchema);
confirmationMessage = ""; // if there's an exception it'll visible in the log.
validateSettings();
JdbcConnection dbConn = (JdbcConnection) database.getConnection();
try {
Database db = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(dbConn);
String savedDefaultSchema = database.getDefaultSchemaName();
String savedLiquibaseSchema = database.getLiquibaseSchemaName();
database.setDefaultSchemaName(originalSchema);
ChangeLogHistoryServiceFactory savedCLHSFactory = ChangeLogHistoryServiceFactory.getInstance();
ChangeLogHistoryServiceFactory.reset();
Liquibase liquibase = new Liquibase(changeLogPath, new ClassLoaderResourceAccessor(), database);
liquibase.update(new Contexts(), new LabelExpression());
ChangeLogHistoryServiceFactory.setInstance(savedCLHSFactory);
database.setDefaultSchemaName(savedDefaultSchema);
confirmationMessage = String.format("UpgradeSchema has successfully run on schema %s using change log %s.", originalSchema, changeLogPath);
}
catch (DatabaseException de) {
throw new CustomChangeException(de);
}
catch (LiquibaseException le) {
throw new CustomChangeException(le);
}
}
I discovered if I did not "reset" the ChangeLogHistoryServiceFactory it would use the cached changelog table of the combined service which was being used to "drive" the changelog. A "services" map is maintained by ChangeLogHistoryServiceFactory and since the "DataBase", which is the key to the map, does not change the same StandardChangeLogHistoryService is returned when in the new environment. Doing a reset on the ChangeLogHistoryServiceFactory gets around it.
Being a relative newbie to Liquibase (I've written change sets using the "builtin" Change objects, but never attempted a custom one), I thought I'd ask the experts for feedback as to whether the above conforms to "best practices" of running a Liquibase change log to affect a different schema from within a change set.
I do recognize the above is not thread safe, but I'd like to keep that out of the discussion unless relevant.
Thanks for taking the time to read this.
Re : State of liquibase cassandra
Thanks for the update. It is very helpful.
Our Cassandra version is 3.11.*.
Cheers
URGENT: Moving views and functions to files for better version control
URGENT: failOnError="false" and runAlways="false" don't seem to have the desired intent.
Re : URGENT: failOnError="false" and runAlways="false" don't seem to have the desired intent.
addColumn rollup for Oracle
Issue related generateChangeLog in MySQL
Parsing liquibase.properties paramter not used
- name=value
- parameter.name=value
- [INFO] Parsing Liquibase Properties File
- [INFO] File: src/main/resources/liquibase.properties
- [INFO] 'name' in properties file is not being used by this task.
- [INFO] 'parameter.name' in properties file is not being used by this task.
Not identical behaviour of mv:liquibase:diff and exceuting diff via maven profile
P.S. pom is attached.
liquibase.properties:
changeLogFile=db/changelog/db.changelog-master.xml
initial install dump
I would like to have a command launched at the end of the cycle ony if success :
mysqldump --no-create-db --no-data "${database}" > "${curdir}/db/structure.sql"
mysqldump --no-create-db --complete-insert --quote-names "${database}" databasechangelog databasechangeloglock > "${curdir}/db/data.sql"
the purpose of these files are for initial install off new instance.
How can i do ?
Or do i miss something ? ;)
Where are the supported jdbc drivers listed for the liquibase-maven-plugin?
- <plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.0.5</version>
<configuration>
<changeLogFile>liquibase/local-changelog.yml</changeLogFile>
<driver>???</driver>
<url>jdbc:postgresql:flow</url>
<username>postgres</username>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
- <driver>oracle.jdbc.driver.OracleDriver</driver>
<url>jdbc:oracle:thin:@tf-appserv-linux:1521:xe</url>