-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] Programmatic migrations and/or documentation for it #155
Comments
@cromefire |
@cromefire (In addition, I understood what you want.) |
Well it's OSS, I didn't pay for anything, so there's no need to apologise.
I've seen them and it works so far, but because I'm not building an internal application, but a (soon to be) OSS application/"product", I'd like it to be as easy as possible for the user, so if a user just get's the jar or the docker container, he shouldn't have to clone the source code and run the DB upgrade manually. I'd rather like to build something like liquibase provides and automatically migrate at application launch. I can easily do that myself, if I have a way to kick off migrations from within the app. |
@cromefire Maybe, Arguments0: migration package. package text ("com.sample.package") which contains your migration class So, the following new function may meet your needs. fun migrate() {
JarmonicaUpMain.main(
"com.package", "", "directory/path", "Env"
)
} |
I'll have a look at it |
So what I came up with as probably working is something like this: fun migrate(migrations: List<AbstractMigration>, dbConfig: DbConfig, migrationTableName: String = "harmonica_migration") {
val connection = Connection(dbConfig)
val versionService = VersionService(migrationTableName)
try {
connection.transaction {
versionService.setupHarmonicaMigrationTable(connection)
}
for (migration in migrations) {
val migrationVersion =
versionService.pickUpVersionFromClassName(migration.javaClass.name)
if (versionService.isVersionMigrated(connection, migrationVersion)) continue
connection.transaction {
migration.connection = connection
migration.up()
versionService.saveVersion(connection, migrationVersion)
}
}
connection.close()
} catch (e: Exception) {
connection.close()
throw e
}
} You can't implement it externally, because everything on the |
Is your feature request related to a problem? Please describe.
There doesn't seem to be an "easy" way to programmatically migrate (At least not documented).
Describe the solution you'd like
Something like:
(probably a bit more complex, but at least an easy and documented API)
In that case spitting the core/API from the plugin would probably be nice too.
Describe alternatives you've considered
I've tried to look at the plugin and reproduce it but it looks quite complicated.
Additional context
I'm trying to use it in spring but I'd like to make migrations automatically, because (semi-)manually might not be feasible in many contexts.
The text was updated successfully, but these errors were encountered: