Skip to content

Commit

Permalink
added invoke (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
Montagon authored Nov 8, 2023
1 parent e61a96f commit 978aaa4
Showing 1 changed file with 40 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,46 @@ import org.flywaydb.core.Flyway
import org.flywaydb.core.api.configuration.FluentConfiguration
import org.flywaydb.core.api.output.MigrateResult

class PsqlVectorStoreConfig (
val host: String,
val port: Int,
val database: String,
val driver: String,
val user: String,
val password: String,
val migrationsTable: String,
val migrationsLocations: List<String> = listOf("vectorStore/migrations")
class PsqlVectorStoreConfig(
val uri: String,
val driver: String,
val user: String,
val password: String,
val migrationsTable: String,
val migrationsLocations: List<String> = listOf("vectorStore/migrations")
) {
suspend fun migrate(): MigrateResult =
withContext(Dispatchers.IO) {
val url = "jdbc:postgresql://${host}:${port}/${database}"
val migration: FluentConfiguration = Flyway.configure()
.dataSource(
url,
user,
password
)
.table(migrationsTable)
.locations(*migrationsLocations.toTypedArray())
.loggers("slf4j")
val isValid = migration.ignoreMigrationPatterns("*:pending").load().validateWithResult()
if (!isValid.validationSuccessful) {
throw IllegalStateException("Migration validation failed: ${isValid.errorDetails}")
}
migration.load().migrate()
}
suspend fun migrate(): MigrateResult =
withContext(Dispatchers.IO) {
val migration: FluentConfiguration = Flyway.configure()
.dataSource(
uri,
user,
password
)
.table(migrationsTable)
.locations(*migrationsLocations.toTypedArray())
.loggers("slf4j")
val isValid = migration.ignoreMigrationPatterns("*:pending").load().validateWithResult()
if (!isValid.validationSuccessful) {
throw IllegalStateException("Migration validation failed: ${isValid.errorDetails}")
}
migration.load().migrate()
}

companion object {
operator fun invoke(
host: String,
port: Int,
database: String,
driver: String,
user: String,
password: String,
migrationsTable: String,
migrationsLocations: List<String> = listOf("vectorStore/migrations")
): PsqlVectorStoreConfig {
val uri = "jdbc:postgresql://${host}:${port}/${database}"
return PsqlVectorStoreConfig(uri, driver, user, password, migrationsTable, migrationsLocations)
}
}

}

0 comments on commit 978aaa4

Please sign in to comment.