diff --git a/api/resources/db/migration/V3__Create_tag_table.sql b/api/resources/db/migration/V3__Create_tag_table.sql new file mode 100644 index 0000000..71f9b44 --- /dev/null +++ b/api/resources/db/migration/V3__Create_tag_table.sql @@ -0,0 +1,9 @@ +CREATE TABLE `Tags` +( + `id` int PRIMARY KEY AUTO_INCREMENT, + `name` varchar(50) 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 diff --git a/api/src/entities/Tag.kt b/api/src/entities/Tag.kt new file mode 100644 index 0000000..c6467d4 --- /dev/null +++ b/api/src/entities/Tag.kt @@ -0,0 +1,11 @@ +package be.vandewalleh.entities + +import me.liuwj.ktorm.entity.Entity + +interface Tag : Entity { + companion object : Entity.Factory() + + val id: Int + var name: String + var note: Note +} \ No newline at end of file diff --git a/api/src/tables/Tags.kt b/api/src/tables/Tags.kt new file mode 100644 index 0000000..3cb4cf2 --- /dev/null +++ b/api/src/tables/Tags.kt @@ -0,0 +1,12 @@ +package be.vandewalleh.tables + +import be.vandewalleh.entities.Tag +import me.liuwj.ktorm.schema.Table +import me.liuwj.ktorm.schema.int +import me.liuwj.ktorm.schema.varchar + +object Tags : Table("Tags") { + val id by int("id").primaryKey().bindTo { it.id } + val name by varchar("name").bindTo { it.name } + val noteId by int("note_id").references(Notes) { it.note } +} \ No newline at end of file