An alternative way to use Liquibase

There isn’t currently a data type precondition, but you could create your own using the extension system (liqubase.org/extensions). 


You could probably also override the change types you use and have the precondition built in so you don’t need to specify it in the changeSet. It does definitely go against the normal liquibase usage, but you are also already there :slight_smile:

Nathan

I am trying to use Liquibase in a different way.


I do not keep multiple xml files for changes in the database but instead just update only one single xml for each table, which I execute always ( in my application start-up )


This table xml is built in order to ‘detect’ any database changes and execute only the modifications

 - The logic is simple and based to preconditions

     - If table does not exist (precondition not->tableExists) create it with all the required columns

     - else for every column ( 2 changesets )

         - if column does not exist (precondition not->columnExists) add it 

         - if column exists modify the data type to the latest one  ( HERE IS THE PROBLEM )


The problem is that the last data type modification is executed always since there is no such a precondition

( e.g  columnDataTypeEquals  )


I am attaching the xml I use for a simple 2 column table TEST_TABLE ( id, test_column)

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

   

       

           

       

       

           

               

           

           

       

   

   

       

           

       

       

           

       

   

   

       

           

       

       

           

       

   

   

       

           

       

       

   



Well , I chose to solve the above with a custom precondition , thanks. ( below is the easy solution )

Additionally , I noticed I have to do the same for NULL to NOT NULL modifications

There is no such precondition ( e.g   <isNullableColumn …column , table etc >  and  <isNotNullable … )


Seems to be a relatively easy implementation ( it’s a piety not to include it into the next API version )

Below is the simple solution I implemented for the original post’s problem.

Thanks again, for the reply 


The custom precondition solution for the changed datatype is the following

  • xml

 

   

   <param name=“columnName” value="<span);


      } catch(DatabaseException e) {

         throw new CustomPreconditionErrorException(StringUtil.stackTrace(e));

      }

   }


}

Thanks. I created  https://liquibase.jira.com/browse/CORE-1138 to make sure it gets build and included somewhere more accessible.


Nathan