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

Re : liquibase + h2

$
0
0
Unfortunately that was an issue with the SQL generated through Liquibase 3.2.2. There is a fix for 3.3.0 (out very soon) that should resolve it. Without updating for 3.3.0, you'll have to switch to a <sql> block to control the SQL generated.

Nathan

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

$
0
0
Thanks, Nathan!

Would you entertain a "do not commit" patch?  If not, that's OK, I just won't bother submitting one. :)

Re : Validation and Output

$
0
0
I already have a solution for that I would like to share with you guys, maybe is useful for someone.

Java Class
  1. /**
  2.  * CustomBuildCheck Precondition
  3.  * <customPrecondition className="nl.tele2.bos.liquibase.custom.preconditions.CustomBuildCheck">
  4.  * <param name="sql" value="Select * from ...;"/>
  5.  * <param name="expectedResult" value="0"/>
  6.  * </customPrecondition>
  7.  * 
  8.  * @author Enric Ballo (enric.ballo@tele2.com)
  9.  * @since Oct 24, 2014
  10.  */
  11. @Getter
  12. @Setter
  13. public class CustomBuildCheck implements CustomPrecondition {

  14.     private static final String LAST_DDL_TIME = "LAST_DDL_TIME";

  15.     /** Liquibase logger */
  16.     private final Logger logger = LogFactory.getInstance().getLog("liquibase");

  17.     /** the sql to execute */
  18.     private String sql;

  19.     /** the expected result */
  20.     private String expectedResult;

  21.     @SuppressWarnings("rawtypes")
  22.     @Override
  23.     public void check(final Database database) throws CustomPreconditionFailedException, CustomPreconditionErrorException {

  24.         try {
  25.             
  26.             logger.debug("CustomBuildCheck is executed...");

  27.             final List<Map<String, ?>> resultQuery =
  28.                     ExecutorService.getInstance().getExecutor(database).queryForList(
  29.                             new RawSqlStatement(getSql().replaceFirst(";$", "")));

  30.             if (resultQuery == null) {
  31.                 throw new CustomPreconditionFailedException("No rows returned from SQL Precondition");
  32.             }

  33.             final int size = resultQuery.size();
  34.             
  35.             logger.debug("result is :" + size);
  36.             logger.debug("expected result is :" + expectedResult);
  37.             
  38.             final Integer resultInteger = new Integer(size);
  39.             final Integer expectIntegerResult = new Integer(expectedResult);

  40.             if (!expectIntegerResult.equals(resultInteger)) {

  41.                 logger.debug("We have some errors! displaying the result");

  42.                 final StringBuilder invalidObject = new StringBuilder();
  43.                 
  44.                 int counter = 1;
  45.                 for (final Map<String, ?> map : resultQuery) {

  46.                     invalidObject.append("  " + counter + " )  ");

  47.                     for (final Map.Entry entry : map.entrySet()) {
  48.                         invalidObject.append(entry.getValue());
  49.                         
  50.                         //Avoid the last -
  51.                         if (!entry.getKey().equals(LAST_DDL_TIME)) {
  52.                             invalidObject.append(" - ");
  53.                         }

  54.                     }

  55.                     invalidObject.append("\n");
  56.                     counter++;
  57.                 }

  58.                 final StringBuilder message = new StringBuilder();
  59.                 message.append("\n");
  60.                 message.append("\n");
  61.                 message.append("\n");
  62.                 message.append("--------------------------------------------------------------------------------------------- \n");
  63.                 message.append("               ERROR - There are " + size + " invalid Objects in the Database \n");
  64.                 message.append("--------------------------------------------------------------------------------------------- \n");
  65.                 message.append("      OWNER - OBJECT NAME - STATUS - LAST DDL TIME \n");
  66.                 message.append("\n");
  67.                 message.append(invalidObject.toString());
  68.                 message.append("\n");
  69.                 message.append("--------------------------------------------------------------------------------------------- \n");
  70.                 message.append("\n");
  71.                 message.append("\n");

  72.                 throw new CustomPreconditionFailedException(message.toString());
  73.             }

  74.         } catch (final DatabaseException e) {
  75.             throw new CustomPreconditionFailedException(e.getMessage());
  76.         }
  77.     }

  78. }
ChangeLog file

  1. <changeSet id="dataBaseCheck_v2" author="e-ballo" runAlways="true">
  2. <preConditions onFail="HALT">
  3. <customPrecondition
  4. className="nl.tele2.bos.liquibase.custom.preconditions.CustomBuildCheck">
  5. <param name="sql" value="SELECT alo.owner
  6.                                   ,alo.object_name
  7.                                   ,alo.status
  8.                                   ,alo.last_ddl_time
  9.                              FROM all_objects alo
  10.                             WHERE status = 'INVALID'
  11.                               AND alo.owner in ('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.                          ORDER BY alo.owner, alo.object_name;"/>
  18. <param name="expectedResult" value="0" />
  19. </customPrecondition>
  20. </preConditions>
  21. </changeSet>
Sample output:

SEVERE 10/30/14 9:52 AM: 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:
     Reason:
          liquibase/changelogs/bos-incremental-changelog.xml : Custom Precondition Failed:


---------------------------------------------------------------------------------------------
               ERROR - There are 1 invalid Objects in the Database
---------------------------------------------------------------------------------------------
      OWNER - OBJECT NAME - STATUS - LAST DDL TIME

  1 )  ZON - T2_ORDER_ENTRY_PCK - INVALID - 2014-10-30 09:52:36.0

---------------------------------------------------------------------------------------------



Re : Validation and Output

$
0
0
Great, thanks for sharing.

Nathan

Error executing SQL --rollback drop table test: Invalid SQL type: sqlKind = UNINITIALIZED

$
0
0
Hi,

I am trying to execute following changeset using liquibase:

--liquibase formatted sql

--changeset create_table:001

create table test (
    id int primary key,
    name varchar(255)
);
--rollback drop table test;

--changeset insert:2
insert into test (id, name) values (1, 'first');
insert into test (id, name) values (2, 'second');

Post execution I see following error messages in the stdout:

Error executing SQL --rollback drop table test: Invalid SQL type: sqlKind = UNINITIALIZED
liquibase.exception.DatabaseException: Error executing SQL --rollback drop table test: Invalid SQL type: sqlKind = UNINITIALIZED
Not sure why by my rollback
comment is bring treated as another sql to execute. I looked around other discussion and checked if my
liquibase formatted sql has any special characters, ran dos2unix command against the file but am still get the same error message. 

I am running following version of liquibase:

$ cat buildinfo.properties
#Mon Jun 02 10:55:49 CDT 2014 build.timestamp=Mon Jun 02 10:55:49 CDT 2014 build.version=3.2.0

Any help/suggestions to resolve this would be appreciated.

Thanks in advance.

Re : Compability issues between master of liquibase-core and liquibase-hibernate

junit compile scope

$
0
0
liquibase-core-3.3.0 depends on junit:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
</dependency>
Is it really necessary to use the compile scope?

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

$
0
0
I wouldn't pull one into the main Liquibase repo since it I think it would be an edge case for people, but it would make a good extension. I currently have liquibase.org/extensions as a place to reference available extensions and am planning on continuing to improve that.

Nathan

Re : Error executing SQL --rollback drop table test: Invalid SQL type: sqlKind = UNINITIALIZED

$
0
0
I'm not seeing it with 3.3.0, and possibly remember it being addressed with that version. Can you update and see if that fixes the problem?

Nathan

Re : junit compile scope

$
0
0
It currently is because there are portions of the "production" code that can be used by extension writers as starting points for testing their extensions. For normal use, junit isn't a runtime dependency, but it's needed to compile Liquibase.

I'm working on a refactoring of that to remove the dependency and better split the SDK out. 

Nathan

Re : Liquibase 2.0.5 does not seem to commit between changesets against MySQL 5.5

$
0
0
I have the same problem and it happens every time a changelog contains a ChangeSet that
creates a new table with foreign key constraints and one or more other ChangeSet(s) that use dropAllForeignKeyConstraints tag  to drop all foreing key constraints from that same table.

But the problem is not caused by MySQL or missing database commit, but due to the way the class
liquibase.change.core.DropAllForeignKeyConstraintsChange is implemented.

On the validation stage, liquibase.change.core.DropAllForeignKeyConstraintsChange.generateStatements(Database)
method is called, and here there are some lazy initialization statements for the private List attribute childDropChanges: on this stage both the new table has not been created yet and private attribute childDropChanges is not initialized yet, so the private method generateChildren(Database database) is called, but it doesn't find any foreign key constraint defined for the baseTableName declared (the table doesn't exist yet!), so the childDropChanges List attribute is initialized, empty...

When run stage arise, the List attribute childDropChanges of DropAllForeignKeyConstraintsChange has been
inizialized, so the lazy initialization code inside generateStatements(Database) is skipped, leaving the
List childDropChanges empty, even if, in the mean time, other ChangeSet created the table and its foreign key
constraints that one expects should be dropped!

So the change run successfully with an empty list of constraint to drop, leaving the table unchanged!

I'm stuck to the 2.0.5 version due to incompatibility of new versions of Liquibase with some extensions of mine: any solutions to suggest?

Many thanks in advance
Regards
Roberto

MySQL 5.6 keywords `partition' not quoted as a column name

$
0
0

I am trying to upgrade my liquibase to 3.3.0 

If the column contains a keyword, such as "PARTITION". the migration fails.

e.g. the generated SQL DDL contains: PARTITION VARCHAR(20) NOT NULL
because there is a change set about creating a table with a column called key.

I found the similar closed bug https://liquibase.jira.com/browse/CORE-1478. It is fixed for word "key". I have the same problem with "PARTITION".


My change set is :

<changeSet id="create table  TABLE_1 " author="tomcat">

        <createTable tableName=" TABLE_1 ">

            <column name="PARTITION" type="VARCHAR(64)"/>

            <column name="NAME" type="VARCHAR(255)"/>

        </createTable>

   </changeSet>

Re : Error executing SQL --rollback drop table test: Invalid SQL type: sqlKind = UNINITIALIZED

$
0
0
Hi Nathan,

It was silly mistake from my end, was trying to call formatted sql having this in my changelog.xml <sqlFile path = "ddl/myfile.sql" />. The correct syntax is <include file="ddl/myfile.sql"/>. Apologies for bothering you!!

Thanks.

Re : Formatted SQL with a comment.

$
0
0
Hi Nathan,

I checked the jira ticket related to this, it seems it has been fixed in liquibase version 3.2.0, however I am not able to add comment via my formatted sql. Any ideas/sugestions?

Here's how my formatted sql looks like:

--liquibase formatted sql
--changeset ascii:001
--comment CREATE TABLE
create table ascii (
    id int primary key,
    name varchar(255)
);
--rollback drop table ascii;

--changeset ascii:002
--comment INSERT TABLE
insert into ascii (id, name) values (1, 'first');
insert into ascii (id, name) values (2, 'second');
insert into ascii (id, name) values (3, 'third');

Am i missing something? I am running liquibase version 3.2.0.

Labels vs. contexts in 3.3.0

$
0
0
While I understand the gist behind labels and contexts, I'd like to hear about the use cases that caused this feature to exist.

Also, are they documented on the main site?  I'm not sure where I can put labels in my changesets.

Thanks very much,
Best,

What is the ResourceAccessor#list() method used for?

$
0
0
Hello; I would like to know what the ResourceAccessor#list(String, String, boolean, boolean, boolean) method is used for.

I am curious because I have written a URLResourceAccessor.  I am unsure whether to try to delegate or emulate this method or simply return null, since as a general rule a URL can't "list" its contents.

Best,

Re : Labels vs. contexts in 3.3.0

$
0
0
I added http://blog.liquibase.org/2014/11/contexts-vs-labels.html for some additional background. 

Labels can be added to changeSets the same as contexts. 

The concrete use case behind adding labels was a company that is basically trying to get around not using version control branches. They want to label changeSets based on features (instead of creating a branch) and then selectively "merge" those features at execution time. 

The idea of giving the deployment team the power to write complex logic is more general than that particular use case, which is why the more generic "label" term was created.

Nathan

Re : Labels vs. contexts in 3.3.0

$
0
0
Thanks.  That's interesting.  Viewed from a really high level, both are ways of dynamically whittling a changelog down at runtime.

My concrete use case is locale-specific changesets.  Picture an installation where the guy running Liquibase says, "OK, what language packs do you want?" and he gets an answer.  Then depending on the answer, he does something with expressions or whatever that indicates, say, that the Spanish and English language changesets should be run.

Is that a case better suited for contexts (seemingly so)?

Best,

Re : Labels vs. contexts in 3.3.0

$
0
0
Yes, at a high level that is what they both do.

I think contexts would make the most sense in your case because at runtime the description of the environment is just a simple list of the languages you want installed "EN", "ES", "EN, ES", etc. 

When in doubt, I usually go with contexts because it will simplify deployment configuration while giving changeSet authors the option to handle complex logic if needed.

Nathan

Re : What is the ResourceAccessor#list() method used for?

$
0
0
I think it is only used with includeAll, so if you cannot list all it's contents you won't be able to use includeAll. Otherwise it should be fine to return null.

Nathan
Viewing all 2993 articles
Browse latest View live


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