SimpleNotes/api/resources/db/migration/V8__Notes_uuid.sql
2020-04-25 18:44:38 +02:00

38 lines
1.0 KiB
SQL

-- 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 CASCADE ON UPDATE RESTRICT;
CREATE TABLE `Chapters`
(
`id` int PRIMARY KEY AUTO_INCREMENT,
`number` int NOT NULL,
`title` varchar(50) 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 CASCADE ON UPDATE RESTRICT;