From 87c4eaed8c4e39da233cd3bc39b499273cb57b16 Mon Sep 17 00:00:00 2001 From: Hubert Van De Walle Date: Sat, 25 Apr 2020 16:15:42 +0200 Subject: [PATCH] Add migration --- api/resources/db/migration/V8__Notes_uuid.sql | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 api/resources/db/migration/V8__Notes_uuid.sql diff --git a/api/resources/db/migration/V8__Notes_uuid.sql b/api/resources/db/migration/V8__Notes_uuid.sql new file mode 100644 index 0000000..ef36e39 --- /dev/null +++ b/api/resources/db/migration/V8__Notes_uuid.sql @@ -0,0 +1,36 @@ +-- no need to migrate existing data yet +drop table if exists Chapters; +drop table if exists Tags; +drop table if exists Notes; + +CREATE TABLE `Notes` +( + `uuid` binary(16) PRIMARY KEY, + `title` varchar(50) NOT NULL, + `user_id` int NOT NULL, + `updated_at` datetime +); + +ALTER TABLE `Notes` + ADD FOREIGN KEY (`user_id`) REFERENCES `Users` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT; + +CREATE TABLE `Tags` +( + `id` int PRIMARY KEY AUTO_INCREMENT, + `name` varchar(50) NOT NULL, + `note_uuid` binary(16) NOT NULL +); + +ALTER TABLE `Tags` + ADD FOREIGN KEY (`note_uuid`) REFERENCES `Notes` (`uuid`) ON DELETE RESTRICT ON UPDATE RESTRICT; + +CREATE TABLE `Chapters` +( + `id` int PRIMARY KEY AUTO_INCREMENT, + `number` int NOT NULL, + `content` text NOT NULL, + `note_uuid` binary(16) NOT NULL +); + +ALTER TABLE `Chapters` + ADD FOREIGN KEY (`note_uuid`) REFERENCES `Notes` (`uuid`) ON DELETE RESTRICT ON UPDATE RESTRICT;