Cleaning old table.
This commit is contained in:
parent
ac3b137e53
commit
084643aab5
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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<Int>) : IntEntity(id) {
|
||||
companion object : IntEntityClass<ItemV2>(ItemsV2)
|
||||
class Item(id: EntityID<Int>) : IntEntity(id) {
|
||||
companion object : IntEntityClass<Item>(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)
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ fun List.toView(): ListView {
|
||||
return ListView(this.id.value, this.name)
|
||||
}
|
||||
|
||||
fun List.toViewWithItems(items: kotlin.collections.List<ItemV2>): ListViewWithItems {
|
||||
fun List.toViewWithItems(items: kotlin.collections.List<Item>): ListViewWithItems {
|
||||
return ListViewWithItems(this.id.value, this.name, items.map { it.toView() })
|
||||
}
|
||||
|
||||
|
@ -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<Int>) : IntEntity(id) {
|
||||
companion object : IntEntityClass<Item>(Items)
|
||||
|
||||
var list by Items.list
|
||||
var content by Items.content
|
||||
var position by Items.position
|
||||
var checked by Items.checked
|
||||
|
||||
|
||||
}
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user