diff options
Diffstat (limited to 'src/main/kotlin/io/dico/parcels2/storage/migration')
-rw-r--r-- | src/main/kotlin/io/dico/parcels2/storage/migration/plotme/PlotmeMigration.kt | 28 | ||||
-rw-r--r-- | src/main/kotlin/io/dico/parcels2/storage/migration/plotme/PlotmeTables.kt | 41 |
2 files changed, 40 insertions, 29 deletions
diff --git a/src/main/kotlin/io/dico/parcels2/storage/migration/plotme/PlotmeMigration.kt b/src/main/kotlin/io/dico/parcels2/storage/migration/plotme/PlotmeMigration.kt index a79d315..831fe42 100644 --- a/src/main/kotlin/io/dico/parcels2/storage/migration/plotme/PlotmeMigration.kt +++ b/src/main/kotlin/io/dico/parcels2/storage/migration/plotme/PlotmeMigration.kt @@ -7,8 +7,10 @@ import io.dico.parcels2.* import io.dico.parcels2.options.PlotmeMigrationOptions import io.dico.parcels2.storage.Storage import io.dico.parcels2.storage.exposed.abs -import io.dico.parcels2.storage.exposed.greater +import io.dico.parcels2.storage.exposed.greaterOf import io.dico.parcels2.storage.migration.Migration +import io.dico.parcels2.storage.migration.plotme.PlotmeTables.PlotmePlotPlayerMap +import io.dico.parcels2.storage.migration.plotme.PlotmeTables.PlotmeTable import io.dico.parcels2.storage.toUUID import kotlinx.coroutines.Job import kotlinx.coroutines.launch @@ -24,6 +26,7 @@ class PlotmeMigration(val options: PlotmeMigrationOptions) : Migration { private var database: Database? = null private var isShutdown: Boolean = false private val mlogger = LoggerFactory.getLogger("PlotMe Migrator") + private val tables = PlotmeTables(options.tableNamesUppercase) val dispatcher = newFixedThreadPoolContext(1, "PlotMe Migration Thread") private fun <T> transaction(statement: Transaction.() -> T) = org.jetbrains.exposed.sql.transactions.transaction(database!!, statement) @@ -51,9 +54,9 @@ class PlotmeMigration(val options: PlotmeMigrationOptions) : Migration { isShutdown = true } - suspend fun doWork(target: Storage) { + suspend fun doWork(target: Storage) = with (tables) { val exit = transaction { - (!PlotmePlotsT.exists()).also { + (!PlotmePlots.exists()).also { if (it) mlogger.warn("Plotme tables don't appear to exist. Exiting.") } } @@ -75,29 +78,32 @@ class PlotmeMigration(val options: PlotmeMigrationOptions) : Migration { } mlogger.info("Transmitting data from plotmeplots table") + var count = 0 transaction { - PlotmePlotsT.selectAll() - .orderBy(PlotmePlotsT.world_name) - .orderBy(with(SqlExpressionBuilder) { greater(PlotmePlotsT.px.abs(), PlotmePlotsT.pz.abs()) }) + + PlotmePlots.selectAll() + .orderBy(PlotmePlots.world_name) + .orderBy(greaterOf(PlotmePlots.px.abs(), PlotmePlots.pz.abs())) .forEach { row -> - val parcel = getParcelId(PlotmePlotsT, row) ?: return@forEach - val owner = PlayerProfile.safe(row[PlotmePlotsT.owner_uuid]?.toUUID(), row[PlotmePlotsT.owner_name]) + val parcel = getParcelId(PlotmePlots, row) ?: return@forEach + val owner = PlayerProfile.safe(row[PlotmePlots.owner_uuid]?.toUUID(), row[PlotmePlots.owner_name]) target.setParcelOwner(parcel, owner) target.setParcelOwnerSignOutdated(parcel, true) + ++count } } mlogger.info("Transmitting data from plotmeallowed table") transaction { - PlotmeAllowedT.transmitPlotmeAddedTable(Privilege.CAN_BUILD) + PlotmeAllowed.transmitPlotmeAddedTable(Privilege.CAN_BUILD) } mlogger.info("Transmitting data from plotmedenied table") transaction { - PlotmeDeniedT.transmitPlotmeAddedTable(Privilege.BANNED) + PlotmeDenied.transmitPlotmeAddedTable(Privilege.BANNED) } - mlogger.warn("Data has been **transmitted**.") + mlogger.warn("Data has been **transmitted**. $count plots were migrated to the parcels database.") mlogger.warn("Loading parcel data might take a while as enqueued transactions from this migration are completed.") } diff --git a/src/main/kotlin/io/dico/parcels2/storage/migration/plotme/PlotmeTables.kt b/src/main/kotlin/io/dico/parcels2/storage/migration/plotme/PlotmeTables.kt index 8564ad3..dc788c8 100644 --- a/src/main/kotlin/io/dico/parcels2/storage/migration/plotme/PlotmeTables.kt +++ b/src/main/kotlin/io/dico/parcels2/storage/migration/plotme/PlotmeTables.kt @@ -2,25 +2,30 @@ package io.dico.parcels2.storage.migration.plotme import org.jetbrains.exposed.sql.Table -const val uppercase: Boolean = false -@Suppress("ConstantConditionIf") -fun String.toCorrectCase() = if (uppercase) this else toLowerCase() - -sealed class PlotmeTable(name: String) : Table(name) { - val px = integer("idX").primaryKey() - val pz = integer("idZ").primaryKey() - val world_name = varchar("world", 32).primaryKey() -} +class PlotmeTables(val uppercase: Boolean) { + fun String.toCorrectCase() = if (uppercase) this else toLowerCase() -object PlotmePlotsT : PlotmeTable("plotmePlots".toCorrectCase()) { - val owner_name = varchar("owner", 32) - val owner_uuid = blob("ownerid").nullable() -} + val PlotmePlots = PlotmePlotsT() + val PlotmeAllowed = PlotmeAllowedT() + val PlotmeDenied = PlotmeDeniedT() + + inner abstract class PlotmeTable(name: String) : Table(name) { + val px = integer("idX").primaryKey() + val pz = integer("idZ").primaryKey() + val world_name = varchar("world", 32).primaryKey() + } + + inner abstract class PlotmePlotPlayerMap(name: String) : PlotmeTable(name) { + val player_name = varchar("player", 32) + val player_uuid = blob("playerid").nullable() + } + + inner class PlotmePlotsT : PlotmeTable("plotmePlots".toCorrectCase()) { + val owner_name = varchar("owner", 32) + val owner_uuid = blob("ownerid").nullable() + } -sealed class PlotmePlotPlayerMap(name: String) : PlotmeTable(name) { - val player_name = varchar("player", 32) - val player_uuid = blob("playerid").nullable() + inner class PlotmeAllowedT : PlotmePlotPlayerMap("plotmeAllowed".toCorrectCase()) + inner class PlotmeDeniedT : PlotmePlotPlayerMap("plotmeDenied".toCorrectCase()) } -object PlotmeAllowedT : PlotmePlotPlayerMap("plotmeAllowed".toCorrectCase()) -object PlotmeDeniedT : PlotmePlotPlayerMap("plotmeDenied".toCorrectCase()) |