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

Re-start using liquibase on project

$
0
0
I have in my project liquibase set up and all is working fine. There is initial xml files, made one year ago and a lot of change sets that are made meanwhile.

I run all change-sets for test executions. That mean I run initial change set and also all differential scripts(new columns, changed types). I want to reduce time of this execution. I was thinking about this:

1. on existing database run generateChangeLog for both structure and data (in this way I will get much less code, because there way a lot of changesmeanwhile, eg. add column table.column1, change type of table.column1, delete column,...... This mean that I will have much less change sets)

2. Instead of old files I want to use generated ones.

I have stable environments where old change sets have been executed. This mean than table databasechangelog is already populated with old values. (values from old files)

Now, I want to execute new change set what will be written starting now in old environments. This will not work because for example: I have table A in my DB, but change set I am executing has: create table A;

What is best way to solve this problem? 

In short: I have databasechangelog populated, but I have to re-create all files, and I want  to be able to run re-created change sets for test, but also to be able to execute same xml files for future sets.

Creating a table with liquibase xml using api java with context defined not working

$
0
0
Hi,
I need update my database with new changesets of one especific context. When a run my code, the liquibase runs normally, but the table is not created. Nothing error is showed, so it is very difficult to understand the problem. What do I doing wrong?

My code is:

  1. Connection connection = // my connection
  2. Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
  3. Liquibase liquibase = new Liquibase("config/liquibase/master.xml", new ClassLoaderResourceAccessor(), database);
  4. liquibase.update( "TEST" );

Like a said, the liquibase runs but don't create my table from xml. I am using 3.4.1 for liquibase and java 8.

Re : Creating a table with liquibase xml using api java with context defined not working

$
0
0
If there was some sort of error, I am pretty certain that the liquibase.update() method would throw an exception. If it is not, then Liquibase believes it is operating 'as designed', so the likelihood is that the problem is with the state of the changelog vs. the state of the database. 

There is another API you can use to see what the status is for all of the changesets - if you call liquibase.getChangeSetStatuses(contexts) you will get back a List<ChangeSetStatus> that you can iterate over and see what is happening. 

Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/

Re : Creating a table with liquibase xml using api java with context defined not working

$
0
0
Thanks so much Steve, you was very fast!

First, let me to explain the cenario that I am developing. I am buiding a graphic interface that choose a database, a context tag and the rotine from liquibase (update, rollback) to run. I choose all the params and the new changes are running in the database choosed.

I used the API that you told me:

  1. List<ChangeSetStatus> list = liquibase.getChangeSetStatuses(new Contexts("TEST"));
  2. for (ChangeSetStatus change : list) {
  3.    System.out.println(change.getDescription() + " - " + change.getChangeSet().getFilePath());
  4. }

So, the code threw eighteen lines, the number of all my changesets exactly. The last line (changeset), it is the one that I want to run because of the context that I choosed on interface.

The cenario what I want, is it possible?

Thanks.

Re : Creating a table with liquibase xml using api java with context defined not working

$
0
0
I'd like to help you, but you aren't giving me much information to work with. What you want to do seems completely possible - it is exactly what Liquibase is designed to do.

So - what is the 'willRun' value of each of your changesets? What is the dateLastExecuted? Since you are writing your own code and using the API, maybe you could try debugging through it to see what it is doing.

Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/

Liquibase 3.4.2 H2 database

$
0
0
Hello 

We recently upgraded liquibase to use the latest version (3.4.2) and we use H2 in memory database. With the new version I'm getting the below exception 

2016-04-20 10:08:12,284 [main] ERROR - [h2database.write()] - jdbc[6] exception org.h2.jdbc.JdbcSQLException: Table "DATABASECHANGELOGLOCK" not found; SQL statement:
select count(*) from PUBLIC.DATABASECHANGELOGLOCK [42102-180]

This works perfectly fine with 3.3.0. 

Could someone please help.

Thanks in advance

Regards
Vinitha

Some additional information after some debugging....following code in SnapshotGeneratorFactory seems to be the problem creator. Are there any additional flags that we can set to indicate its in memory and database changelock table will not be available ?

   //workaround for common check for databasechangelog/lock table to not snapshot the whole database like we have to in order to handle case issues
        if (example instanceof Table && (example.getName().equals(database.getDatabaseChangeLogTableName()) || example.getName().equals(database.getDatabaseChangeLogLockTableName()))) {
            try {
                ExecutorService.getInstance().getExecutor(database).queryForInt(new RawSqlStatement("select count(*) from " + database.escapeObjectName(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName(), example.getName(), Table.class)));
                return true;
            } catch (DatabaseException e) {
                if (database instanceof PostgresDatabase) { //throws "current transaction is aborted" unless we roll back the connection
                    database.rollback();
                }
                return false;
            }
        }

Re : Creating a table with liquibase xml using api java with context defined not working

$
0
0
Hi Steve,

I discovered what was the problem! Debugging, I gave pass the wrong context to the liquibase! So, now it works normally.

Thanks for your help.

Re : Cannot get diff against Hibernate to work in ant

$
0
0
I have very limited experience with the hibernate plugin but based on the ClassNotFoundException I would say that the classpath given to the ant task doesn't have everything it needs to run. The javax.persistence package tells me that it is missing the JPA API/interface jar (I think that is something like persistence-api.jar). You can try to print out the classpath that to see if all the jars you expect are present. You can print out a path with an id like this (Ant >= 1.7).
  1. <echo>${toString:mypath.classpath}</echo>

Hope this helps.


Re : Liquibase 3.4.1 - unsupported database Exasol issue

$
0
0
Hi,

I am trying to do the liquibase implementation for exasol and I have the same issues. 
I changed the type of LOCKED column to BOOLEAN and then to VARCHAR, in both cases I get:

Unexpected error running Liquibase: java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.Integer

lzkrae, if you found the solution for that, I would be grateful if you'd shared it with everyone. 
Thanks

Re : Liquibase 3.4.2 H2 database

$
0
0
Can you post the full stacktrace? You may need to run with --logLevel=debug or something similar depending on how you run Liquibase.

Nathan

Re : Liquibase 3.4.2 H2 database

Wrong release date for 3.5.0 on download page

$
0
0
The download page states that 3.5.0 was released "Apr 19, 2015".

Shouldn't that be "Apr 19, 2016"?


Re : Wrong release date for 3.5.0 on download page

$
0
0
Yes it should. I fixed it up, thanks for pointing it out.

Nathan

Extending Liquibase CreateTableStatement

$
0
0
I need a simple extension to Liquibase to add a distribution clause to a postgresql variant.  I've created a project with a database that extends PostgresDatabase, a CreateTableGeneratorX that extends CreateTableGenerator and implements generateSql and a CreateTableStatementX that adds the properties that I need to set for the distribution clause.  The generated SQL should look something like:

  1. CREATE TABLE MYTABLE(columns...) distribute by HASH(column1);


I want to add the "distribute by" to the changleLog, XML or SQL DSL.  Can anyone tell me how to do this last part and test it?  The documentation for extension still seems fairly outdated.

Re : Extending Liquibase CreateTableStatement

$
0
0
I think I'm almost at a point where my extension should be workable.  I created the following:

liquibase.ext.pgxl.change.CreateTableChangePgxl - extends AbstractChange implements ChangeWithColumns<ColumnConfig>

liquibase.ext.pgxl.database.PgxlDatabase - extends AbstractJdbcDatabase

liquibase.ext.pgxl.sqlgenerator.CreateTableGeneratorPgxl - extends AbstractSqlGenerator<CreateTableStatementPgxl>

liquibase.ext.pgxl.statement.CreateTableStatementPgxl - extends CreateTableStatement


and registered them in my MANIFEST:

  1. Liquibase-Package: liquibase.ext.pgxl.change,liquibase.ext.pgxl.database,liquibase.ext.pgxl.sqlgenerator,liquibase.ext.pgxl.statement

I've also created an extension xsd which adds the distributionType and Column attributes.:

  1. <?xml version="1.0" encoding="UTF-8"?>

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:lb="http://www.liquibase.org/xml/ns/dbchangelog"
    targetNamespace="http://www.liquibase.org/xml/ns/dbchangelog-ext/liquibase-postgresxl"
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog-ext/liquibase-postgresxl"
    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.5.xsd"
    elementFormDefault="qualified">
    <xsd:import namespace="http://www.liquibase.org/xml/ns/dbchangelog"
    schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd" />


    <xsd:element name="createPgxlTable">
    <xsd:complexType>
    <xsd:choice maxOccurs="unbounded">
    <xsd:element ref="lb:column" minOccurs="1" maxOccurs="unbounded"/>
    <xsd:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:choice>
    <xsd:attributeGroup ref="lb:tableNameAttribute"/>
    <xsd:attribute name="tablespace" type="xsd:string"/>
    <xsd:attribute name="distributionType" type="xsd:string"/>
    <xsd:attribute name="distributionColumn" type="xsd:string"/>
    <xsd:attribute name="remarks" type="xsd:string"/>
    <xsd:anyAttribute namespace="##other" processContents="lax"/>
    </xsd:complexType>
    </xsd:element>

    </xsd:schema>


I then try to use this in my changelog:

  1. <databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext/liquibase-postgresxl"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd
    http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
    http://www.liquibase.org/xml/ns/dbchangelog-ext/liquibase-postgresxl ../../resources/xsd/changelog-ext.xsd"

    >

    <changeSet id="9" author="Rob">
    <ext:createPgxlTable tableName="test" distributionType="HASH" distributionColumn="ID" schemaName="shared_data">
    <column autoIncrement="false" name="ID" type="INTEGER" />
    </ext:createPgxlTable>
    </changeSet>


    </databaseChangeLog>


But when I run liquibase update or updateSQL, my changeset runs...  but does nothing with the createPgxlTable.  It seems like something isn't being registered with liquibase.

Semantics of ignoreClasspathPrefix

$
0
0
I am using Liquibase through the Spring integration to run any changesets on application start-up.  Since the changelog is part of a jar, I specify the location in one of my property files as:
liquibase.change-log = classpath:db/changelog/current.xml

Liquibase gets set up by Spring Boot's auto-configuration mechanism.  When a changeset us run, the file name is recorded in DATABASECHANGELOG as classpath:db/changelog/current.xml.

I am also using the Gradle plugin to provide a way to update the database without running the application.  When I run with the same changelog file, the recorded file name doesn't have the prefix (I am still loading it from the class path, by specifying it in the respective activity).

Liquibase provides the ignoreClasspathPrefix property (which is true by default) to deal with this discrepancy and it does work to some extent.  If I apply the changesets through Gradle first, the Spring app will recognize that they have been run and skips them.  However, if the changesets get executed by the Spring app first, gradle update will attempt to apply the changesets again and use the file name without the classpath: prefix.

It would seem that the ignoreClasspathPrefix property should remove the prefix from the file name before being recorded in DATABASECHANGELOG, to provide consistent behavior.  Or am I missing something in my setup?  Using Spring Boot 1.3.3.RELEASE and the Liquibase version it pulls by default (3.4.2).  Any insights would be appreciated.

Thanks,
Alex

Re : Extending Liquibase CreateTableStatement

$
0
0
In CreateTableChangePgxl did you annotate it with @DatabseChange and a priority higher than PRIORITY_DEFAULT? 

Also, do you have a CreateTableGenerator subclass that uses the new Statement class?

Nathan

Re : Extending Liquibase CreateTableStatement

$
0
0
Thanks for responding Nathan.  

I have:

@DatabaseChange(name="createPgxlTable", description = "create tables"
priority =  ChangeMetaData.PRIORITY_DATABASE)
public class CreateTableChangePgxl extends AbstractChange implements ChangeWithColumns<ColumnConfig>
{.......
}

And for the generator:

public class CreateTableGeneratorPgxl extends AbstractSqlGenerator<CreateTableStatementPgxl>
{.......
@Override
public int getPriority() {
return PRIORITY_DATABASE;
}
.......
}


This is my output from updateSQL:

-- Lock Database
UPDATE public.databasechangeloglock SET LOCKED = TRUE, LOCKEDBY = '192.168.1.187 (192.168.1.187)', LOCKGRANTED = '2016-05-18 18:49:28.290' WHERE ID = 1 AND LOCKED = FALSE;

-- Changeset changelog/changelog.xml::11::Rob
INSERT INTO public.databasechangelog (ID, AUTHOR, FILENAME, DATEEXECUTED, ORDEREXECUTED, MD5SUM, DESCRIPTION, COMMENTS, EXECTYPE, CONTEXTS, LABELS, LIQUIBASE) VALUES ('11', 'Rob', 'changelog/changelog.xml', NOW(), 9, '7:d41d8cd98f00b204e9800998ecf8427e', 'Empty', '', 'EXECUTED', NULL, NULL, '3.4.2');

-- Release Database Lock
UPDATE public.databasechangeloglock SET LOCKED = FALSE, LOCKEDBY = NULL, LOCKGRANTED = NULL WHERE ID = 1;


Re : Checksum calculations and line ending styles

$
0
0
What version of Liquibase addressed this?

Re : Extending Liquibase CreateTableStatement

$
0
0
Try using a higher priority than PRIORITY_DATABASE. The standard database-specific CreateTable implemetnations will use that as well and may be selected instead. 

Try just setting priority to 100 on both classes.

Nathan
Viewing all 1169 articles
Browse latest View live


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