Add Chapters table

This commit is contained in:
Hubert Van De Walle 2020-04-19 17:37:27 +02:00
parent e0ffbad105
commit 0dd4886846
3 changed files with 36 additions and 5 deletions

View File

@ -1,9 +1,13 @@
CREATE TABLE `Tags`
CREATE TABLE `Chapters`
(
`id` int PRIMARY KEY AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`note_id` int NOT NULL
`number` int NOT NULL,
`content` text NOT NULL,
`note_id` int NOT NULL
);
ALTER TABLE `Tags`
ADD FOREIGN KEY (`note_id`) REFERENCES `Notes` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `Chapters`
ADD FOREIGN KEY (`note_id`) REFERENCES `Notes` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `Notes`
DROP COLUMN `content`;

View File

@ -0,0 +1,12 @@
package be.vandewalleh.entities
import me.liuwj.ktorm.entity.Entity
interface Chapter : Entity<Chapter> {
companion object : Entity.Factory<Chapter>()
val id: Int
var number: Int
var content: String
var note: Note
}

View File

@ -0,0 +1,15 @@
package be.vandewalleh.tables
import be.vandewalleh.entities.Chapter
import be.vandewalleh.entities.Tag
import me.liuwj.ktorm.schema.Table
import me.liuwj.ktorm.schema.int
import me.liuwj.ktorm.schema.text
import me.liuwj.ktorm.schema.varchar
object Chapters : Table<Chapter>("Chapters") {
val id by int("id").primaryKey().bindTo { it.id }
val number by int("number").bindTo { it.number }
val content by text("content").bindTo { it.content }
val noteId by int("note_id").references(Notes) { it.note }
}