Fix collation inconsistency on saved_filters/ticket_attachments (#41)
README Dev Note #12 mandates utf8mb4_general_ci for new tables, but these two tables were created with utf8mb4_unicode_ci in the baseline schema — inconsistent with every other table, and a future join or comparison against a general_ci column would need explicit COLLATE casts or hit "Illegal mix of collations" errors. - Fixed 000_baseline.sql so a fresh install matches the convention directly. - Added 002_fix_collation_consistency.sql for existing deployments. MariaDB silently drops the inline CHECK (json_valid(...)) constraint on saved_filters.filter_criteria when that column is MODIFYed (found by actually running this against a local MariaDB instance), so the migration explicitly re-adds it after the collation conversion. Verified against a local MariaDB 10.11: baseline applies cleanly, migration is idempotent (safe to run twice), and the json_valid CHECK is still enforced afterward. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MGDKHiU5RJdo3dqQUDow3X
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
-- Fix collation inconsistency on saved_filters and ticket_attachments
|
||||
--
|
||||
-- README.md Developer Notes #12: "Database collation: Use
|
||||
-- utf8mb4_general_ci (not unicode_ci) for new tables." These two tables
|
||||
-- were created with utf8mb4_unicode_ci instead, inconsistent with every
|
||||
-- other table in the schema. Mixed collations don't break anything by
|
||||
-- themselves, but any future query joining/comparing these columns
|
||||
-- against general_ci columns needs explicit COLLATE casts or hits
|
||||
-- "Illegal mix of collations" errors.
|
||||
--
|
||||
-- Safe to re-run.
|
||||
|
||||
ALTER TABLE `saved_filters`
|
||||
CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
|
||||
|
||||
-- saved_filters.filter_criteria is pinned to utf8mb4_bin (for the
|
||||
-- json_valid() CHECK constraint) — restore that after the table-wide
|
||||
-- CONVERT TO above, which resets it to general_ci. MariaDB drops the
|
||||
-- inline CHECK when the column is MODIFYed, so re-add it explicitly.
|
||||
ALTER TABLE `saved_filters`
|
||||
MODIFY COLUMN `filter_criteria` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL;
|
||||
|
||||
ALTER TABLE `saved_filters`
|
||||
DROP CONSTRAINT IF EXISTS `saved_filters_filter_criteria_json`;
|
||||
|
||||
ALTER TABLE `saved_filters`
|
||||
ADD CONSTRAINT `saved_filters_filter_criteria_json` CHECK (json_valid(`filter_criteria`));
|
||||
|
||||
ALTER TABLE `ticket_attachments`
|
||||
CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
|
||||
Reference in New Issue
Block a user