Quantcast
Channel: Liquibase Forums
Viewing all 2993 articles
Browse latest View live

sqloutput command preceeds databasechangelog table with current schema name

$
0
0
When I execute the sqloutput command, liquibase 3.2.2 precedes each insert on databasechangelog table with current schema name.

INSERT INTO MY_TEST_SCHEMA.DATABASECHANGELOG (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, LIQUIBASE) VALUES ('...);

This forces me to process the outcome files to remove the "MY_TEST_SCHEMA." string, because we execute liquibase against a test schema before we launch the resulting files to production.

I've been using liquibase 2.0.3 for quite long and this behaviour is new in liquibase 3.0.0. 

Is there any way to remove the schema name?


Re : sqloutput command preceeds databasechangelog table with current schema name

$
0
0
It looks like there was a bug with the handling of the ouputDefaultSchemaName=false parameter. That will be fixed with 3.3.0 which I'm trying to get out in the next week.

Nathan

rollbacks not working if Spring starts them even if runInTransaction=false

$
0
0
So, I have a lot of INSERTs that I wanna do inside a Spring-driven JUnit test.  My changesets look like:
  1.      < changeSet runInTransaction = "false" author = "me (generated)" id = "1413580824558-29" >
  2.          < insert tableName = "some_table" >
  3.              < column name = "id" valueNumeric = "10" />
  4.               < column name = "created" valueDate = "2014-10-17 10:25:55.0" />
  5.              < column name = "modified" valueDate = "2014-10-17 10:25:55.0" />
  6.          </ insert >


My Spring-driven JUnit test looks like:

  1. @RunWith (SpringJUnit4ClassRunner. class )
  2. @ContextConfiguration (classes= {PersistenceJPAConfig. class })
  3. @Transactional ()
  4. @TestExecutionListeners ({
  5.      DependencyInjectionTestExecutionListener. class ,
  6.      TransactionalTestExecutionListener. class
  7.      })
  8. @TransactionConfiguration (defaultRollback= true )
  9. public class DatabaseBasedIT {


I have a method that loads a changelog via the Spring-bean:

  1.      protected void loadLiquibaseChangelog(String changelogFilename ) throws LiquibaseException {
  2.          SpringLiquibase springLiquibase = new SpringLiquibase();
  3.          springLiquibase .setDataSource( ds );
  4.          springLiquibase .setChangeLog( changelogFilename );
  5.          springLiquibase .setResourceLoader( resourceLoader );
  6.          springLiquibase .afterPropertiesSet();
  7.     }


Spring says it rolled back the tx:


  1. INFO 10/22/14 10:16 PM: liquibase: Successfully released change log lock
  2. Oct 22, 2014 10:16:54 PM org.springframework.test.context.transaction.TransactionContext endTransaction
  3. INFO: Rolled back transaction for test context [DefaultTestContext@14af2ab6 testClass = DatabaseBasedIT, testInstance =DatabaseBasedIT@2e5e130a, testMethod = onlyLoadsChangeLogFromLiquibase@DatabaseBasedIT, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@3f70f50e testClass = DatabaseBasedIT, locations = '{}', classes = '{class PersistenceJPAConfig}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]].


But the data doesn't actually get rolled back because the data is still left over after the tests are done.  (If I manually INSERT the data using the DataSource that Spring gives me, that gets rolled back properly.


Looking at the code for liquibase.changelog. ChangeSet and setting some breakpoints, I can see that autocommit is set to true.  Could this be the reason that the liquibase data isn't rolled back?


P.S. I can create a small sample project if need be, but I'm hoping it's easy enough to figure out with that. ;) 

Re : Strange things with Java 8

$
0
0
It's odd Java 8 would make a difference with the logic knowing TAG is a keyword. I wonder if it's a problem with java 8 not finding the redshift extension correctly? 

I assume there isn't a difference in your classpath between java 8 and 7. Do you notice anything in the log about finding or not finding or errors loading classes in 8 vs 7?

Nathan

MySQL addColumn defaultValue="0"

$
0
0
Create liquibase diff :

mysql> create database test1 default character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql> use test1
Database changed

mysql> create table a(id int(10), archive bit not null default 0);
Query OK, 0 rows affected (0.04 sec)

mysql> create database test2 default character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql> use test2;
Database changed
mysql> create table a(id int(10));
Query OK, 0 rows affected (0.05 sec)


root@82a05bda089b:/opt# ./liquibase --driver=com.mysql.jdbc.Driver --classpath=/opt/mysql-connector-java-5.1.33/mysql-connector-java-5.1.33-bin.jar --url="jdbc:mysql://localhost/test2" --username=root --password='' diffChangeLog --referenceUrl="jdbc:mysql://localhost/test1" --referenceUsername=root --referencePassword='' > diff.xml
Liquibase 'diffChangeLog' Successful

root@82a05bda089b:/opt# cat diff.xml
<?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 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
    <changeSet author="root (generated)" id="1414169048190-1">
        <addColumn tableName="a">
            <column defaultValue="0" name="archive" type="BIT(1)">
                <constraints nullable="false"/>
            </column>
        </addColumn>
    </changeSet>
</databaseChangeLog>

Liquibase update database test2 :

root@82a05bda089b:/opt# ./liquibase --driver=com.mysql.jdbc.Driver --classpath=/opt/mysql-connector-java-5.1.33/mysql-connector-java-5.1.33-bin.jar --url="jdbc:mysql://localhost/test2" --username=root --password='' --changeLogFile=diff.xml updateUnexpected error running Liquibase: Error executing SQL ALTER TABLE test2.a ADD archive BIT(1) NOT NULL DEFAULT '0': Invalid default value for 'archive'

in mysql-server general_log:

          122 Query    ALTER TABLE test2.a ADD archive BIT(1) NOT NULL DEFAULT '0'
          122 Query    rollback

mysql> ALTER TABLE test2.a ADD archive BIT(1) NOT NULL DEFAULT '0';
ERROR 1067 (42000): Invalid default value for 'archive'
mysql> ALTER TABLE test2.a ADD archive BIT(1) NOT NULL DEFAULT 0;
Query OK, 0 rows affected (0.04 sec)
Records: 0  Duplicates: 0  Warnings: 0


How to fix?

Re : Validation and Output

$
0
0
Thanks for your reply Nathan!

I'm trying to make it work, and looks good so far, but I would like to enable the logger, then will be easy to see what i'm doing. But I don't know why I can't see the log in debug level.

This is my code: 

  1. <changeSet id="dataBaseCheck_v2" author="e-ballo" runAlways="true">
  2. <preConditions onFailMessage="There are invalid objects in the database!!"
  3. onFail="HALT">
  4. <customPrecondition
  5. className="nl.tele2.bos.liquibase.custom.preconditions.CustomBuildCheck">
  6. <param name="sql"
  7. value="SELECT count(1)
  8. FROM all_objects alo
  9. WHERE status = 'INVALID'
  10. AND alo.owner in
  11. ('BOS_RELEASE','BIL','BLIS','CBSMIG','COJO','CMD_AGENT','CIN','NOPA','ORC','PRV','SEC','TIPI_OWNER','TT','ZON')
  12. AND alo.OBJECT_NAME not like 'TST%'
  13. AND alo.OBJECT_NAME not like 'TEST%'
  14. AND ALO.OBJECT_NAME &lt;&gt; 'ZON_ORBIT_LOG_PCK'
  15. AND ALO.OBJECT_NAME &lt;&gt; 'ZON_TESTING_PCK'
  16. AND ALO.OBJECT_NAME &lt;&gt; 'ZON_MONITORING_PCK';"/>
  17. <param name="sqlNames" value="SELECT alo.owner
  18. , alo.object_name
  19. , alo.status
  20. ,
  21. alo.last_ddl_time
  22. FROM all_objects alo
  23. WHERE status = 'INVALID'
  24. AND
  25. alo.owner in
  26. ('BOS_RELEASE','BIL','BLIS','CBSMIG','COJO','CMD_AGENT','CIN','NOPA','ORC','PRV','SEC','TIPI_OWNER','TT','ZON')
  27. AND alo.OBJECT_NAME not like 'TST%'
  28. AND alo.OBJECT_NAME not like
  29. 'TEST%'
  30. AND ALO.OBJECT_NAME &lt;&gt; 'ZON_ORBIT_LOG_PCK'
  31. AND
  32. ALO.OBJECT_NAME &lt;&gt; 'ZON_TESTING_PCK'
  33. AND ALO.OBJECT_NAME &lt;&gt;
  34. 'ZON_MONITORING_PCK'
  35. ORDER BY alo.owner, alo.object_name;"/>
  36. <param name="expectedResult" value="1" />
  37. </customPrecondition>
  38. </preConditions>
  39. </changeSet>
Java class:
  1. import liquibase.database.Database;
  2. import liquibase.database.DatabaseConnection;
  3. import liquibase.exception.CustomPreconditionErrorException;
  4. import liquibase.exception.CustomPreconditionFailedException;
  5. import liquibase.exception.DatabaseException;
  6. import liquibase.executor.ExecutorService;
  7. import liquibase.logging.LogFactory;
  8. import liquibase.logging.Logger;
  9. import liquibase.precondition.CustomPrecondition;
  10. import liquibase.statement.core.RawSqlStatement;
  11. import lombok.Getter;
  12. import lombok.Setter;

  13. /**
  14.  * CustomBuildCheck Precondition
  15.  * <customPrecondition className="nl.tele2.bos.liquibase.custom.preconditions.CustomBuildCheck">
  16.  * <param name="sql" value=""/>
  17.  * <param name="sqlNames" value=""/>
  18.  * <param name="expectedResult" value="0"/>
  19.  * </customPrecondition>
  20.  * 
  21.  * @author Enric Ballo 
  22.  * @since Oct 24, 2014
  23.  */
  24. public class CustomBuildCheck implements CustomPrecondition {
  25.     
  26.     private final Logger logger = LogFactory.getInstance().getLog("CustomBuildCheck");

  27.     @Getter
  28.     @Setter
  29.     private String expectedResult;

  30.     @Getter
  31.     @Setter
  32.     private String sql;

  33.     @Getter
  34.     @Setter
  35.     private String sqlNames;

  36.     @Override
  37.     public void check(final Database database) throws CustomPreconditionFailedException, CustomPreconditionErrorException {

  38.         final DatabaseConnection connection = database.getConnection();
  39.         try {
  40.             logger.debug("CustomBuildCheck is executed...");
  41.             
  42.             final String result =
  43.                     ExecutorService.getInstance().getExecutor(database).queryForObject(
  44.                             new RawSqlStatement(getSql().replaceFirst(";$", "")), String.class);

  45.             if (result == null) {
  46.                 throw new CustomPreconditionFailedException("No rows returned from SQL Precondition");
  47.             }
  48.             
  49.             logger.debug("result is :"+result);
  50.             
  51.             if (!expectedResult.equals(result)) {
  52.                 
  53.                 logger.debug("We have some errors! ");

  54.                 // final String resultNames = ExecutorService.getInstance().getExecutor(database).queryForObject(new RawSqlStatement(getSqlNames().replaceFirst(";$", "")), String.class);

  55.                 throw new CustomPreconditionFailedException("SQL Precondition failed.  Expected '" + expectedResult + "' got '" + result
  56.                     + "'");
  57.             }

  58.         } catch (final DatabaseException e) {
  59.             throw new CustomPreconditionFailedException(e.getMessage());
  60.         }
  61.     }

  62. }
Result in the console:
  1. DEBUG 10/27/14 3:27 PM: liquibase: liquibase/changelogs/bos-incremental-changelog.xml: liquibase/changelogs/bos-incremental-databaseCheck-changelog.xml::dataBaseCheck_v2::e-ballo: Computed checksum for  as d41d8cd98f00b204e9800998ecf8427e
  2. DEBUG 10/27/14 3:27 PM: liquibase: liquibase/changelogs/bos-incremental-changelog.xml: liquibase/changelogs/bos-incremental-databaseCheck-changelog.xml::dataBaseCheck_v2::e-ballo: Running Changeset:liquibase/changelogs/bos-incremental-databaseCheck-changelog.xml::dataBaseCheck_v2::e-ballo
  3. DEBUG 10/27/14 3:27 PM: liquibase: liquibase/changelogs/bos-incremental-changelog.xml: liquibase/changelogs/bos-incremental-databaseCheck-changelog.xml::dataBaseCheck_v2::e-ballo: Changeset liquibase/changelogs/bos-incremental-databaseCheck-changelog.xml::dataBaseCheck_v2::e-ballo
  4. DEBUG 10/27/14 3:27 PM: liquibase: liquibase/changelogs/bos-incremental-changelog.xml: liquibase/changelogs/bos-incremental-databaseCheck-changelog.xml::dataBaseCheck_v2::e-ballo: Executing QUERY database command: SELECT count(1)     FROM all_objects alo     WHERE status = 'INVALID'     AND alo.owner in     ('BOS_RELEASE','BIL','BLIS','CBSMIG','COJO','CMD_AGENT','CIN','NOPA','ORC','PRV','SEC','TIPI_OWNER','TT','ZON')     AND alo.OBJECT_NAME not like 'TST%'     AND alo.OBJECT_NAME not like 'TEST%'     AND ALO.OBJECT_NAME <> 'ZON_ORBIT_LOG_PCK'     AND ALO.OBJECT_NAME <> 'ZON_TESTING_PCK'     AND ALO.OBJECT_NAME <> 'ZON_MONITORING_PCK'
  5. SEVERE 10/27/14 3:27 PM: liquibase: liquibase/changelogs/bos-incremental-changelog.xml: liquibase/changelogs/bos-incremental-databaseCheck-changelog.xml::dataBaseCheck_v2::e-ballo: Change Set liquibase/changelogs/bos-incremental-databaseCheck-changelog.xml::dataBaseCheck_v2::e-ballo failed.  Error: Migration failed for change set liquibase/changelogs/bos-incremental-databaseCheck-changelog.xml::dataBaseCheck_v2::e-ballo:
  6.      Reason:
  7.           liquibase/changelogs/bos-incremental-changelog.xml : There are invalid objects in the database!!

  8. liquibase.exception.MigrationFailedException: Migration failed for change set liquibase/changelogs/bos-incremental-databaseCheck-changelog.xml::dataBaseCheck_v2::e-ballo:
  9.      Reason:
  10.           liquibase/changelogs/bos-incremental-changelog.xml : There are invalid objects in the database!!

  11.         at liquibase.changelog.ChangeSet.execute(ChangeSet.java:463)
  12.         at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:43)
  13.         at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:70)
  14.         at liquibase.Liquibase.update(Liquibase.java:195)
  15.         at liquibase.Liquibase.update(Liquibase.java:174)
  16.         at liquibase.integration.commandline.Main.doMigration(Main.java:997)
  17.         at liquibase.integration.commandline.Main.run(Main.java:170)
  18.         at liquibase.integration.commandline.Main.main(Main.java:89)
  19. Caused by: liquibase.exception.PreconditionFailedException: Preconditions Failed
  20.         at liquibase.precondition.core.PreconditionContainer.check(PreconditionContainer.java:220)
  21.         at liquibase.changelog.ChangeSet.execute(ChangeSet.java:449)
  22.         ... 7 more
  23. DEBUG 10/27/14 3:27 PM: liquibase: liquibase/changelogs/bos-incremental-databaseCheck-changelog.xml::dataBaseCheck_v2::e-ballo: Release Database Lock
  24. DEBUG 10/27/14 3:27 PM: liquibase: liquibase/changelogs/bos-incremental-databaseCheck-changelog.xml::dataBaseCheck_v2::e-ballo: Executing UPDATE database command: UPDATE BOS_RELEASE.DATABASECHANGELOGLOCK SET LOCKED = 0, LOCKEDBY = NULL, LOCKGRANTED = NULL WHERE ID = 1
  25. INFO 10/27/14 3:27 PM: liquibase: liquibase/changelogs/bos-incremental-databaseCheck-changelog.xml::dataBaseCheck_v2::e-ballo: Successfully released change log lock
  26. Unexpected error running Liquibase: Preconditions Failed

How shall i use the Logger ? do am I doing something wrong ?

Thanks in advance

Re : Validation and Output

$
0
0
Ok, I just fixed

Just if someone want to know the LogFactory should be like this:


  1.     private final Logger logger = LogFactory.getInstance().getLog("liquibase");

Re : Validation and Output

$
0
0
Glad you got it figured out. Thanks for letting us know.

Nathan

Re : MySQL addColumn defaultValue="0"

Re : Validation and Output

$
0
0
I'm almost done, but i would like to know if there is a way to execute a query and get a list of results.

I was looking into JdbcExecutor class and i don't have a clear idea how i can do that.

I would like to do this query when I have errors, and then display in the logs as a sever the list of all the object that are not working.

  1. SELECT    alo.owner
  2. , alo.object_name
  3. , alo.status
  4. , alo.last_ddl_time
  5. FROM all_objects alo
  6. WHERE status = 'INVALID'
  7. AND alo.owner in
  8. ('BOS_RELEASE','BIL','BLIS','CBSMIG','COJO','CMD_AGENT','CIN','NOPA','ORC','PRV','SEC','TIPI_OWNER','TT','ZON')
  9. AND alo.OBJECT_NAME not like 'TST%'
  10. AND alo.OBJECT_NAME not like 'TEST%'
  11. AND ALO.OBJECT_NAME &lt;&gt; 'ZON_ORBIT_LOG_PCK'
  12. AND ALO.OBJECT_NAME &lt;&gt; 'ZON_TESTING_PCK'
  13. AND ALO.OBJECT_NAME &lt;&gt; 'ZON_MONITORING_PCK'
  14. ORDER BY alo.owner, alo.object_name;

Thanks in advance,

Re : Validation and Output

$
0
0
The easiest way with JdbcExecutor to query is to use a queryForList() method. If you want to specify the exact SQL, use `executor.queryForList(new RawSqlStatement(YOUR_SQL)` which will return a List of Maps containing the data from the result set.

Nathan

Re : rollbacks not working if Spring starts them even if runInTransaction=false

$
0
0
I think the autocommit setting is the problem. I just put in a fix for 3.3 that correctly handles the autocommit. That may be affecting the runInTransaction as well. 

Would you be able to test with the build from https://liquibase.jira.com/builds/browse/CORE-LB-29 when it finishes and let me know if it resolves your problem?

Nathan

Re : MySQL addColumn defaultValue="0"

MySQL diff - modify index key

$
0
0
mysql> create database test1 default character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> create database test2 default character set utf8;
Query OK, 1 row affected (0.00 sec)

mysql> use test1
Database changed
mysql> create table a (id int(10), c int(10), v int(10), b int(10), key cvb (c,v,b));
Query OK, 0 rows affected (0.00 sec)

mysql> use test2
Database changed
mysql> create table a (id int(10), c int(10),  v int(10), b int(10), key cvb (v,b));
Query OK, 0 rows affected (0.00 sec)


Liquibase Version: 3.2.2

Create diffChangeLog:

root@080c21576872:/opt# ./liquibase --driver=com.mysql.jdbc.Driver --classpath=/usr/share/java/mysql-connector-java-5.1.10.jar --url="jdbc:mysql://localhost/test2" --username=root --password='' diffChangeLog --referenceUrl="jdbc:mysql://localhost/test1" --referenceUsername=root --referencePassword='' > diff.xml
Liquibase 'diffChangeLog' Successful

root@080c21576872:/opt# cat diff.xml
<?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 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
    <changeSet author="root (generated)" id="1414522888481-1">
        <createIndex indexName="cvb" tableName="a" unique="false">
            <column name="c"/>
            <column name="v"/>
            <column name="b"/>
        </createIndex>
    </changeSet>
    <changeSet author="root (generated)" id="1414522888481-2">
        <dropIndex indexName="cvb" tableName="a"/>
    </changeSet>
</databaseChangeLog>


Update test2:

root@080c21576872:/opt# ./liquibase --driver=com.mysql.jdbc.Driver --classpath=/usr/share/java/mysql-connector-java-5.1.10.jar --url="jdbc:mysql://localhost/test2" --username=root --password='' --changeLogFile=diff.xml update
Unexpected error running Liquibase: Error executing SQL CREATE INDEX cvb ON test2.a(c, v, b): Duplicate key name 'cvb'


The sequence of actions in the file is broken.

modify file diff.xml:

root@080c21576872:/opt# cat diff.xml
<?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 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
    <changeSet author="root (generated)" id="1414522888481-2">
        <dropIndex indexName="cvb" tableName="a"/>
    </changeSet>
    <changeSet author="root (generated)" id="1414522888481-1">
        <createIndex indexName="cvb" tableName="a" unique="false">
            <column name="c"/>
            <column name="v"/>
            <column name="b"/>
        </createIndex>
    </changeSet>
</databaseChangeLog>

root@080c21576872:/opt# ./liquibase --driver=com.mysql.jdbc.Driver --classpath=/usr/share/java/mysql-connector-java-5.1.10.jar --url="jdbc:mysql://localhost/test2" --username=root --password='' --changeLogFile=diff.xml update
Liquibase Update Successful


How to generate the correct file ?

Re : MySQL diff - modify index key


liquibase + h2

$
0
0
Please help me.
When I use <modifyDataType columnName="column1" newDataType="numeric(3)" tableName="employee"/> or <dropNotNullConstraint tableName="employee" columnName="column1" columnDataType="numeric(3)"/> then erased remarks into "column1". I use h2database. How to solve this problem?

Re : rollbacks not working if Spring starts them even if runInTransaction=false

$
0
0
@nvoxland: Sorry, that doesn't seem to fix it. :(  (Although there's a chance my environment is messed up.)

Also, I'm not sure if runInTransaction is supposed to be "true" or "false" in the case of transactions managed outside of Liquibase (i.e., my case).

Either way, I tried with both and neither seems to work.  By "work," I mean rollback the data.

If you point me to the place where you like to keep your unit / integration tests, I can probably make one to expose this behavior.

Re : New Extension: Liquibase Vertica support

loadUpdateData generating SQL output terminated with /;

$
0
0
loadUpdateData is generating anonymous PL/SQL blocks for each row in order to handle the conditional logic of the insert or update terminated with /; (slash semi-colon).  SQL*Plus doesn't tolerate this well.  The proper RUN statement after a PL/SQL block is a slash, alone on a line.  Is there an option to alter the delimiter like with sqlFile?

Re : rollbacks not working if Spring starts them even if runInTransaction=false

$
0
0
Sorry, I didn't read your original question well enough to really understand what you are doing. 

The problem you are running into is that after each changeSet, liquibase does a connection.commit(), and so when you call rollback after it is done, there is nothing to roll back.

Before each changeSet, liqiubase will run connection.setAutoCommit(!runInTransaction) so by having it set to false it will also automatically commit after each insert and therefore not roll back.

There is nothing built into liquibase to control the fact that it commits after each changeSet, but you should be able to easily override the behavior in your tests. 

SpringLiquibase has a `createDatabase(Connection c)` method which creates a liquibase.database.Database instance based on the connection. It is that Database object's commit() method that is called after the changeSet is ran so if create a subclass of SpringLiquibase that overrides createDatabase() to return a delegate pattern object that delegates all Database methods except commit() to the normal Database object and just replace commit() with a no-op.  That should keep the changeSets from committing when in your test cases and the outer connection rollback() will roll back the changes.

Just remember that some database operations like CREATE TABLE auto-commit and there is no way to avoid that besides using a different database.

Nathan
Viewing all 2993 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>