How to run liquibase scripts before bootstrap context?

Viewed 170

Good day, everyone! The problem is: I have Spring Cloud Config Server with that bootstrap.yaml

spring:
  application:
    name: config-server
  cloud:
    config:
      server:
        bootstrap: true
        jdbc:
          sql: SELECT `KEY`, `VALUE` FROM `PROPERTIES` WHERE `APPLICATION`=? AND `PROFILE`=? AND `LABEL`=?;
          order: 0
          fail-on-error: true
        default-profile: LOCAL_HOST
        enabled: false
      discovery:
        enabled: false
      enabled: false
      profile: LOCAL_HOST
  datasource:
    url: jdbc:mysql://localhost:3306/springconfig
    username: ****
    password: ****
    driver-class-name: com.mysql.cj.jdbc.Driver
  liquibase:
    enabled: true
    change-log: classpath:/db/changelog/db.changelog-master.xml
  profiles:
    active: jdbc

The most important part is jdbc sql query which works when microservice asks for property. It's all about spring cloud config with jdbc storage. The next part is liquibase script:

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">

    <changeSet author="*****" id="config_server_schema_1">
        <comment>Create SCHEMA config_server</comment>
        <sql dbms="mysql" endDelimiter=";">
            CREATE SCHEMA IF NOT EXISTS config_server
        </sql>
    </changeSet>

    <changeSet author="****" id="properties_table_2">
        <comment>Create PROPERTIES table</comment>
        <createTable catalogName="config_server" schemaName="config_server" tableName="PROPERTIES">
            <column autoIncrement="true" name="id" type="BIGINT">
                <constraints primaryKey="true"/>
            </column>
            <column name="APPLICATION" type="VARCHAR(255)">
                <constraints unique="true" nullable="false"/>
            </column>
            <column name="PROFILE" type="VARCHAR(255)">
                <constraints unique="true" nullable="false"/>
            </column>
            <column name="LABEL" type="VARCHAR(255)">
                <constraints unique="true" nullable="false"/>
            </column>
            <column name="KEY" type="VARCHAR(255)">
                <constraints unique="true" nullable="false"/>
            </column>
            <column name="VALUE" type="VARCHAR(255)"/>
        </createTable>
    </changeSet>

</databaseChangeLog>

So, when i start spring boot application first loads bootstrap context (thanks spring starter bootstrap) from file bootstrap.yaml (see above). And spring checks: would be query executable? The answer is 'No':

Caused by: java.sql.SQLSyntaxErrorException: Table 'config_server.PROPERTIES' doesn't exist
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
    at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
    at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1009)
    at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
    at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
    at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:722)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:651)
    ... 15 common frames omitted

Liquibase script didn't run. Can you please explain how can i run script before or in same time with bootstrap context? Much thanks!

0 Answers
Related