From 1922f4491cf7972de2bc4c123a30fd3b3262485b Mon Sep 17 00:00:00 2001 From: k1LoW Date: Fri, 1 Nov 2019 00:21:00 +0900 Subject: [PATCH] Remove `MATCH SIMPLE` from my.sql see https://dev.mysql.com/doc/refman/8.0/en/constraint-foreign-key.html --- sample/exclude/posts.md | 2 +- sample/exclude/user_options.md | 2 +- sample/mysql/posts.md | 2 +- sample/mysql/user_options.md | 2 +- sample/svg/posts.md | 2 +- sample/svg/user_options.md | 2 +- testdata/my.sql | 12 ++++++------ 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sample/exclude/posts.md b/sample/exclude/posts.md index 5b309caa..ff52faca 100644 --- a/sample/exclude/posts.md +++ b/sample/exclude/posts.md @@ -19,7 +19,7 @@ CREATE TABLE `posts` ( PRIMARY KEY (`id`), UNIQUE KEY `user_id` (`user_id`,`title`), KEY `posts_user_id_idx` (`id`) USING BTREE, - CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) + CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Posts table' ``` diff --git a/sample/exclude/user_options.md b/sample/exclude/user_options.md index de0eec21..babe4faf 100644 --- a/sample/exclude/user_options.md +++ b/sample/exclude/user_options.md @@ -14,7 +14,7 @@ CREATE TABLE `user_options` ( `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`user_id`), - CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) + CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='User options table' ``` diff --git a/sample/mysql/posts.md b/sample/mysql/posts.md index fa525a07..fdda185f 100644 --- a/sample/mysql/posts.md +++ b/sample/mysql/posts.md @@ -19,7 +19,7 @@ CREATE TABLE `posts` ( PRIMARY KEY (`id`), UNIQUE KEY `user_id` (`user_id`,`title`), KEY `posts_user_id_idx` (`id`) USING BTREE, - CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) + CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Posts table' ``` diff --git a/sample/mysql/user_options.md b/sample/mysql/user_options.md index de0eec21..babe4faf 100644 --- a/sample/mysql/user_options.md +++ b/sample/mysql/user_options.md @@ -14,7 +14,7 @@ CREATE TABLE `user_options` ( `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`user_id`), - CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) + CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='User options table' ``` diff --git a/sample/svg/posts.md b/sample/svg/posts.md index eb23147e..b4823c15 100644 --- a/sample/svg/posts.md +++ b/sample/svg/posts.md @@ -19,7 +19,7 @@ CREATE TABLE `posts` ( PRIMARY KEY (`id`), UNIQUE KEY `user_id` (`user_id`,`title`), KEY `posts_user_id_idx` (`id`) USING BTREE, - CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) + CONSTRAINT `posts_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='Posts table' ``` diff --git a/sample/svg/user_options.md b/sample/svg/user_options.md index 07e11db1..bd9841d5 100644 --- a/sample/svg/user_options.md +++ b/sample/svg/user_options.md @@ -14,7 +14,7 @@ CREATE TABLE `user_options` ( `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `updated` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`user_id`), - CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) + CONSTRAINT `user_options_user_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='User options table' ``` diff --git a/testdata/my.sql b/testdata/my.sql index 3cfef158..d264e597 100644 --- a/testdata/my.sql +++ b/testdata/my.sql @@ -23,7 +23,7 @@ CREATE TABLE user_options ( show_email boolean NOT NULL DEFAULT false, created timestamp NOT NULL, updated timestamp, - CONSTRAINT user_options_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE + CONSTRAINT user_options_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO ACTION ON DELETE CASCADE ) COMMENT = 'User options table'; CREATE TABLE posts ( @@ -35,7 +35,7 @@ CREATE TABLE posts ( created datetime NOT NULL, updated datetime, CONSTRAINT posts_id_pk PRIMARY KEY(id), - CONSTRAINT posts_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE, + CONSTRAINT posts_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) ON UPDATE NO ACTION ON DELETE CASCADE, UNIQUE(user_id, title) ) COMMENT = 'Posts table'; CREATE INDEX posts_user_id_idx ON posts(id) USING BTREE; @@ -48,8 +48,8 @@ CREATE TABLE comments ( created datetime NOT NULL, updated datetime, CONSTRAINT comments_id_pk PRIMARY KEY(id), - CONSTRAINT comments_post_id_fk FOREIGN KEY(post_id) REFERENCES posts(id) MATCH SIMPLE, - CONSTRAINT comments_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id) MATCH SIMPLE, + CONSTRAINT comments_post_id_fk FOREIGN KEY(post_id) REFERENCES posts(id), + CONSTRAINT comments_user_id_fk FOREIGN KEY(user_id) REFERENCES users(id), UNIQUE(post_id, user_id) ) COMMENT = 'Comments\nMulti-line\r\ntable\rcomment'; CREATE INDEX comments_post_id_user_id_idx ON comments(post_id, user_id) USING HASH; @@ -62,8 +62,8 @@ CREATE TABLE comment_stars ( created timestamp NOT NULL, updated timestamp, CONSTRAINT comment_stars_id_pk PRIMARY KEY(id), - CONSTRAINT comment_stars_user_id_post_id_fk FOREIGN KEY(comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id) MATCH SIMPLE, - CONSTRAINT comment_stars_user_id_fk FOREIGN KEY(comment_user_id) REFERENCES users(id) MATCH SIMPLE, + CONSTRAINT comment_stars_user_id_post_id_fk FOREIGN KEY(comment_post_id, comment_user_id) REFERENCES comments(post_id, user_id), + CONSTRAINT comment_stars_user_id_fk FOREIGN KEY(comment_user_id) REFERENCES users(id), UNIQUE(user_id, comment_post_id, comment_user_id) );