hhandoko / cassandra-migration

Apache Cassandra / DataStax Enterprise database migration (schema evolution) library
Apache License 2.0
51 stars 21 forks source link

Add support for additional resolvers and locate local classes in Kotlin #82

Open mkobit opened 5 years ago

mkobit commented 5 years ago

Outcome Desired

Ability to extend and implement how migrations are discovered.


Definition of Done

Out of Scope


How to Demo

When trying to evaluate this tool, I wrote a local Kotlin class to experiment with Java-based migrations:

    @DisplayName("com.hhandoko:cassandra-migration:0.15 : https://github.com/hhandoko/cassandra-migration")
    @Test
    fun `trying out hhandoko_cassandra-migration`() {
        // local classes don't work with cassandra-migration classpath scanning mechanism
        class V2__AddDataPointMigration : JavaMigration {
            override fun migrate(session: Session) {
                session.execute("""
                    INSERT into Data (account, id, data) VALUES
                    (
                        628d17b8-7f67-4bba-8e89-dadbdb6769e0,
                        0,
                        textAsBlob('70696e656170706c652070697a7a6120697320612073696e')
                    )
                """.trimIndent())
            }
        }

Unfortunately, this class does not get discovered by scanning techniques.

mkobit commented 5 years ago

There is a big commented out section in CassandraMigrationConfiguration

//    /**
//     * Retrieves the the custom MigrationResolvers to be used in addition to the built-in ones for resolving migrations to apply.
//     *
//     * @return The custom MigrationResolvers to be used in addition to the built-in ones for resolving migrations to apply.
//     *         An empty array if none.
//     *         (default: none)
//     */
//    val resolvers: Array<MigrationResolver>

That makes me think this feature was eventually planned, but just not implemented yet.