From 6d6b37c0ad62d448503efadf613790d133a88465 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Wed, 28 Mar 2018 10:01:50 +0200 Subject: bin/bootstrap-mysql: "ON DELETE SET NULL" for "NULL" columns --- bin/bootstrap-mysql | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/bootstrap-mysql b/bin/bootstrap-mysql index 43a79af..5f51c07 100755 --- a/bin/bootstrap-mysql +++ b/bin/bootstrap-mysql @@ -234,10 +234,17 @@ if [ ! "$1" = 'slim' ]; then tr ' ' '\n' | \ sed -n 's/^://;T;p' | \ while read -r link; do - printf 'ALTER TABLE `%s` ADD FOREIGN KEY (`%s`) REFERENCES `%s` (`id`) ON UPDATE CASCADE ON DELETE CASCADE;\n' \ + printf 'ALTER TABLE `%s` ADD FOREIGN KEY (`%s`) REFERENCES `%s` (`id`) ON UPDATE CASCADE ON DELETE ' \ "${table}" \ "${column}" \ "${link}" + if echo "${rest}" | \ + grep -qwF 'NULL'; then + printf 'SET NULL' + else + printf 'CASCADE' + fi + printf ';\n' done fi ;; -- cgit v1.2.3-70-g09d2