Skip to content

Commit 2871640

Browse files
committed
Migrate table names with uppercase to lowercase names (macOS, Windows)
For case sensitive filesystems which are typically used by Linux such renames were already done in earlier migration steps, but those steps have no effect on macOS and Windows. The new SQL migration code renames any table name with uppercase letters to a lowercase table name. The script was created by Claude.AI. Fixes: #6139 Signed-off-by: Stefan Weil <sw@weilnetz.de>
1 parent 256951c commit 2871640

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
--
2+
-- (c) Kitodo. Key to digital objects e. V. <contact@kitodo.org>
3+
--
4+
-- This file is part of the Kitodo project.
5+
--
6+
-- It is licensed under GNU General Public License version 3 or later.
7+
--
8+
9+
-- This SQL script renames all tables to lowercase.
10+
-- This is required for MariaDB on macOS or Windows because these
11+
-- operating systems use case insensitive filesystems.
12+
13+
-- Table renames on such filesystems must use an intermediate table name
14+
-- because a direct `RENAME TABLE A TO a;` does not work.
15+
16+
-- First, create a procedure to handle the renames
17+
DELIMITER //
18+
19+
CREATE PROCEDURE rename_tables_to_lowercase()
20+
BEGIN
21+
DECLARE done INT DEFAULT FALSE;
22+
DECLARE table_name_var VARCHAR(255);
23+
24+
-- Cursor for all tables with uppercase characters
25+
DECLARE table_cursor CURSOR FOR
26+
SELECT TABLE_NAME
27+
FROM INFORMATION_SCHEMA.TABLES
28+
WHERE TABLE_SCHEMA = DATABASE()
29+
AND TABLE_NAME != LOWER(TABLE_NAME);
30+
31+
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
32+
33+
OPEN table_cursor;
34+
35+
rename_loop: LOOP
36+
FETCH table_cursor INTO table_name_var;
37+
IF done THEN
38+
LEAVE rename_loop;
39+
END IF;
40+
41+
-- Execute renames using dynamic SQL
42+
SET @temp_name = CONCAT(LOWER(table_name_var), '_temp');
43+
SET @rename1 = CONCAT('RENAME TABLE `', table_name_var, '` TO `', @temp_name, '`');
44+
SET @rename2 = CONCAT('RENAME TABLE `', @temp_name, '` TO `', LOWER(table_name_var), '`');
45+
46+
PREPARE stmt1 FROM @rename1;
47+
EXECUTE stmt1;
48+
DEALLOCATE PREPARE stmt1;
49+
50+
PREPARE stmt2 FROM @rename2;
51+
EXECUTE stmt2;
52+
DEALLOCATE PREPARE stmt2;
53+
54+
END LOOP;
55+
56+
CLOSE table_cursor;
57+
END //
58+
59+
DELIMITER ;
60+
61+
-- Execute the procedure
62+
CALL rename_tables_to_lowercase();
63+
64+
-- Clean up
65+
DROP PROCEDURE rename_tables_to_lowercase;

0 commit comments

Comments
 (0)