-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Reorganize Postgres configuration * Create Hikari data source as resource * Remove duplicated code * Remove PostgresVectorStoreConfig class * Remove unnecessary println
- Loading branch information
1 parent
dbe5ac1
commit 812b744
Showing
13 changed files
with
183 additions
and
296 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...esql/src/main/kotlin/com/xebia/functional/xef/store/config/PostgreSQLVectorStoreConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.xebia.functional.xef.store.config | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class PostgreSQLVectorStoreConfig( | ||
val url: String, | ||
val driver: String, | ||
val user: String, | ||
val password: String, | ||
val collectionName: String, | ||
val vectorSize: Int, | ||
val migrationsTable: String = "migrations", | ||
val migrationsLocations: List<String> = listOf("vectorStore/migrations") | ||
) |
49 changes: 49 additions & 0 deletions
49
...ostgresql/src/main/kotlin/com/xebia/functional/xef/store/migrations/DatabaseMigrations.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.xebia.functional.xef.store.migrations | ||
|
||
import com.xebia.functional.xef.store.config.PostgreSQLVectorStoreConfig | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.flywaydb.core.Flyway | ||
import org.flywaydb.core.api.configuration.FluentConfiguration | ||
import org.flywaydb.core.api.output.MigrateResult | ||
import javax.sql.DataSource | ||
|
||
suspend fun runDatabaseMigrations( | ||
dataSource: DataSource, | ||
migrationsTable: String, | ||
migrationsLocations: List<String> | ||
): MigrateResult = | ||
withContext(Dispatchers.IO) { | ||
val migration: FluentConfiguration = Flyway.configure() | ||
.dataSource(dataSource) | ||
.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 runDatabaseMigrations( | ||
config: PostgreSQLVectorStoreConfig | ||
): MigrateResult = | ||
withContext(Dispatchers.IO) { | ||
with(config) { | ||
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() | ||
} | ||
} |
51 changes: 0 additions & 51 deletions
51
...gresql/src/main/kotlin/com/xebia/functional/xef/store/migrations/PsqlVectorStoreConfig.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
server/src/main/kotlin/com/xebia/functional/xef/server/db/VectorStoreConfig.kt
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
server/src/main/kotlin/com/xebia/functional/xef/server/db/local/LocalVectorStoreConfig.kt
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
server/src/main/kotlin/com/xebia/functional/xef/server/db/psql/Migrate.kt
This file was deleted.
Oops, something went wrong.
73 changes: 0 additions & 73 deletions
73
server/src/main/kotlin/com/xebia/functional/xef/server/db/psql/PSQLVectorStoreConfig.kt
This file was deleted.
Oops, something went wrong.
17 changes: 5 additions & 12 deletions
17
server/src/main/kotlin/com/xebia/functional/xef/server/db/psql/XefDatabaseConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,26 @@ | ||
package com.xebia.functional.xef.server.db.psql | ||
|
||
import com.typesafe.config.Config | ||
import com.typesafe.config.ConfigFactory | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.hocon.Hocon | ||
|
||
@Serializable | ||
class XefDatabaseConfig( | ||
val host: String, | ||
val port: Int, | ||
val database: String, | ||
data class XefDatabaseConfig( | ||
val url: String, | ||
val user: String, | ||
val password: String, | ||
val migrationsTable: String, | ||
val migrationsLocations: List<String> | ||
) { | ||
|
||
fun getUrl(): String = "jdbc:postgresql://$host:$port/$database" | ||
|
||
companion object { | ||
@OptIn(ExperimentalSerializationApi::class) | ||
suspend fun load(configNamespace: String, config: Config? = null): XefDatabaseConfig = | ||
suspend fun load(configNamespace: String, config: Config): XefDatabaseConfig = | ||
withContext(Dispatchers.IO) { | ||
val rawConfig = config ?: ConfigFactory.load().resolve() | ||
val jdbcConfig = rawConfig.getConfig(configNamespace) | ||
Hocon.decodeFromConfig(serializer(), jdbcConfig) | ||
val databaseConfig = config.getConfig(configNamespace) | ||
Hocon.decodeFromConfig(serializer(), databaseConfig) | ||
} | ||
} | ||
} |
Oops, something went wrong.