-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#86 Added liquibase migrations at startup
- Loading branch information
Showing
10 changed files
with
91 additions
and
11 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
botalka/src/main/kotlin/ru/vityaman/lms/botalka/app/spring/storage/SpringMigration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package ru.vityaman.lms.botalka.app.spring.storage | ||
|
||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.jdbc.datasource.SingleConnectionDataSource | ||
import org.springframework.stereotype.Component | ||
import ru.vityaman.lms.botalka.storage.migration.LiquibaseMigration | ||
import kotlin.io.path.Path | ||
|
||
@Component | ||
class SpringMigration( | ||
@Value("\${spring.liquibase.change-log}") | ||
changelog: String, | ||
|
||
@Value("\${spring.datasource.url}") | ||
url: String, | ||
|
||
@Value("\${spring.datasource.username}") | ||
username: String, | ||
|
||
@Value("\${spring.datasource.password}") | ||
password: String, | ||
) { | ||
init { | ||
val suppressClose = false | ||
SingleConnectionDataSource(url, username, password, suppressClose) | ||
.use { LiquibaseMigration(Path(changelog), it).start() } | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
botalka/src/main/kotlin/ru/vityaman/lms/botalka/storage/migration/LiquibaseMigration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package ru.vityaman.lms.botalka.storage.migration | ||
|
||
import liquibase.Liquibase | ||
import liquibase.database.DatabaseFactory | ||
import liquibase.database.jvm.JdbcConnection | ||
import liquibase.resource.ClassLoaderResourceAccessor | ||
import java.nio.file.Path | ||
import javax.sql.DataSource | ||
import kotlin.io.path.pathString | ||
|
||
class LiquibaseMigration( | ||
private val changelog: Path, | ||
private val source: DataSource, | ||
) { | ||
@Suppress("Deprecation") | ||
fun start() { | ||
val resources = ClassLoaderResourceAccessor(javaClass.classLoader) | ||
println("Migration::start") | ||
source.connection.use { connection -> | ||
val database = DatabaseFactory.getInstance() | ||
.findCorrectDatabaseImplementation(JdbcConnection(connection)) | ||
Liquibase(changelog.pathString, resources, database).use { | ||
it.update("development") | ||
} | ||
} | ||
println("Migration::end") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
botalka/src/test/kotlin/ru/vityaman/lms/botalka/app/spring/BotalkaApplicationTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters