Compare commits

...

2 Commits

Author SHA1 Message Date
e9ba266d53 bump version to 1.1.1
All checks were successful
/ publish (push) Successful in 2m5s
2025-12-12 21:40:50 +01:00
8fcc08ecb5 refactor 2025-12-12 21:40:26 +01:00
3 changed files with 25 additions and 31 deletions

View File

@@ -1,5 +1,5 @@
group = "com.infendro"
version = "1.1.0"
version = "1.1.1"
repositories {
mavenCentral()

View File

@@ -11,17 +11,35 @@ import org.slf4j.LoggerFactory
internal val logger: Logger = LoggerFactory.getLogger("Database")
class MigrationConfig {
internal val migrations: MutableList<Migration> = mutableListOf()
fun migration(
name: String,
migrate: Transaction.() -> Unit,
) {
if (migrations.any { it.name == name })
throw DuplicateMigrationException(name)
migrations += Migration(name, migrate)
}
data class Migration(
val name: String,
val migrate: Transaction.() -> Unit,
)
}
fun migrate(
config: Config
config: MigrationConfig,
) {
transaction {
SchemaUtils.create(MigrationTable)
}
for ((name, migrate) in config.migrations) {
if (MigrationRepository.exists(name)) {
if (MigrationRepository.exists(name))
continue
}
transaction {
try {
@@ -37,32 +55,10 @@ fun migrate(
}
}
@Suppress("UNUSED")
fun migrate(
configure: Config.() -> Unit
configure: MigrationConfig.() -> Unit,
) {
val config = Config()
val config = MigrationConfig()
config.configure()
migrate(config)
}
class Config {
internal val migrations: MutableList<Migration> = mutableListOf()
@Suppress("UNUSED")
fun migration(
name: String,
migrate: Transaction.() -> Unit,
) {
if (migrations.any { it.name == name }) {
throw DuplicateMigrationException(name)
}
migrations += Migration(name, migrate)
}
data class Migration(
val name: String,
val migrate: Transaction.() -> Unit
)
}

View File

@@ -15,8 +15,6 @@ object MigrationRepository {
name: String,
): Unit = transaction {
MigrationEntity
.new {
this.name = name
}
.new { this.name = name }
}
}