question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature] Programmatic migrations and/or documentation for it

See original GitHub issue

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:

val config = DbConfig()
config.migrate()

(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.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
cromefirecommented, Dec 5, 2020

I’ll have a look at it

0reactions
cromefirecommented, Dec 8, 2020

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 VersionService and AbstractMigration.connection is internal, but it should work if added inside the library.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating Room databases | Android Developers
Automated migrations. Automatic migration specifications. Manual migrations; Test migrations. Export schemas; Test a single migration; Test all migrations.
Read more >
Database migrations. CLI and Golang library. - GitHub
Migrate reads migrations from sources and applies them in correct order to a database. Drivers are "dumb", migrate glues everything together and makes...
Read more >
Scripting migrations with the Contentful CLI
This tutorial details how to use the Contentful CLI to script changes to a content model and entries in a structured and reproducible...
Read more >
node-pg-migrate
Postgresql database migration management tool for node.js. ... Looking for v3 docs? see v3 branch. Installation. $ npm install node-pg-migrate pg.
Read more >
code-first DB Migrations - ServiceStack Docs
We'll use this feature in our 2nd migration for its Data Model changes where we want to: Add a new Code VARCHAR column...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found