diff --git a/integrations/postgresql/src/main/kotlin/com/xebia/functional/xef/store/migrations/PsqlVectorStoreConfig.kt b/integrations/postgresql/src/main/kotlin/com/xebia/functional/xef/store/migrations/PsqlVectorStoreConfig.kt index c8a8d10ce..984fed951 100644 --- a/integrations/postgresql/src/main/kotlin/com/xebia/functional/xef/store/migrations/PsqlVectorStoreConfig.kt +++ b/integrations/postgresql/src/main/kotlin/com/xebia/functional/xef/store/migrations/PsqlVectorStoreConfig.kt @@ -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 = listOf("vectorStore/migrations") +class PsqlVectorStoreConfig( + val uri: String, + val driver: String, + val user: String, + val password: String, + val migrationsTable: String, + val migrationsLocations: List = 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 = listOf("vectorStore/migrations") + ): PsqlVectorStoreConfig { + val uri = "jdbc:postgresql://${host}:${port}/${database}" + return PsqlVectorStoreConfig(uri, driver, user, password, migrationsTable, migrationsLocations) + } + } }