From 21d8111734d8eb4f54033f29f23ce8bce4b63b32 Mon Sep 17 00:00:00 2001 From: "ext.jeremy.guillot@maxicoffee.domains" Date: Thu, 26 Mar 2026 17:58:07 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20migrer=20les=20donn=C3=A9es=20manga.genr?= =?UTF-8?q?es=20de=20PHP=20s=C3=A9rialis=C3=A9=20vers=20JSON?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La migration vers DBAL 4 a changé le type de colonne genres de Types::ARRAY (PHP sérialisé) vers Types::JSON. Les données existantes en base doivent être converties via preUp() avant l'ALTER TABLE. --- migrations/Version20260326165659.php | 97 ++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 migrations/Version20260326165659.php diff --git a/migrations/Version20260326165659.php b/migrations/Version20260326165659.php new file mode 100644 index 0000000..29415c1 --- /dev/null +++ b/migrations/Version20260326165659.php @@ -0,0 +1,97 @@ +connection->fetchAllAssociative('SELECT id, genres FROM manga WHERE genres IS NOT NULL'); + foreach ($rows as $row) { + $raw = $row['genres']; + // Skip if already valid JSON + json_decode($raw); + if (json_last_error() === JSON_ERROR_NONE) { + continue; + } + // Unserialize PHP format and re-encode as JSON + $value = @unserialize($raw); + if ($value === false && $raw !== 'b:0;') { + $value = []; + } + $this->connection->executeStatement( + 'UPDATE manga SET genres = :json WHERE id = :id', + ['json' => json_encode($value), 'id' => $row['id']] + ); + } + } + + public function up(Schema $schema): void + { + $this->addSql('COMMENT ON COLUMN api_token.expires_at IS \'\''); + $this->addSql('COMMENT ON COLUMN content_source.health_last_tested_at IS \'\''); + $this->addSql('COMMENT ON COLUMN failed_job.failed_at IS \'\''); + $this->addSql('COMMENT ON COLUMN job.created_at IS \'\''); + $this->addSql('COMMENT ON COLUMN job.started_at IS \'\''); + $this->addSql('COMMENT ON COLUMN job.completed_at IS \'\''); + $this->addSql('ALTER TABLE manga ALTER genres TYPE JSON USING genres::json'); + $this->addSql('COMMENT ON COLUMN manga.genres IS \'\''); + $this->addSql('COMMENT ON COLUMN manga.created_at IS \'\''); + $this->addSql('COMMENT ON COLUMN manga.last_monitoring_check IS \'\''); + $this->addSql('COMMENT ON COLUMN manga_preferred_sources.created_at IS \'\''); + $this->addSql('COMMENT ON COLUMN manga_preferred_sources.updated_at IS \'\''); + $this->addSql('COMMENT ON COLUMN source.created_at IS \'\''); + $this->addSql('COMMENT ON COLUMN source.updated_at IS \'\''); + $this->addSql('DROP INDEX idx_75ea56e0e3bd61ce'); + $this->addSql('DROP INDEX idx_75ea56e0fb7336f0'); + $this->addSql('DROP INDEX idx_75ea56e016ba31db'); + $this->addSql('ALTER TABLE messenger_messages ALTER id DROP DEFAULT'); + $this->addSql('ALTER TABLE messenger_messages ALTER id ADD GENERATED BY DEFAULT AS IDENTITY'); + $this->addSql('COMMENT ON COLUMN messenger_messages.created_at IS \'\''); + $this->addSql('COMMENT ON COLUMN messenger_messages.available_at IS \'\''); + $this->addSql('COMMENT ON COLUMN messenger_messages.delivered_at IS \'\''); + $this->addSql('CREATE INDEX IDX_75EA56E0FB7336F0E3BD61CE16BA31DBBF396750 ON messenger_messages (queue_name, available_at, delivered_at, id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('COMMENT ON COLUMN api_token.expires_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN content_source.health_last_tested_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN failed_job.failed_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN job.created_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN job.started_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN job.completed_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('ALTER TABLE manga ALTER genres TYPE TEXT'); + $this->addSql('COMMENT ON COLUMN manga.genres IS \'(DC2Type:array)\''); + $this->addSql('COMMENT ON COLUMN manga.created_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN manga.last_monitoring_check IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN manga_preferred_sources.created_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN manga_preferred_sources.updated_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('DROP INDEX IDX_75EA56E0FB7336F0E3BD61CE16BA31DBBF396750'); + $this->addSql('ALTER TABLE messenger_messages ALTER id SET DEFAULT nextval(\'messenger_messages_id_seq\'::regclass)'); + $this->addSql('ALTER TABLE messenger_messages ALTER id DROP IDENTITY'); + $this->addSql('COMMENT ON COLUMN messenger_messages.created_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN messenger_messages.available_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN messenger_messages.delivered_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('CREATE INDEX idx_75ea56e0e3bd61ce ON messenger_messages (available_at)'); + $this->addSql('CREATE INDEX idx_75ea56e0fb7336f0 ON messenger_messages (queue_name)'); + $this->addSql('CREATE INDEX idx_75ea56e016ba31db ON messenger_messages (delivered_at)'); + $this->addSql('COMMENT ON COLUMN source.created_at IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('COMMENT ON COLUMN source.updated_at IS \'(DC2Type:datetime_immutable)\''); + } +}