Skip to content
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

Added URI constructor to PSQL Vector Store Config #525

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}

}