liquibase , Why are all contexts executed when non specified on update?

Why are all contexts executed when non specified on update?


Tag: liquibase

I'm using Liquibase 3.3.5 to update my database. Having contexts is a nice way to only execute specific parts of the changelog. But I don't understand, why ALL changesets are executed, when no context is provided on update. Consider the following example:


For me, this doesn't make sense at all :).

I would expect, that only changeset B will be executed, since it doesn't define a specific context.

In the Liquibase contexts example: ("Using Contexts for Test Data") they say, that one should mark the changesets for testing with "test", and executing them with giving the context "test" to apply testdata. Fine - make sense. But

"When it comes time to migrate your production database, don’t include the “test" context, and your test data not be included. "

So, if I wouldn't specify "test" context when executing production update, it would execute the "test" changesets as well, since I didn't specify a context at all.

Again, I would expect that leaving out test on update execution, would only perform the regular changesets without the test changesets.

Or I'm missing something here :)?


This is just how Liquibase works - if you do an update and don't specify a context, then all changesets are considered as applicable to that update operation.

There were a couple of ways that this could have been implemented, and the development team had to pick one.

  1. if you don't specify a context during an update operation, then no changesets are considered.
  2. if you don't specify a context, then all changesets are considered.
  3. if you don't specify a context, then only changesets that have no context are considered.
  4. if you don't specify a context and none of the changesets have contexts on them, then all changesets are considered, but if some of the changesets do have contexts, go to option 1, 2, or 3 above.

The team could have gone with option 3 (which matches your expectation) but decided long ago to go with option 2, as that seemed like the 'best' way at the time. I wasn't on the team at that time, so I don't know any more than that.


Why my predcondition is not serialized?

I have a problem. I autogenerate my changelog. I try to add some precondition on a changeset. But when i serialize mys changeset, the precondition rule doesn't appear in my XML changelog. I see only the addcolumn section Here how i generate my changeset: final ChangeSet changeset = new CustomChangeSet("myId",...

Can Liquibase use DB2's multiple tablespaces?

In DB2 LUW it is recommended that tables, indexes and "long objects" (ie LOBs) should be placed in separate tablespaces. Our existing SQL scripts have lines like this: CREATE TABLE "APPLICATIONTABLE"( APPLICATIONID INTEGER NOT NULL, APPLICATIONNAME VARCHAR(30) NOT NULL )IN USERSPACE1 INDEX IN USERSPACE2 LONG IN USERSPACE3; In a changeset...

How to execute liquibase with java.lang.NumberFormatException on PostgreSQL

In trying to execute diffChangelog in liquibase 3.3.3 on a PostgreSQL 9.3 database (from PowerShell script) as: $_cmd='C:\liquibase-3.3.3-bin\liquibase --driver=org.postgresql.Driver --url=jdbc:postgresql://localhost:5432/chaos --username=postgres --password=Password diffChangelog --referenceUrl=jdbc:postgresql:// --referenceUsername=postgres --referencePassword=Password > db-changelog.xml'; CMD.EXE /c "`"$_cmd`"" I get the error: *CMD.EXE : Unexpected error running Liquibase:...

How can I force Liquibase to recalculate checksums without re-running the statements?

We're using Liquibase 3.2 with Java 6. Is there a way I can force Liquibase to recalculate checksums without re-running the same statements from our Liquibase files? In our database, I run this ... update DATABASECHANGELOG set md5sum = null where 1; However, when I run my Liquibase change scripts,...

How to update already run database migration files using Grails DBMigration plugin?

I have migration file named test-plugin-migration-1.2.groovy which nedds to be only renamed as migrations listed in it are already run and some other custom migrations. test-plugin-migration-1.2.groovy - > test-plugin-migration-1-2.groovy I tried adding a custom migration for DATABASECHANGELOG table in new file named rename-migration.groovy rename-migration.groovy changeSet(author: "Laxmi Salunkhe", id: "12345-1") {...

Why are all contexts executed when non specified on update?

I'm using Liquibase 3.3.5 to update my database. Having contexts is a nice way to only execute specific parts of the changelog. But I don't understand, why ALL changesets are executed, when no context is provided on update. Consider the following example: changeset A: context=test changeset B: no context changeset...

How to enforce column order with Liquibase?

Setup: liquibase 3.3.5 PostgreSQL 9.3 Windows 7 Ultimate Having set the file with changeLogFile = C://temp/changeset.xml, I created a diff file with Liquibase (3.3.5). liquibase.bat diffChangeLog Examination of the changeset.xml file shows -<addColumn tableName="view_dx"> <column type="int8" name="counter" defaultValueNumeric="0" defaultValue="0"/> </addColumn Problem is when liquibase.bat update is run, the changed...

liquibase database build from scratch

When I run liquibase update from scratch, it takes a while as the process fires each changelog one by one. Sometimes my own database changes diverge enough that its easiest to rebuild the database if I want to start again for example. The rebuild would be quickest if I did...

Liquibase not working from within JBoss?

I am using Liquibase 3.3.2 and trying to implement a webservice that accepts a number of changelogs, looks up a specific DataSource depending on the context, and use that DataSource together with the liquibase ChangeLogs to perform a database update. I am using PostgreSQL as a database. Somehow the liquibase...

multiples dbms in precondition of liquibase using yaml

In precondition documentation of liquibase we can see the example below: <preConditions> <dbms type="oracle" /> <dbms type="mysql" /> </preConditions> When try to recreate the same rule using yaml, it not works. preConditions: dbms: type: oracle dbms: type: mysql I also have tried something like: preConditions: - dbms: dbms: type: oracle...

Liquibase endDelimiter usage

Trying to run this from Liquibase: --changeset blah runOnChange:true endDelimiter:\n/\s*\n|\n/\s*$ DELETE MYTABLE; INSERT INTO MYTABLE(A,B,C) VALUES ('A', 'B', 'C'); DECLARE row_count NUMBER; BEGIN SELECT COUNT(1) INTO row_count FROM OTHERTABLE; IF (row_count = 0) THEN DELETE MYTABLE WHERE A LIKE 'BLAH:%'; END IF; END; / But getting this error: Caused by:...

MS SQLServer JDBCcommandline with Liquibase - Login Failure/ TCP IP Exception/ Port Not Valid

I'm trying to connect to Microsoft SQL Server 2008 SP3 using Liquibase and Microsoft JDBC Driver 4.1. I get various exceptions and not a single successful way to authenticate into the server via commandline. With the same username and password I was able to login to the database via MS...

loadUpdateData in liquibase, select only some columns from csv

Assume having the following csv: a,b,c 1,2,3 where a,b,c are column names and 1,2,3 are values. Is it possible to load only columns a,b? <loadUpdateData tableName="TABLE" file="file.csv" primaryKey="a"> <column name="a" header="a"/> <column name="b" header="b"/> </loadUpdateData> This will generate an SQL error, because it will try to insert column c. I...

Liquibase NoSuchMethodError with SQL Server

When running my Liquibase setup I'm getting the following error: Caused by: java.lang.NoSuchMethodError: liquibase.database.Database.escapeTableName(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; I really cannot tell what is wrong with my initial schema file, can anyone with more experience help me spot the errors? If I had to guess it's most likely something from the file I have...

How to improve performance of Liquibase on Greenplum database

I'm evaluating the use of Liquibase (3.3.2) against a Greenplum (Postgres on steroids) database using postgresql 8.4-701.jdbc4 and am running into performance issues when trying to add one changeset (create table) against an existing schema containing many partitioned tables. I'm in hour three currently, with no idea how much longer...

ERROR: cannot ALTER TABLE because it has pending trigger events while attempting to drop a column in a table

I wrote a sql tag in my liquibase changeset. this sql code is suppose to make data migration in a table named "Purchase". so i have the following sql queries: UPDATE purchase SET location_id = (SELECT location_id FROM shop WHERE = purchase.shop_id); then, ALTER TABLE purchase DROP COLUMN shop_id;...

How does Liquibase Tag - commandline

I was able to tag successfully using liquibase commandline, but do not know where it is tagged to and stored. The command was executed successfully, below is the input and response to the tag command. This may be a very trivial question, but i could not find any documentation to...

Update query in liquibase

I need to run the below update query in liquibase, but I am not sure about the syntax. Can anyone please help: update xyz.users set email = (select CONCAT(username, ' ') "email" from xyz.users ) where email like '' ; ...

Liquibase 3.3.3 refusing to run “due to maven configuration”

Did something change in liquibase between version 2 and version 3? I have the following in my pom file... <plugin> <groupId>org.liquibase</groupId> <artifactId>liquibase-maven-plugin</artifactId> <version>3.3.3</version> <configuration> <changeLogFile>src/main/resources/liquibase/liquibase-changesets.xml</changeLogFile> <driver>${db.liquibase.driver}</driver> <username>${db.liquibase.username}</username>...

How do I use a Liquibase changelog which is in jar file

I currently have the following in my liquibase.change-log=classpath:/db/changelog/db.changelog-master.xml The actual path to the file is src/main/resources/db/changelog/db.changelog-master.xml. The changelog is found by Liquibase and everything is working as I would expect. I've moved the changelog and all of the project's JPA entities and repositories into a separate project so that...

How to insert using a sequence with Liquibase

I would like to do a liquibase insert with the primary key being auto generated from the sequence defined in the database. The target database is HSQLDB. It works to do an insert specifying a value for the primary key <insert ...> <column name="TAG_ID" valueNumeric="2"/> I found this (admittedly older)...

jhipster run embedded jar with prod profile - issue with liquibase

I have packaged my app with : mvn -Pprod package Then I ran java -jar myapp-0.0.1-SNAPSHOT.war it works fine. But if I run : java -jar myapp-0.0.1-SNAPSHOT.war I am getting this error: [ERROR] org.springframework.boot.context.embedded.tomcat.ServletContextInitializerLifecycleListener - Error starting Tomcat context: org.springframework.beans.factory.BeanCreationException [WARN] org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context...

Maven liquibase plugin

I am new to Maven and Liquibase. For the past couple of days, I have been playing around with liquibase without Maven. I have tried generating changelog file with a new database and an existing database. Now I am trying to implement Maven and Liquibase using the plugin. What is...

Create column of type double precision[] with liquibase

How to create column of type double precision[] (array of doubles) with liquibase in postgresql database? <changeSet id="add t_name table"> <createTable tableName="t_name"> ... <column name="doubleArray" type="???"/> ... </createTable> </changeSet> Google didn't help, please, if someone knows a solution, I will be very appreciative....

liquibase generate sql between 2 changelogs

We currently use liquibase to version control our mysql database, however, we are not allowed to run liquibase on production. The first time we deployed we did an sql dump of the database, which was the amalgamation of all the changelogs to date. So say the changelog currently is at...

Is there a liquibase lock timeout?

You can see in the issue here: (liquibase-lock-reasons) at situation where the client Liquibase locks when a Liquibase operation has been interrupted, leaving liquibase in a locked state. I'm wondering if there is a way to configure Liquibase to automatically detect this situation from the date and time in the...

Liquibase: how to run always a changeset as the last update operation

I'm using Liquibase on my project and need always to execute a procedure after each Liquibase updates... Currently, the changeSet looks like this: <changeSet id="liquibase-0" author="liquibase" runAlways="true"> <sqlFile relativeToChangelogFile="true" path="procedure/owner-changer.sql"/> </changeSet> How can I do ensure that this changeSet will be run as the last update operation? Thks...

Liquibase not dropping sequences on Postgres

i'm driving crazy already as liquibase (on postgres) is not dropping sequences when running a liquibase:dropAll through the maven plugin. These sequences are created by liquibase itself through different changelogs. I've found that there was the same issue once for Derby but that is resolved already. Is anyone aware of...

Can you clear liquibase checksums for a given file only?

Running liquibase --url=jdbc:oracle:thin:@localhost:1521/XE -- driver=oracle.jdbc.OracleDriver --changeLogFile=db.changelog-next.xml -- username=owner --password=xxxx --logLevel=info clearCheckSums clears ALL checksums from the database. Is there a way to clear only the checksums for changesets in db.changelog-next.xml. Thanks...

Liquibase generateChangeLog command - generating changelog with insert statements

To generate insert statements from my databases (oracle,db2) i've used liquibase generateChangeLog command with argument --diffTypes="data" This command generate correct xml with insert statements, however this is not aware of foreign constraints, so I cannot use this file to again to fill my databases. Similar problems has been described here...

Get the output SQL from a Liquibase changeset

I'm having a SQL syntax error when my Spring Boot application tries to start. It cannot instantiate the SpringLiquibase bean, because the outputed SQL of a changeset is leading to a syntax error. I need to check the SQL generated from Liquibase in order to find what's wrong. How can...