Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liquibase cannot find parser

I am getting a Liquibase exception when running update.

Caused by: liquibase.exception.UnknownChangelogFormatException: 
Cannot find parser that supports <?xml version="1.0" encoding="UTF-8" standalone="no"?>

I thought Liquibase by default supports xml parsing so I am not sure of the case here. Am I missing a configuration when I initialize the class?

  private lazy val liquibase: Liquibase = {
    val fsFO: ResourceAccessor = new FileSystemResourceAccessor
    val clFO: ResourceAccessor = new ClassLoaderResourceAccessor
    val contextClassLoader = Thread.currentThread().getContextClassLoader
    val threadClFO: ResourceAccessor = new ClassLoaderResourceAccessor(contextClassLoader)
    val database = DatabaseFactory.getInstance.findCorrectDatabaseImplementation(new JdbcConnection(connection))
    new Liquibase(changeLog, new CompositeResourceAccessor(clFO, fsFO, threadClFO), database)
  }

  def update(): Unit = Try(liquibase.update(context)) match {
    case Success(_) => log.info("LIQUIBASE FINISHED: Update change log")
    case Failure(ex) => throw new Exception("LIQUIBASE FAILED: Update change log", ex)
  }

The variable changelog is the String read using `java.o.File

  val fileReader = new FileReader(file)
  val characters = new Array[Char](file.length().toInt)
  fileReader.read(characters)
  new String(characters)

Master.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="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 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
    <changeSet author="author" id="1444318866725-1">
        <createTable tableName="author">
            <column name="id" type="INT">
                <constraints nullable="false"/>
            </column>
            <column defaultValue="NULL::character varying" name="first_name" type="VARCHAR(255)"/>
            <column defaultValue="NULL::character varying" name="last_name" type="VARCHAR(255)"/>
        </createTable>
    </changeSet>
    <changeSet author="author" id="1444318866725-2">
        <addPrimaryKey columnNames="id" constraintName="author_pkey" tableName="author"/>
    </changeSet>
    <changeSet author="author" id="add-column-gender">
        <dropColumn tableName="author">
            <column name="first_name"/>
        </dropColumn>
        <addColumn tableName="author">
            <column name="gender" type="varchar(255)"/>
        </addColumn>
    </changeSet>
</databaseChangeLog>

1 Answers

It appears that the issue is that the changeLog variable is something other than a String that contains the path to the changelog file.

like image 70
SteveDonie Avatar answered Oct 18 '25 03:10

SteveDonie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!