From db311eee3c4a014ba7dedf5de7bb5cc83aa56bc0 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Thu, 18 Aug 2016 15:06:18 +0200 Subject: [PATCH] Closes#3 : cfData is declared as array in config/doctrine/Person.orm.yml --- Resources/config/doctrine/Person.orm.yml | 4 +- .../migrations/Version20160818113633.php | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 Resources/migrations/Version20160818113633.php diff --git a/Resources/config/doctrine/Person.orm.yml b/Resources/config/doctrine/Person.orm.yml index e566ddc7e..bdc066aae 100644 --- a/Resources/config/doctrine/Person.orm.yml +++ b/Resources/config/doctrine/Person.orm.yml @@ -32,12 +32,12 @@ Chill\PersonBundle\Entity\Person: type: text default: '' email: - type: text + type: text proxyAccompanyingPeriodOpenState: type: boolean name: proxy_open cFData: - type: array + type: json_array phonenumber: type: text nullable: true diff --git a/Resources/migrations/Version20160818113633.php b/Resources/migrations/Version20160818113633.php new file mode 100644 index 000000000..eed0a3b14 --- /dev/null +++ b/Resources/migrations/Version20160818113633.php @@ -0,0 +1,48 @@ +connection->executeQuery('SELECT id, cfdata FROM person'); + + $this->addSQL('ALTER TABLE person RENAME COLUMN cfdata TO cfdata_old'); + $this->addSQL('ALTER TABLE person ADD COLUMN cfdata jsonb'); + + foreach ($personIdAndCFData as $person) { + $personId = $person['id']; + $cFDataArray = unserialize($person['cfdata']); + $cFDataJson = json_encode($cFDataArray); + $this->addSql( + 'UPDATE person set cfdata = :cfdatajson WHERE id = :id', + ['cfdatajson' => $cFDataJson, 'id' => $personId] + ); + } + } + + /** + * Inverse of up + * + * @param Schema $schema + */ + public function down(Schema $schema) + { + $this->addSQL('ALTER TABLE person DROP COLUMN cfdata'); + $this->addSQL('ALTER TABLE person RENAME COLUMN cfdata_old TO cfdata'); + } +}