From 084643aab5b0fb656f857435e602c1c0aa8b35ab Mon Sep 17 00:00:00 2001 From: aminecmi Date: Fri, 12 Aug 2022 22:55:35 +0200 Subject: [PATCH] Cleaning old table. --- .drone.yml | 5 ++-- src/main/kotlin/MigrationsController.kt | 7 +++--- src/main/kotlin/dao/DB.kt | 18 +++++++------- src/main/kotlin/dao/{ItemsV2.kt => Items.kt} | 16 ++++++------ src/main/kotlin/dao/Lists.kt | 2 +- src/main/kotlin/dao/old/Items.kt | 26 -------------------- src/main/kotlin/server.kt | 4 +-- 7 files changed, 24 insertions(+), 54 deletions(-) rename src/main/kotlin/dao/{ItemsV2.kt => Items.kt} (64%) delete mode 100644 src/main/kotlin/dao/old/Items.kt diff --git a/.drone.yml b/.drone.yml index 528337b..22b6a70 100644 --- a/.drone.yml +++ b/.drone.yml @@ -55,9 +55,8 @@ steps: script: - sudo service ldc stop - cd /home/ubuntu/courses-jar - - mv target/* ./ - - sudo chown ubuntu:ubuntu ./* - - sudo mv -f ./liste-de-courses-1.4-SNAPSHOT-jar-with-dependencies.jar /usr/local/bin/ #todo change file to variable + - sudo chown ubuntu:ubuntu ./target/* + - sudo mv -f ./target/liste-de-courses-1.4-SNAPSHOT-jar-with-dependencies.jar /usr/local/bin/ #todo change file to variable - cd /usr/local/bin/ - sudo rm ldc.jar - sudo ln -s liste-de-courses-1.4-SNAPSHOT-jar-with-dependencies.jar ldc.jar #todo change file to variable diff --git a/src/main/kotlin/MigrationsController.kt b/src/main/kotlin/MigrationsController.kt index ca7384c..d951460 100644 --- a/src/main/kotlin/MigrationsController.kt +++ b/src/main/kotlin/MigrationsController.kt @@ -1,5 +1,4 @@ import dao.* -import dao.old.Items import org.jetbrains.exposed.sql.and import org.jetbrains.exposed.sql.deleteAll import org.jetbrains.exposed.sql.selectAll @@ -34,7 +33,7 @@ class MigrationsController { } println("Migration ${it.key} done.") } else { - println("Migration ${it.key} done.") + println("Migration ${it.key} already done.") } } } @@ -44,7 +43,7 @@ class MigrationsController { try { transaction { Items.selectAll().forEach { - ItemV2.new { + Item.new { list = it[Items.list] content = it[Items.content] position = if (it[Items.checked]) null else it[Items.position] @@ -64,7 +63,7 @@ class MigrationsController { transaction { Lists.selectAll().forEach { var i = 0 - ItemV2.find { ItemsV2.list eq it[Lists.id].value and (ItemsV2.checked eq false) } + Item.find { Items.list eq it[Lists.id].value and (Items.checked eq false) } .sortedBy { it.position } .forEach { it.position = i diff --git a/src/main/kotlin/dao/DB.kt b/src/main/kotlin/dao/DB.kt index d73d36d..5f16f9e 100644 --- a/src/main/kotlin/dao/DB.kt +++ b/src/main/kotlin/dao/DB.kt @@ -24,7 +24,7 @@ class DB { val list = List.findById(resourceId) if (list != null) { - ItemV2.find { ItemsV2.list eq list.id.value}.forEach { i -> i.delete() } + Item.find { Items.list eq list.id.value}.forEach { i -> i.delete() } } list?.delete() ?: ctx.status(404) @@ -69,7 +69,7 @@ class DB { transaction { val listOpt = List.findById(resourceID) if (listOpt != null) { - val items = ItemV2.find { ItemsV2.list eq resourceID } + val items = Item.find { Items.list eq resourceID } .sortedBy { it.position } ctx.json(listOpt.toViewWithItems(items)) @@ -83,10 +83,10 @@ class DB { transaction { val listOpt = List.findById(listId) if (listOpt != null) { - val count = ItemV2.find { ItemsV2.list eq listId and (ItemsV2.checked eq false) }.count() + val count = Item.find { Items.list eq listId and (Items.checked eq false) }.count() val p = (count + 1) - var i = ItemV2.new { + var i = Item.new { list = listId content = c.content position = p.toInt() @@ -104,7 +104,7 @@ class DB { private fun reorderElements(listId: Int, position: Int?, itemId: Int? = null) { transaction { var i = 0 - ItemV2.find { ItemsV2.list eq listId and (ItemsV2.id neq itemId and (ItemsV2.checked eq false)) } + Item.find { Items.list eq listId and (Items.id neq itemId and (Items.checked eq false)) } .sortedBy { it.position } .forEach { if (position != null && i == position) { @@ -122,11 +122,11 @@ class DB { transaction { val listOpt = List.findById(listId) if (listOpt != null) { - val item = ItemV2.find { ItemsV2.list eq listId and (ItemsV2.id eq itemId) }.limit(1).firstOrNull() + val item = Item.find { Items.list eq listId and (Items.id eq itemId) }.limit(1).firstOrNull() if (item != null) { item.delete() var i = 0 - ItemV2.all() + Item.all() .sortedBy { it.position } .forEach { it.position = i @@ -145,7 +145,7 @@ class DB { transaction { val listOpt = List.findById(listId) if (listOpt != null) { - val item = ItemV2.find { ItemsV2.list eq listId and (ItemsV2.id eq itemId) }.limit(1).firstOrNull() + val item = Item.find { Items.list eq listId and (Items.id eq itemId) }.limit(1).firstOrNull() if (item != null) { if (body.position != null) { reorderElements(listId, body.position, itemId) @@ -155,7 +155,7 @@ class DB { var p: Int? = if (body.checked) { null } else { - (ItemV2.find { ItemsV2.list eq listId and (ItemsV2.checked eq false) }.count() + 1).toInt() + (Item.find { Items.list eq listId and (Items.checked eq false) }.count() + 1).toInt() } item.position = p reorderElements(listId, p, itemId) diff --git a/src/main/kotlin/dao/ItemsV2.kt b/src/main/kotlin/dao/Items.kt similarity index 64% rename from src/main/kotlin/dao/ItemsV2.kt rename to src/main/kotlin/dao/Items.kt index a457993..cb7bf0a 100644 --- a/src/main/kotlin/dao/ItemsV2.kt +++ b/src/main/kotlin/dao/Items.kt @@ -5,24 +5,24 @@ import org.jetbrains.exposed.dao.IntEntityClass import org.jetbrains.exposed.dao.id.EntityID import org.jetbrains.exposed.dao.id.IntIdTable -object ItemsV2 : IntIdTable() { +object Items : IntIdTable("ItemsV2") { val list = integer("list") val content = varchar("content", 256) val position = integer("position").nullable() val checked = bool("checked").default(false) } -class ItemV2(id: EntityID) : IntEntity(id) { - companion object : IntEntityClass(ItemsV2) +class Item(id: EntityID) : IntEntity(id) { + companion object : IntEntityClass(Items) - var list by ItemsV2.list - var content by ItemsV2.content - var position by ItemsV2.position - var checked by ItemsV2.checked + var list by Items.list + var content by Items.content + var position by Items.position + var checked by Items.checked } -fun ItemV2.toView(): ItemView { +fun Item.toView(): ItemView { return ItemView(this.id.value, this.content, this.checked, this.position) } diff --git a/src/main/kotlin/dao/Lists.kt b/src/main/kotlin/dao/Lists.kt index da10ffd..d3c3c9e 100644 --- a/src/main/kotlin/dao/Lists.kt +++ b/src/main/kotlin/dao/Lists.kt @@ -20,7 +20,7 @@ fun List.toView(): ListView { return ListView(this.id.value, this.name) } -fun List.toViewWithItems(items: kotlin.collections.List): ListViewWithItems { +fun List.toViewWithItems(items: kotlin.collections.List): ListViewWithItems { return ListViewWithItems(this.id.value, this.name, items.map { it.toView() }) } diff --git a/src/main/kotlin/dao/old/Items.kt b/src/main/kotlin/dao/old/Items.kt deleted file mode 100644 index 8f7327f..0000000 --- a/src/main/kotlin/dao/old/Items.kt +++ /dev/null @@ -1,26 +0,0 @@ -package dao.old - -import org.jetbrains.exposed.dao.IntEntity -import org.jetbrains.exposed.dao.IntEntityClass -import org.jetbrains.exposed.dao.id.EntityID -import org.jetbrains.exposed.dao.id.IntIdTable - -@Deprecated("Position should be nullable") -object Items : IntIdTable() { - val list = integer("list") - val content = varchar("content", 256) - val position = integer("position") - val checked = bool("checked").default(false) -} - -@Deprecated("Position should be nullable") -class Item(id: EntityID) : IntEntity(id) { - companion object : IntEntityClass(Items) - - var list by Items.list - var content by Items.content - var position by Items.position - var checked by Items.checked - - -} \ No newline at end of file diff --git a/src/main/kotlin/server.kt b/src/main/kotlin/server.kt index 76f0b38..0b187d6 100644 --- a/src/main/kotlin/server.kt +++ b/src/main/kotlin/server.kt @@ -1,5 +1,4 @@ import dao.* -import dao.old.Items import io.javalin.Javalin import io.javalin.apibuilder.ApiBuilder.* import io.javalin.core.security.Role @@ -36,8 +35,7 @@ fun main() { transaction { addLogger(StdOutSqlLogger) SchemaUtils.create (Lists) - SchemaUtils.drop (Items) - SchemaUtils.create (ItemsV2) + SchemaUtils.create (Items) SchemaUtils.create (Keys) SchemaUtils.create (Migrations) migrationsController.checkMigrationsToDo()