I'm trying to execute an update to database using liquibase. The problem is that I have some scripts that creates materialized views and I get the error:
liquibase.exception.MigrationFailedException: Migration failed for
change set
changelog/20160323192000_mviews.xml::20160323192000#1::marius: Reason:
liquibase.exception.DatabaseException: ORA-01722: invalid number
When I execute them in Toad for Oracle 11, the mviews are created without problems.
<changeSet id="20160323192000#1" author="marius">
<sql splitStatements="false"><![CDATA[
CREATE MATERIALIZED VIEW Activities_Others_M AS SELECT * FROM Activities;
]]></sql>
</changeSet>
I also tried to create table in liquibase changeSet and also is not working. Only a normal view is working.
Related
I use liquibase tool to manage a postgres database. I work as the following :
I have a solution composed of different folders containing SQL scripts responsible for schema creation, tables creations, types creation, procedures creation, etc... Then, I have a ChangeLog file in xml format, containing the following informations :
includeAll path="#{Server.WorkingDirectory}#/02 - Schema" relativeToChangelogFile="false"
includeAll path="#{Server.WorkingDirectory}#/03 - Types" relativeToChangelogFile="false
includeAll path="#{Server.WorkingDirectory}#/04 - Tables" relativeToChangelogFile="false"
includeAll path="#{Server.WorkingDirectory}#/05 - Fonctions" relativeToChangelogFile="false"
includeAll path="#{Server.WorkingDirectory}#/06 - Stored Procedures" relativeToChangelogFile="false"
I run liquibase via command line :
liquibase --changeLogFile=$(Changelog.File.Name) --driver=$(Driver.Name) --classpath=$(Driver.Classpath) --url=$(BDD.URL) --username=$(BDD.Login) --password=$(BDD.Password) update
This enable Liquibase to take all the SQL scripts in the different folders listed in the changelogFile, compare it with the current database at url $(BDD.URL), and generate a delta script containing all the SQL queries to be executed to have a database corresponding to my solution.
This works well when I add new scripts (new tables or procedures) or modify existing scripts, my database is correctly updated by the command line, as expected. BUT it does not do anything when I delete a script from my solution.
To be more factual, here is what I want :
I have a SQL file containing the query "CREATE TABLE my_table" located in the folder "04 - Tables".
I execute the update command above, and it creates the table "my_table" in my database.
I finally do not want this table in my database any more. Thus I would like to simply remove the corresponding SQL script from my solution, and then run again the "update" command to simply remove my table in my database, generating automatically a "DROP TABLE my_table" by the liquibase "update" command. But this is not working as Liquibase doesn't record any change when I remove a sql file (whereas it does when I add or modify a file).
Does anyone know a solution to this ? Is there a specific command to drop an element when there is no "CREATE" query for this element, in a SQL solution ?
Many thanks in advance for you help :)
You will need to explicitly write a script to drop the table.
Other option is to rollback the change IF YOU HAVE Specified the Rollback SQL as part of your original SQL script.
There is a Pro Version option to rollback a single update , with free / community version, you can rollback last few changes in sequence
ex; I did "liquibase rollbackCount 5" will rollback the last 5 changes that were applied ONLY IF I HAD Coded the rollback sql needed as part of my script.
My Sql script sample that included the code to rollback is
--rollback drop TABLE test.user1 ; drop table test.cd_activity;
CREATE TABLE test.user1 (
user_type_id int NOT NULL
);
CREATE TABLE test.cd_activity (
activity_id Integer NOT NULL
userid int);
How does liquibase rollback works with springboot application? Would appreciate your inputs.
Here is what i tried - I am creating TableA and TableB in Oracle within a changeset.
TableB already exists in the database, I expect liquibase to rollback TableA as changeset fails while creating TableB but liquibase creating TableA and failing with the below error and never executes rollback block, which is strange:
Caused by: liquibase.exception.DatabaseException: ORA-00955: name is already used by an existing object
Liquibase Configuration:
<changeSet id="rollback" author="test_user">
<validCheckSum>any</validCheckSum>
<sqlFile path="db/changelog/changes/DML/ddl.sql"/>
<sqlFile path="db/changelog/changes/DML/ddl.sql"/>
<rollback> drop table TABLEA;</rollback>
<rollback> drop table TABLEB;</rollback>
</changeSet>
ddl.sql
CREATE TABLE TABLEA
(
TEST_COL VARCHAR2(100)
);
dml.sql
CREATE TABLE TABLEB
(
TEST_COL VARCHAR2(100)
);
Looks like you have a wrong perception of what the rollback is for. It's not for "reverting one big transaction within a whole changeSet". It's for reinstating some past schema state.
According to Oracle documentation
Oracle Database issues an implicit COMMIT before and after any data
definition language (DDL) statement.
So after every create table statement execution, Oracle commits the transaction.
If the error happens during the execution of a changeSet, liquibase can rollback only a failed transaction, which it does.
Check out this thread
Liquibase does not automatically roll back changes made during a deploy if there was an error. Rather, it can roll a database back to a previous schema state when you ask it to. In some cases, it can do that without you explicitly saying how to do the rollback.
It would be better to think of the rollback command in Liquibase as
'undo deploys' rather than a transactional rollback.
Also, check out this liquibase-rollback article on how to use rollbacks.
I am trying to wire up liquibase to be used with Snowflake. I got it to build and start up. It creates the DatabaseChangeLog and DatabaseChangeLogLock tables. But when trying to insert data into the DatabaseChangeLog table I get the following error:
WARNING 10/4/18 5:13 PM: liquibase: Unknown database: Snowflake
Unexpected error running Liquibase: SQL compilation error:
Expression type does not match column data type, expecting TIMESTAMP_NTZ(9) but got TIMESTAMP_LTZ(9) for column DATEEXECUTED
I found the code to convert DATETIME to TIMESTAMP_NTZ, but this is moot as Snowflake has now added the DATETIME data type. How am I supposed to get the metadata to load into this table if Liquibase is trying to load it into a different data type?
I am open to all suggestions, but I am not a java programmer, so it will not be an easy go if I have to create java programs to correct this issue.
Unfortunately, someone with Java development experience will need to make changes to either Liquibase or in a Liquibase extension to support the snowflake DBMS.
Until there is a fix on Snowflake/liquibase side for this, I worked around this issue by introducing a change set that should be the first one executed by liquibase:
<?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-3.8.xsd">
<changeSet id="1" author="user">
<comment>Fix liquibase type mismatch</comment>
<sql>
<!--Due to snowflake and liquibase datetime type mismatch-->
ALTER TABLE "DATABASECHANGELOG" DROP COLUMN "DATEEXECUTED";
ALTER TABLE "DATABASECHANGELOG" ADD COLUMN "DATEEXECUTED" TIMESTAMP_LTZ;
</sql>
<rollback>
</rollback>
</changeSet>
</databaseChangeLog>
I wanted to change the data type of one field from string to date. So i dropped the table in db. Then modified the liquibase file and ran the application. now it complains with the following message.
liquibase.exception.ValidationFailedException: Validation Failed:
So after that I reverted the liquibase file changes and ran the application. This time no error but it is not creating the table.
Please help me how to solve this issue.
I assume the failed validation was an error about checksums. This happens when you modify a changeset which was already executed and try to execute it again.
Liquibase keeps all executed changesets in a table called databasechangelog, so it can find out which changesets can be skipped during execution.
To execute a changeset again, delete the corresponding from this table before, and run Liquibase again.
When using Liquibase, you shouldn't (in general) modify the database outside of Liquibase - the main exception being if you are a developer working on your own private development database. If you are in that state (working on your own private database), then when you modify the database outside of Liquibase (i.e. dropping a table) you will also need to delete the row in the DATABASECHANGELOG table that corresponds to the table create statement so that when you re-run liquibase update it will re-create the table.
I have a table that needs to be reorganised using the reorg command in DB#, However due to large size of the table, I am unable to do so. So I plan to delete entire data from the table and then do any reorg if required..
Is there any possible way for doing so?
I already used
DELETE FROM TABLE-NAME
and
TRUNCATE TABLE SCHAME-NAME.TABLE-NAME IMMEDIATE
But both the above queries aren't working and are giving the following error which is the one for reorg.
Error: DB2 SQL Error: SQLCODE=-668, SQLSTATE=57016, SQLERRMC=7;DB2ADMIN.CERTIFICATE_TAB, DRIVER=3.50.152
SQLState: 57016
ErrorCode: -668