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

Re : Liquibase modify dbchangelog table


Preconditions column exists

$
0
0

Using liquibase 3.4.1 I want to rename my columns in Oracle to uppercase if they exist. I always get the following error no matter what I do:

Unexpected error running Liquibase: ORA-00957: duplicate column name
 [Failed SQL: ALTER TABLE "SYSTEM"."MYTABLE" RENAME COLUMN "id" TO "ID"]

My precondition looks like this:

    <changeSet author="sake" id="gfdgfd" dbms="oracle" objectQuotingStrategy="QUOTE_ALL_OBJECTS">
            <preConditions onFail="MARK_RAN" >          
                      <columnExists tableName="MYTABLE" columnName="id" />
            </preConditions>
            <renameColumn tableName="MYTABLE" oldColumnName="id" newColumnName="ID"/>
</changeSet>

I tried following: - removing objectQuotingStrategy - adding SQL check:

<sqlCheck expectedResult="1">
                SELECT COUNT(*) FROM USER_TAB_COLUMNS
                WHERE TABLE_NAME='MYTABLE'
                AND COLUMN_NAME='id'
            </sqlCheck>

Any idea why this happens? :/

Password encryption in Liquibase properties file

$
0
0
To manage migration with Liquibase, I am using a properties file that holds all the information about the database connection. The pitfall of this file is that it discloses my database password since it is a plain text file. Is there a way to avoid that ? Does Liquibase support any kind of encryption for the properties file ?

Re : Password encryption in Liquibase properties file

While executing the liquibase script, how to print the comment the one which is defined in the above changeset ?

$
0
0
<changeSet id="Aug050815" author="myApplication" >
   <comment>Test comments 1</comment>
   </changeSet>
</databaseChangeLog>


While executing the liquibase script, how to print the comment the one which is defined in the above changeset ?

Silently stopping Liquibase at mid-update

$
0
0

Is there any way I can cancel a Liquibase update after I started it?

I've a list with around 5000 changesets, and I need to prevent all changesets from a specific point forward, to not be executed if a specific condition occurs in one of those scripts.

Since putting <preConditions> in all of the existing scripts, and to all the new ones that will be created until the end of days, is not a doable approach, I was looking into an alternative and already tried the following:

  • Created a <customChange> and throw an exception
  • Created an invalid <sql> statement
  • Added <stop/> in the <changeset>

All cases work, but they also throw thousands of log lines (that I can't have), because I need a silent stop.

Translator from MySQL to liquibase

$
0
0
Do you guys know if there are any tools to convert SQL scripts into LB .xlm files? It would really come in handy in order to import all my previous changes and sum them up in order to be able to do a fresh install of my app.

Re : While executing the liquibase script, how to print the comment the one which is defined in the above changeset ?

$
0
0
You would need to run Liquibase programatically (i.e. from your own Java code) and write a class that implements the ChangeExecListener interface. The class implementing the interface would get notified of all changes and would be able to examine the changeset and print out the comment if there was one. 

There is currently no way to specify a ChangeExecListener from the command line, maven, ant, etc. 

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

Re : Translator from MySQL to liquibase

$
0
0
I assume you mean .xml rather than .xlm

What you would do is:

1. Create a clean, empty database.
2. Apply the SQL scripts that you have to the database.
3. Run the Liquibase generateChangelog command on that database.

Note that this will only capture the end state of the database - i.e. if you have a SQL script that creates a table, and then another later SQL script that drops the table, the XML will not have a <createTable> and a <dropTable>.

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

Liquibase java not applying changesets

$
0
0
Hi,

I'm using Liquibase directly from Java 8, after adding the Maven dependency for Liquibase 3.4.0.
My project includes some database interactions with an Oracle 11g database (I included ojdbc6.jar in the build path and liquibase-oracle-3.0.0.jar as a maven dependency). My changelog is composed with a single changeset of creating a table if it doesn't exist (precondition with onSQLOutput="TEST"). When I run this changelog with the command line, everything works fine, but when I launch it with my Java application, something goes wrong (my simplified java code is written down below).
With the update action, this task simply does nothing. With updateSQL or futureRollbackSQL, it generates a file creating the tables of Liquibase (databasechangelog and databasechangeloglock), but does not include my changeset.
I'm 100% sure that the table does not exist on the given database.

I'm a little lost now, I don't know what to do or what's wrong. I checked at some examples from other topics, but I can't see any error in my code in my code (well... there should be one, obviously). Even posted this question on stackoverflow and didn't get any answer.

So I would be very grateful if you could help me point out my mistake(s) on this application !

Tell me if you need more details.

Thank you for your answers.

Java Code
  1. Connection c = null;
  2. Database database = null;
  3. PrintWriter pw = null;
  4. File file = null;
  5. liquibase.Liquibase liquibase = null;
  6. contexts = db+"."+user;
  7. try {
  8.     pw = new PrintWriter(new FileWriter(file));
  9.     // Get connection
  10.     c = SQLManager.getInstance().getConnection(db, user, passwd);
  11.     // Get liquibase connection
  12.     database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(c));
  13.     liquibase = new liquibase.Liquibase(new DatabaseChangeLog(fsource), new FileSystemResourceAccessor(),
  14.             database);
  15.     // Run liquibase action
  16.     switch (realAction) {
  17.         case Constants.LIQUIBASE_ACTION_FUTUREROLLBACKSQL:
  18.             liquibase.futureRollbackSQL(pw);
  19.             break;
  20.         case Constants.LIQUIBASE_ACTION_UPDATESQL:
  21.             liquibase.update(contexts, pw);
  22.             break;
  23.         case Constants.LIQUIBASE_ACTION_UPDATE:
  24.             liquibase.update(contexts);
  25.             if (!c.getAutoCommit())
  26.                 c.commit();
  27.             break;
  28.         default:
  29.             throw new RuntimeException("Action not implemented");
  30.     }
  31.     pw.close();
  32.     database.close();
  33.     c.close();
  34. } catch (IOException | SQLException | LiquibaseException e) {
  35.     throw new Exception(e.getMessage());
  36. } finally {
  37.     if (c != null) {
  38.         try {
  39.             c.close();
  40.         } catch (SQLException e) {
  41.             throw new RuntimeException(e.getClass() + ": " + e.getMessage());
  42.         }
  43.     }
  44. }

Re : Preconditions column exists

$
0
0
Oracle doesn't consider case when checking for table names or column names.
Thus you don't even have to rename your columns !

Re : Silently stopping Liquibase at mid-update

$
0
0
If you know the number of changesets you have to apply, you could use the equivalent of command line's action "updateCount <value>" in whatever way your are using liquibase.

Or is there no way to break your changelog into much smaller pieces? If you have to stop changesets from executing starting at some point, then you should have a way to create much smaller changelogs (with eventually one big changelog composed with includes).

Re : Liquibase java not applying changesets

dropAll fails when tables have child partitions - postgres

$
0
0
When running dropAll, and the database has a partitioned table, the dropAll process fails when attempting to drop the partitions. (Liquibase version 3.4.1, Postgres 9.4)

master_table
master_table_201508 (partition table)
master_table_201509 (partition table)

"master_table" is created by liquibase, but the partitions are created by a trigger/function

It looks as though liquibase is taking a "snapshot" of the existing tables and then dropping one-by-one. However when the "master_table" is dropped, the partitions are also dropped and liquibase gives the following error when trying to delete the partition tables.

ERROR: table "master_table_201508" does not exist [Failed SQL: DROP TABLE "public"."master_table_201508" CASCADE

Is there a way to work around this? i.e by turning off the cascade delete or changing how the dropAll is handled?

Thanks


Re : Translator from MySQL to liquibase

$
0
0
Thank you for the answer. My bad with the ".xlm" typo. I was looking for something to convert individual sql scripts int xml change sets. If there isn't any similar tool around, I'll just make one with the most frequent commands myself. If anybody is interested, I would gladly share it, because I consider it a useful thing to have. Good day to you all.

Re : Silently stopping Liquibase at mid-update

$
0
0

Or is there no way to break your changelog into much smaller pieces? If you have to stop changesets from executing starting at some point, then you should have a way to create much smaller changelogs (with eventually one big changelog composed with includes).
I already have lots of small changesets. Don't understand exactly your suggestion here.

Re : Silently stopping Liquibase at mid-update

$
0
0
I already have lots of small changesets. Don't understand exactly your suggestion here.
 
I was speaking about breaking your big changelog into smaller changelogs (not changesets) and applying only the last ones.

Re : Translator from MySQL to liquibase

$
0
0
Ah, I see what you are saying. In that case, I can see how a tool might be useful. We have written something like that recently using DaticalDB. We have a command line interface for DaticalDB that is somewhat similar to the one for Liquibase, but works with "project" files that can contain connection information for multiple databases. The command line itself is scriptable using groovy. We wrote a groovy script that will do basically what is described above, but for multiple SQL files. Right now our target databases are Oracle and MS SQL Server, so we use their command line tools to apply the SQL scripts to the database, then use the Liquibase diffChangelog command to 'convert' the SQL that was applied to the database into XML changesets. 

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

Re : Silently stopping Liquibase at mid-update

$
0
0
Your answers gave me an idea and since we are dynamically creating an include changelog file, for all the smaller changelogs, I simple iterate all the smaller changelog files until I reach the file from each things can be executed or not.
Then I execute a query to check for the specific condition, and if everything run ok, I create another dynamic changelog file with the remaining changelogs.

Re : [SOLVED] - Silently stopping Liquibase at mid-update

$
0
0
If I understand correctly:
  1. You got your changesets in tiny changelog files.
  2. You include all these mini changelogs into an include changelog file generated dynamically at process start, which will include all the changesets created up to this day.
  3. You run the big file.
Is that it ?

In this case, can't you save the last changeset applied by this method and start dynamic generation starting from this saved data ?
Viewing all 1169 articles
Browse latest View live