Generate commit for oracle SQL file in liquibase - oracle

I want to generate a SQL file via liquibase for my oracle database. Is there a possibility to ensure that liquibase generates a commit; after every changeset? I thought of manually write after every changeset a commit in <SQL> tags but this is actually not a good approach so is there any command for it? I am using liquibase 3.5.5. and generate the SQL file like this:
.\liquibase --url=offline:oracle?
--changeLogFile="C:\Users\Ferid\Documents\Box Sync\PRIVATE_Ferid\liquibase-3.5.5-bin\cl.xml"
--outputFile="C:\Users\Ferid\Documents\Box Sync\PRIVATE_Ferid\liquibase-3.5.5-bin\output.sql"
updatesql

Related

Can liquibase be helpful if the aim is to only automate execution of SQL queries?

My understanding of using Liquibase is as follows:
It is a repository for SQL queries migration on to Production database.
If xml is prefered ,it has a changelog.xml file which contains changesets which carry instructions in xml tags to perform actions like create, drop alter table etc.
What I want to achieve and for which I am evaluating if liquibase can serve my purpose.
My deployment process on UAT/Production have EAR and DB scripts execution as the major aspects.
I already have the .sql files which are to be fired in a particular sequence post which the EAR is to be brought up. These .sql files contain DDL as well as DML queries and stored procedures.
My aim is to automate the execution of these .sql scripts which is presently carried out manually.
Since liquibase works on an xml to generate the .sql, can my situation where .sqls are already available be proceeded with. Any inputs will be much appreciated.
Liquibase supports multiple formats. XML is only one of them. You can use SQL format. You will have to just add some comments in your scripts with meta information for Liquibase.
You did not provide much information, but what you want to do is exactly what Liquibase is for - upgrade database structure and data when you release a new version of your Java (?) application.

when i do rollback on liquibase, where can i find the logs of this rollback?

I'm using liquibase with oracle database, after executing update command for a specific changeSet, and the log for this changeSet is inserted at DATABASECHANGELOG table, however if I executed a rollbackCount command to rollback that changeSet, the inserted log is deleted and i can't find the history of the changes that were executed and rolledback again.
Liquibase's DATABASECHANGELOG table only records what's in the database. It's not an audit history tool.
For audit, you can look at using Liquibase Hub which records update and rollback operations so you'll have a record of when the operation was performed.
You can also run rollback-*-sql command prior to running an actual rollback. For example, rollback-count-sql or rollback-sql or rollback-to-date-sql. These commands will output rollback SQL to console but not execute rollback on the database. You'll need to follow up with the actual rollback operation.
Run
liquibase rollback-count-sql 10
Examine the generated SQL or log it to a file. If happy with generated SQL then run:
liquibase rollback-count 10

Insert with liquibase failing on H2 with Table not found during startup

I am using liquibase 4.3.3 to insert data to H2 DB using yaml changeset. But, when I try to start the server I get table not found while inserting even though the table exists. But, if I use the generated insert statement and disable liquibase and use spring.sql.init.data-locations to specify the sql file having insert SQL statement, this works. Can you please help me out with this weird problem?

How to rollback database to the original version using Liquibase?

I have an existing database (version x), and I can generate ChangeLog file by using below command
mvn liquibase:generateChangeLog -Dliquibase.outputChangeLogFile=d:\output.xml
After that, I try to remove one table in database directly, How can I user Liquibase to rollback my database to version x ?
Once you have started using Liquibase, you should avoid making changes directly to the database.
Let's simplify the scenario to make it easier to describe. Say at version x your database has a single table called TABLE1 and nothing else. You run the generateChangeLog command, and you get a changelog that has a single changeset that says "create table TABLE1". When Liquibase creates that changeset, it gives it an id. After creating the changelog, you will then want to record in that database that the database and changelog are 'in sync' by running the liquibase changelogSync command - this creates a second table named DATABASECHANGELOG and adds a row to that table with the id of the changeset and some other information.
If you then manually delete the table, Liquibase doesn't 'know' that you have done this, so you would need to also manually let liquibase know that you had done that delete. You would do that by removing the row from the databasechangelog table. You could then re-create the table and get back to version x by running the liquibase update command.

Liquibase: Custom SQL statement

I have my liquibase schema defined initially for PostreSQL. Now, I have to modify the schema file to support Oracle. I have a change-set that has a <sql> tag. It has a query that accesses the pg_catalog table to set a value to the sequence. However, this will not work for Oracle. If I remove it, the Liquibase complains with check-sum validation fail. It complains even if I have an empty <sql> tag or some other query specified within. Within this change-set, I have many other create-table statement, so I cannot just remove oracle from dbms attribute. Is there any way I can suppress this sql from running for Oracle?
The dbms attribute on the changeset is the mechanism designed to handle this problem..... Sounds like you're trying to do too much within one changesest (but I guess you've figured that out)
The checksum validation failure is liquibase's safety mechanism designed to defend the database against someone tampering with the schema files.
How to fix it is to use the clearChecksums option when running liquibase. It tells liquibase to recompute the checksums for the changesets already in the database. This will enable your postgres database instance to accept the alterations to its changesets that you've made for Oracle.

Resources