From 0e429126de2d9f5d950b72397b0c28d3eea76259 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Thu, 23 Jul 2026 22:48:47 +0330 Subject: [PATCH] feat(migration): update blogs table to add nullable sources field and enforce JSON NOT NULL constraint --- migrations/Version20260723171254.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/migrations/Version20260723171254.php b/migrations/Version20260723171254.php index 3f991019..9f9263f1 100644 --- a/migrations/Version20260723171254.php +++ b/migrations/Version20260723171254.php @@ -22,7 +22,14 @@ final class Version20260723171254 extends AbstractMigration // Scoped to the blogs table only. Unrelated project-wide schema drift that // doctrine:diff also emitted (messenger_messages, date_overrides, …) is // deliberately left out — it belongs to other migrations, not this feature. - $this->addSql('ALTER TABLE blogs ADD sources JSON NOT NULL, ADD review_status VARCHAR(20) DEFAULT NULL, ADD reviewed_at INT DEFAULT NULL, ADD review_note VARCHAR(500) DEFAULT NULL, ADD topic_slug VARCHAR(255) DEFAULT NULL, ADD reviewer_id INT DEFAULT NULL'); + // Nullable columns first (safe on a table with existing rows). + $this->addSql('ALTER TABLE blogs ADD review_status VARCHAR(20) DEFAULT NULL, ADD reviewed_at INT DEFAULT NULL, ADD review_note VARCHAR(500) DEFAULT NULL, ADD topic_slug VARCHAR(255) DEFAULT NULL, ADD reviewer_id INT DEFAULT NULL'); + // `sources` is JSON NOT NULL: adding it directly to a table that already + // has rows fails the json_valid CHECK (empty backfill is invalid JSON). + // Add nullable, backfill '[]', then enforce NOT NULL. + $this->addSql('ALTER TABLE blogs ADD sources JSON DEFAULT NULL'); + $this->addSql("UPDATE blogs SET sources = '[]'"); + $this->addSql('ALTER TABLE blogs MODIFY sources JSON NOT NULL'); $this->addSql('ALTER TABLE blogs ADD CONSTRAINT FK_F41BCA7070574616 FOREIGN KEY (reviewer_id) REFERENCES users (id) ON DELETE SET NULL'); $this->addSql('CREATE UNIQUE INDEX UNIQ_F41BCA70A076FAD7 ON blogs (topic_slug)'); $this->addSql('CREATE INDEX IDX_F41BCA7070574616 ON blogs (reviewer_id)');