Skip to content

Commit 434d00e

Browse files
fix(mysql): remove CHECK constraint incompatible with MySQL 8.0.16+
MySQL 8.0.16+ doesn't allow CHECK constraints on columns that have foreign keys with referential actions (ON DELETE SET NULL). The business rule "only template_id OR custom_template_id can be set" is now enforced in the application layer instead. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7f3cb1e commit 434d00e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

database/schema.mysql.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ CREATE TABLE IF NOT EXISTS `albums` (
220220
KEY `idx_albums_published_date` (`is_published`, `published_at`),
221221
KEY `idx_albums_published_shoot` (`is_published`, `shoot_date`),
222222
KEY `idx_albums_published_nsfw` (`is_published`, `is_nsfw`),
223-
CHECK ((`template_id` IS NULL) OR (`custom_template_id` IS NULL)),
223+
-- NOTE: CHECK constraint removed for MySQL 8.0.16+ compatibility
224+
-- Business rule "only template_id OR custom_template_id can be set" enforced in application layer
224225
CONSTRAINT `fk_albums_category` FOREIGN KEY (`category_id`) REFERENCES `categories`(`id`) ON DELETE RESTRICT,
225226
CONSTRAINT `fk_albums_location` FOREIGN KEY (`location_id`) REFERENCES `locations`(`id`) ON DELETE SET NULL,
226227
CONSTRAINT `fk_albums_template` FOREIGN KEY (`template_id`) REFERENCES `templates`(`id`) ON DELETE SET NULL,

0 commit comments

Comments
 (0)