mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
Closes#3 : cfData is declared as array in config/doctrine/Person.orm.yml
This commit is contained in:
parent
ce7c149c35
commit
db311eee3c
@ -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
|
||||
|
48
Resources/migrations/Version20160818113633.php
Normal file
48
Resources/migrations/Version20160818113633.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Application\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* This migration store the cfdata using the postgresql jsonb type instead
|
||||
* of the result of the sterialization
|
||||
*/
|
||||
class Version20160818113633 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Make a copy of the column cfdata into the column cfdata_old. Then
|
||||
* remplace the sterialized data into a json data.
|
||||
*
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
$personIdAndCFData = $this->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');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user