Total Pageviews

Showing posts with label liquibase. Show all posts
Showing posts with label liquibase. Show all posts

2018/06/09

[liquibase] How to add new column in YAML?

Problem
I attempt to add new column in existing table, how to define these change in YAML?


How-To
YAML will looks like:
  - changeSet:
      id: 4
      author: albert
      changes:     
       - addColumn:
          tableName: model_sentence
          columns:  
          - column:
             name: is_green_icon
             type: int


Reference
[1] http://www.liquibase.org/documentation/changes/add_column.html

2018/06/08

[liquibase] How to rename column and modify data type in YAML?

Problem
I attempt to rename an existing column name and modify its data type in liquibase, how to define these changes in YAML?


How-To
YAML will looks like:
  - changeSet:
      id: 4
      author: albert
      changes:     
       - renameColumn:
          tableName: model
          oldColumnName: PREDICT_JSON
          newColumnName: STATISTICS_JSON        
       - modifyDataType:
          tableName: model
          columnName: STATISTICS_JSON
          newDataType: text


Reference
[1] http://www.liquibase.org/documentation/changes/rename_column.html
[2] http://www.liquibase.org/documentation/changes/modify_data_type.html

2018/02/11

[Liquibase] How to fix checksum validation error

Problem
I am editing changelog-master.yaml, I got error message as I start up Spring boot:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liquibase' defined in class path resource [org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfiguration$LiquibaseConfiguration.class]: 
Invocation of init method failed; nested exception is liquibase.exception.ValidationFailedException: Validation Failed:
     1 change sets check sum
          classpath:/db/changelog/db.changelog-master.yaml::1::albert was: 7:6e574692a29b35c6788f06c99fe2eecc but is now: 7:c5994a0c5ad9c2ba211a4f8e3ced2ec9


How-To
Here has the process to solve this problem:
1. drop all tables which had already created in liquibase
2. clear all data in databasechangelog table
delete from databasechangelog


2017/03/03

[liquibase] Caused by: liquibase.exception.LockException: Could not acquire change log lock

Problem

I am running a lot of liquibase-scripts on PostgreSQL database, and get error message as I startup Spring Boot:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
Waiting for changelog lock....
Waiting for changelog lock....
Waiting for changelog lock....
Waiting for changelog lock....
Waiting for changelog lock....
Waiting for changelog lock....
Caused by: liquibase.exception.LockException: Could not acquire change log lock.  Currently locked by albert-PC (10.11.22.33) since 2016/9/26 下午 2:06
 at liquibase.lockservice.StandardLockService.waitForLock(StandardLockService.java:190) ~[liquibase-core-3.5.1.jar:na]
 at liquibase.Liquibase.update(Liquibase.java:196) ~[liquibase-core-3.5.1.jar:na]
 at liquibase.Liquibase.update(Liquibase.java:192) ~[liquibase-core-3.5.1.jar:na]
 at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:434) ~[liquibase-core-3.5.1.jar:na]
 at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:391) ~[liquibase-core-3.5.1.jar:na]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE]
 ... 160 common frames omitted


How-to
The problem was the buggy implementation of SequenceExists in Liquibase. Since the changesets with these statements took a very long time and was accidently aborted. Then the next try executing the liquibase-scripts the lock was held.
Therefore, you can execute this DML to update DATABASECHANGELOGLOCK table:

UPDATE DATABASECHANGELOGLOCK SET LOCKED=FALSE, LOCKGRANTED=null, LOCKEDBY=null where ID=1

Reference

[1] https://stackoverflow.com/questions/15528795/liquibase-lock-reasons