From 0dd4886846a5b926611c2ae25d60696fe3efd07f Mon Sep 17 00:00:00 2001 From: Hubert Van De Walle Date: Sun, 19 Apr 2020 17:37:27 +0200 Subject: [PATCH] Add Chapters table --- .../db/migration/V4__Create_chapters_table.sql | 14 +++++++++----- api/src/entities/Chapter.kt | 12 ++++++++++++ api/src/tables/Chapters.kt | 15 +++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 api/src/entities/Chapter.kt create mode 100644 api/src/tables/Chapters.kt diff --git a/api/resources/db/migration/V4__Create_chapters_table.sql b/api/resources/db/migration/V4__Create_chapters_table.sql index 71f9b44..2867403 100644 --- a/api/resources/db/migration/V4__Create_chapters_table.sql +++ b/api/resources/db/migration/V4__Create_chapters_table.sql @@ -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; \ No newline at end of file +ALTER TABLE `Chapters` + ADD FOREIGN KEY (`note_id`) REFERENCES `Notes` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT; + +ALTER TABLE `Notes` + DROP COLUMN `content`; \ No newline at end of file diff --git a/api/src/entities/Chapter.kt b/api/src/entities/Chapter.kt new file mode 100644 index 0000000..6ca869d --- /dev/null +++ b/api/src/entities/Chapter.kt @@ -0,0 +1,12 @@ +package be.vandewalleh.entities + +import me.liuwj.ktorm.entity.Entity + +interface Chapter : Entity { + companion object : Entity.Factory() + + val id: Int + var number: Int + var content: String + var note: Note +} \ No newline at end of file diff --git a/api/src/tables/Chapters.kt b/api/src/tables/Chapters.kt new file mode 100644 index 0000000..d02dae0 --- /dev/null +++ b/api/src/tables/Chapters.kt @@ -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("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 } +} \ No newline at end of file