Search code examples
spring-bootkotlinff4j

ff4j kotlin cannot create table throws BadSqlGrammarException


I am trying to integrate FF4J into my spring boot application project however it looks like there is some issue with driver or FF4J and the db schema is not created.

My configuration file:

@Configuration
@ConditionalOnClass(FF4j::class)
class FF4JConfiguration {

    @field:Value("\${spring.ff4j.datasource.url}")
    private lateinit var driverUrl: String

    @field:Value("\${spring.datasource.driver-class-name}")
    private lateinit var driverClass: String

    @field:Value("\${spring.datasource.username}")
    private lateinit var user: String

    @field:Value("\${spring.datasource.password}")
    private lateinit var password: String

    @Bean
    fun getFF4j(): FF4j {
        val source = MysqlDataSource()
        source.setURL(driverUrl)
        source.password = password
        source.user = user
        val fF4j = FF4j()
        fF4j.featureStore = FeatureStoreSpringJdbc().apply { setDataSource(source) }
        fF4j.propertiesStore = PropertyStoreSpringJdbc().apply { setDataSource(source) }
        fF4j.eventRepository = JdbcEventRepository(source)
        fF4j.audit(true)
        fF4j.autoCreate(true)
        return fF4j
    }
}

When I debug this is how the datasource looks like: enter image description here

but I do get this BadSqlGrammarException and I have no idea why it cannot create SQL tables for me in the database. The server is running and database is fine because I have other tables as well.

My build.gradle.kts

    implementation("org.ff4j:ff4j-core:1.8.12")
    implementation("org.ff4j:ff4j-web:1.8.12")
    implementation("org.ff4j:ff4j-store-springjdbc:1.8.12")
    implementation("mysql:mysql-connector-java:8.0.30")

Any ideas why this happens?


Solution

  • This is fine. FF4J does not create schema automatically for you. You have to create it yourself by doing so:

    fF4j.featureStore = JdbcFeatureStore().apply {
         dataSource = source
         createSchema()
    }
    fF4j.propertiesStore = JdbcPropertyStore().apply {
         dataSource = source
         createSchema()
    }
    fF4j.eventRepository = JdbcEventRepository(source).apply { createSchema() }
    

    and you will be good to go. Most likely the exception you got is because the ff4j_features table does not exist. Now it will create the schema and all tables and features should working fine