From b5db508005109ffc50a754145955fc2e6d9dded4 Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Thu, 28 Jan 2021 04:04:42 +0000 Subject: [PATCH] Fix relative path mismatch (#151) --- migration/relative_path_fix.10.cr | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 migration/relative_path_fix.10.cr diff --git a/migration/relative_path_fix.10.cr b/migration/relative_path_fix.10.cr new file mode 100644 index 0000000..26df876 --- /dev/null +++ b/migration/relative_path_fix.10.cr @@ -0,0 +1,31 @@ +# In DB version 8, we replaced the absolute paths in DB with relative paths, +# but we mistakenly left the starting slashes. This migration removes them. +class RelativePathFix < MG::Base + def up : String + <<-SQL + -- remove leading slashes from the paths in ids + UPDATE ids + SET path = SUBSTR(path, 2, LENGTH(path) - 1) + WHERE path LIKE '/%'; + + -- remove leading slashes from the paths in titles + UPDATE titles + SET path = SUBSTR(path, 2, LENGTH(path) - 1) + WHERE path LIKE '/%'; + SQL + end + + def down : String + <<-SQL + -- add leading slashes to paths in ids + UPDATE ids + SET path = '/' || path + WHERE path NOT LIKE '/%'; + + -- add leading slashes to paths in titles + UPDATE titles + SET path = '/' || path + WHERE path NOT LIKE '/%'; + SQL + end +end