I'm trying to use liquibase (3.5.5) from an existing database (on MySQL).
I've used the generateChangeLog command to generate a db.changelog.xml file.
C:/liquibase-3.5.5/liquibase.bat --driver=com.mysql.jdbc.Driver ^ --classpath=C:/Libraries/mysql-connector-java-5.1.37-bin.jar ^ --changeLogFile=db.changelog.xml ^ --url="jdbc:mysql://vbalder/izalerting" ^ --username=* ^ --password=* ^ generateChangeLog
result: Liquibase 'generateChangeLog' Successful
The generated db.changelog.xml file contains changeSets with author BGADEYNE (generated)
and id's who are prepended by 1533645947580-
. e.g. 1533645947580-1
- Added
logicalFilePath="db.changelog.xml"
to the databaseChangeLog tag I've used the changelogSync command to create and fill the DATABASECHANGELOG and DATABASECHANGELOGLOCK tables. They do contain rows for each changeSet.
C:/liquibase-3.5.5/liquibase --driver=com.mysql.jdbc.Driver ^ --classpath=C:/Libraries/mysql-connector-java-5.1.37-bin.jar ^ --changeLogFile=db.changelog.xml ^ --url="jdbc:mysql://vbalder/izalerting" ^ --username=izalerting ^ --password=alfa ^ changelogSync
result: Liquibase 'changelogSync' Successful
- Created a CDI component to execute the db.changelog.xml when the application starts.
Added maven dependency:
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-cdi</artifactId>
<version>3.5.5</version>
</dependency>
Added CLI component:
@Dependent
public class LiquibaseProducer {
@Resource(name="java:/izalerting")
private DataSource dbConnection;
@Produces @LiquibaseType
public CDILiquibaseConfig createConfig() {
CDILiquibaseConfig config = new CDILiquibaseConfig();
config.setChangeLog("be/uzgent/iz/alerting/liquibase/db.changelog.xml");
config.setContexts("non-legacy");
return config;
}
@Produces @LiquibaseType
public DataSource createDataSource() throws SQLException {
return dbConnection;
}
@Produces @LiquibaseType
public ResourceAccessor create() {
return new ClassLoaderResourceAccessor(getClass().getClassLoader());
}
}
When deploying the application to WildFly i can see this
2018-08-07 15:07:09,234 ERROR [stderr] (MSC service thread 1-4) INFO 8/7/18 3:07 PM: liquibase.integration.cdi.CDILiquibase: Booting Liquibase 3.5.4 2018-08-07 15:07:09,285 ERROR [stderr] (MSC service thread 1-4) INFO 8/7/18 3:07 PM: liquibase: Successfully acquired change log lock 2018-08-07 15:07:09,781 ERROR [stderr] (MSC service thread 1-4) INFO 8/7/18 3:07 PM: liquibase: Reading from PUBLIC.DATABASECHANGELOG 2018-08-07 15:07:09,814 ERROR [stderr] (MSC service thread 1-4) SEVERE 8/7/18 3:07 PM: liquibase: db.changelog.xml: db.changelog.xml::1533645947580-1::BGADEYNE (generated): Change Set db.changelog.xml::1533645947580-1::BGADEYNE (generated) failed. Error: Table "ALERTRESULT" already exists; SQL statement: 2018-08-07 15:07:09,815 ERROR [stderr] (MSC service thread 1-4) CREATE TABLE PUBLIC.alertresult (triggerid VARCHAR(255) NOT NULL, application VARCHAR(40) NOT NULL, resultid INT NOT NULL, subject VARCHAR(255), content CLOB, contenturl CLOB, executetime TIMESTAMP, html BOOLEAN DEFAULT TRUE NOT NULL, alertlevel VARCHAR(20) DEFAULT 'INFO' NOT NULL, closable BOOLEAN DEFAULT TRUE NOT NULL, screenwidth INT, screenheight INT) [42101-173] [Failed SQL: CREATE TABLE PUBLIC.alertresult (triggerid VARCHAR(255) NOT NULL, application VARCHAR(40) NOT NULL, resultid INT NOT NULL, subject VARCHAR(255), content CLOB, contenturl CLOB, executetime TIMESTAMP, html BOOLEAN DEFAULT TRUE NOT NULL, alertlevel VARCHAR(20) DEFAULT 'INFO' NOT NULL, closable BOOLEAN DEFAULT TRUE NOT NULL, screenwidth INT, screenheight INT)] 2018-08-07 15:07:09,816 ERROR [stderr] (MSC service thread 1-4) INFO 8/7/18 3:07 PM: liquibase: db.changelog.xml::1533645947580-1::BGADEYNE (generated): Successfully released change log lock
The DATABASECHANGELOG table contains a row for each changeSet.
+------------------+-----------------------+-------------------+-----------+
| # ID | AUTHOR | FILENAME | EXECTYPE |
+------------------+-----------------------+-------------------+-----------+
| 1533645947580-1 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-2 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-3 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-4 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-5 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-6 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-7 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-8 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-9 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-10 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-11 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-12 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-13 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-14 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-15 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-16 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-17 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-18 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-19 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
| 1533645947580-20 | BGADEYNE (generated) | db.changelog.xml | EXECUTED |
+------------------+-----------------------+-------------------+-----------+
Does anyone know what I'm doiing wrong here?