Liquibase kotlin(DSL, Wrapper client, ORM integration) Help

Exposed-migration

Install

Add bellow code your build.gradle.kts

dependencies { // liquibase-kotlin implementation("io.github.momosetkn:liquibase-kotlin-custom-exposed-migration-change:4.32.0-0.9.2") }

Use customExposedMigrationChange

execute is required, rollback is optional. the callback argument type is org.jetbrains.exposed.sql.Database.

import momosetkn.liquibase.kotlin.parser.KotlinCompiledDatabaseChangeLog import momosetkn.liquibase.kotlin.change.custom.exposed.customExposedMigrationChange import org.jetbrains.exposed.sql.SchemaUtils import org.jetbrains.exposed.sql.Table import org.jetbrains.exposed.sql.transactions.transaction class CompiledDatabaseChangelog1 : KotlinCompiledDatabaseChangeLog({ changeSet(author = "your_name", id = "20241007-2000-1") { // https://jetbrains.github.io/Exposed/table-definition.html#dsl-create-table val createdByExposed = object : Table("created_by_exposed") { val id = integer("id").autoIncrement() val name = varchar("name", 256) override val primaryKey = PrimaryKey(id) } customExposedMigrationChange( execute = { db -> transaction(db) { SchemaUtils.create(createdByExposed) } }, rollback = { db -> transaction(db) { SchemaUtils.drop(createdByExposed) } }, ) } })
databaseChangeLog { changeSet(author = "your_name", id = "20241007-2000-1") { // https://jetbrains.github.io/Exposed/table-definition.html#dsl-create-table val createdByExposed = object : Table("created_by_exposed") { val id = integer("id").autoIncrement() val name = varchar("name", 256) override val primaryKey = PrimaryKey(id) } customExposedMigrationChange( execute = { db -> transaction(db) { SchemaUtils.create(createdByExposed) } }, rollback = { db -> transaction(db) { SchemaUtils.drop(createdByExposed) } }, ) } }

Configure org.jetbrains.exposed.sql.Database

override the momosetkn.liquibase.kotlin.change.custom.exposed.LiquibaseExposedMigrationConfig.provideDatabase

example code

fun provideDatabase( javaxSqlDataSource: javax.sql.DataSource, liquibaseDatabaseShortName: String ): Database { val dialect = getDialect(liquibaseDatabaseShortName) val db = Database.connect( datasource = javaxSqlDataSource, databaseConfig = dialect?.let { DatabaseConfig { explicitDialect = dialect } }, ) return db } internal fun getDialect(liquibaseDatabaseShortName: String): VendorDialect? { return when (liquibaseDatabaseShortName) { "h2" -> H2Dialect() "mariadb" -> MariaDBDialect() "mysql" -> MysqlDialect() "oracle" -> OracleDialect() "postgresql" -> PostgreSQLDialect() "sqlserver" -> SQLServerDialect() "sqlite" -> SQLiteDialect() else -> null } } momosetkn.liquibase.kotlin.change.custom.exposed.LiquibaseExposedMigrationConfig.provideDatabase = ::provideDatabase

k

Last modified: 15 October 2024