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'); + } +}