mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 05:44:24 +00:00
Adding chill_person as prefix for tables of this bundle
This commit is contained in:
parent
ae57771de9
commit
52fb5f56be
@ -1,4 +1,5 @@
|
|||||||
Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive:
|
Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive:
|
||||||
|
table: chill_person_closingmotive
|
||||||
type: entity
|
type: entity
|
||||||
id:
|
id:
|
||||||
id:
|
id:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
Chill\PersonBundle\Entity\AccompanyingPeriod:
|
Chill\PersonBundle\Entity\AccompanyingPeriod:
|
||||||
table: accompanying_period
|
table: chill_person_accompanying_period
|
||||||
type: entity
|
type: entity
|
||||||
id:
|
id:
|
||||||
id:
|
id:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
Chill\PersonBundle\Entity\MaritalStatus:
|
Chill\PersonBundle\Entity\MaritalStatus:
|
||||||
table: marital_status
|
table: chill_person_marital_status
|
||||||
type: entity
|
type: entity
|
||||||
id:
|
id:
|
||||||
id:
|
id:
|
||||||
@ -8,4 +8,4 @@ Chill\PersonBundle\Entity\MaritalStatus:
|
|||||||
fields:
|
fields:
|
||||||
name:
|
name:
|
||||||
type: json_array
|
type: json_array
|
||||||
lifecycleCallbacks: { }
|
lifecycleCallbacks: { }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
Chill\PersonBundle\Entity\Person:
|
Chill\PersonBundle\Entity\Person:
|
||||||
type: entity
|
type: entity
|
||||||
table: null
|
table: chill_person_person
|
||||||
indexes:
|
indexes:
|
||||||
person_names:
|
person_names:
|
||||||
columns: [firstName, lastName]
|
columns: [firstName, lastName]
|
||||||
|
@ -4,78 +4,56 @@ namespace Application\Migrations;
|
|||||||
|
|
||||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||||
use Doctrine\DBAL\Schema\Schema;
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
||||||
use Chill\MainBundle\Entity\Center;
|
use Chill\MainBundle\Entity\Center;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a center to class person
|
* Add a center to class person
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
class Version20150607231010 extends AbstractMigration implements ContainerAwareInterface
|
class Version20150607231010 extends AbstractMigration
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @var ContainerInterface
|
|
||||||
*/
|
|
||||||
private $container;
|
|
||||||
|
|
||||||
public function setContainer(ContainerInterface $container = null)
|
|
||||||
{
|
|
||||||
if ($container === NULL) {
|
|
||||||
throw new \RuntimeException('Container is not provided. This migration '
|
|
||||||
. 'need container to set a default center');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->container = $container;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDescription()
|
public function getDescription()
|
||||||
{
|
{
|
||||||
return 'Add a center on the person entity. The default center is the first '
|
return 'Add a center on the person entity. The default center is the first '
|
||||||
. 'recorded.';
|
. 'recorded.';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Schema $schema
|
* @param Schema $schema
|
||||||
*/
|
*/
|
||||||
public function up(Schema $schema)
|
public function up(Schema $schema)
|
||||||
{
|
{
|
||||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
$this->abortIf(
|
||||||
|
$this->connection->getDatabasePlatform()->getName() != 'postgresql',
|
||||||
|
'Migration can only be executed safely on \'postgresql\'.'
|
||||||
|
);
|
||||||
|
|
||||||
// retrieve center for setting a default center
|
// retrieve center for setting a default center
|
||||||
$centers = $this->container->get('doctrine.orm.entity_manager')
|
$centers = $this->connection->fetchAll('SELECT id FROM centers');
|
||||||
->getRepository('ChillMainBundle:Center')
|
|
||||||
->findAll();
|
|
||||||
|
|
||||||
|
|
||||||
if (count($centers) > 0) {
|
if (count($centers) > 0) {
|
||||||
$defaultCenterId = $centers[0]->getId();
|
$defaultCenterId = $centers[0]['id'];
|
||||||
} else { // if no center, performs other checks
|
} else { // if no center, performs other checks
|
||||||
//check if there are data in person table
|
//check if there are data in person table
|
||||||
$nbPeople = $this->container->get('doctrine.orm.entity_manager')
|
$nbPeople = $this->connection->fetchColumn('SELECT count(*) FROM person');
|
||||||
->createQuery('SELECT count(p) FROM ChillPersonBundle:Person p')
|
|
||||||
->getSingleScalarResult();
|
|
||||||
|
|
||||||
if ($nbPeople > 0) {
|
if ($nbPeople > 0) {
|
||||||
// we have data ! We have to create a center !
|
// we have data ! We have to create a center !
|
||||||
$center = new Center();
|
$newCenterId = $this->connection->fetchColumn('SELECT nextval(\'centers_id_seq\');');
|
||||||
$center->setName('Auto-created center');
|
$this->addSql(
|
||||||
$this->container->get('doctrine.orm.entity_manager')
|
'INSERT INTO centers (id, name) VALUES (:id, :name)',
|
||||||
->persist($center)
|
['id' => $newCenterId, 'name' => 'Auto-created center']
|
||||||
->flush();
|
);
|
||||||
$defaultCenterId = $center->getId();
|
$defaultCenterId = $newCenterId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->addSql('ALTER TABLE person ADD center_id INT');
|
$this->addSql('ALTER TABLE person ADD center_id INT');
|
||||||
|
|
||||||
if (isset($defaultCenterId)) {
|
if (isset($defaultCenterId)) {
|
||||||
$this->addSql('UPDATE person SET center_id = :id', array('id' => $defaultCenterId));
|
$this->addSql('UPDATE person SET center_id = :id', array('id' => $defaultCenterId));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addSql('ALTER TABLE person '
|
$this->addSql('ALTER TABLE person '
|
||||||
. 'ADD CONSTRAINT FK_person_center FOREIGN KEY (center_id) '
|
. 'ADD CONSTRAINT FK_person_center FOREIGN KEY (center_id) '
|
||||||
. 'REFERENCES centers (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
. 'REFERENCES centers (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
@ -88,13 +66,13 @@ class Version20150607231010 extends AbstractMigration implements ContainerAwareI
|
|||||||
*/
|
*/
|
||||||
public function down(Schema $schema)
|
public function down(Schema $schema)
|
||||||
{
|
{
|
||||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
|
$this->abortIf(
|
||||||
|
$this->connection->getDatabasePlatform()->getName() != 'postgresql',
|
||||||
|
'Migration can only be executed safely on \'postgresql\'.'
|
||||||
|
);
|
||||||
|
|
||||||
$this->addSql('ALTER TABLE Person DROP CONSTRAINT FK_person_center');
|
$this->addSql('ALTER TABLE Person DROP CONSTRAINT FK_person_center');
|
||||||
$this->addSql('DROP INDEX IDX_person_center');
|
$this->addSql('DROP INDEX IDX_person_center');
|
||||||
$this->addSql('ALTER TABLE Person DROP center_id');
|
$this->addSql('ALTER TABLE Person DROP center_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
46
Resources/migrations/Version20160818151130.php
Normal file
46
Resources/migrations/Version20160818151130.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Application\Migrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add the prefix 'chill_person' to all the (db) table name of this bundle
|
||||||
|
*/
|
||||||
|
class Version20160818151130 extends AbstractMigration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Schema $schema
|
||||||
|
*/
|
||||||
|
public function up(Schema $schema)
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE person RENAME TO chill_person_person');
|
||||||
|
$this->addSql('ALTER TABLE person_id_seq RENAME TO chill_person_person_id_seq');
|
||||||
|
|
||||||
|
$this->addSql('ALTER TABLE marital_status RENAME TO chill_person_marital_status');
|
||||||
|
|
||||||
|
$this->addSql('ALTER TABLE accompanying_period RENAME TO chill_person_accompanying_period');
|
||||||
|
$this->addSql('ALTER TABLE accompanying_period_id_seq RENAME TO chill_person_accompanying_period_id_seq');
|
||||||
|
|
||||||
|
$this->addSql('ALTER TABLE closingmotive RENAME TO chill_person_closingmotive');
|
||||||
|
$this->addSql('ALTER TABLE closingmotive_id_seq RENAME TO chill_person_closingmotive_id_seq');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Schema $schema
|
||||||
|
*/
|
||||||
|
public function down(Schema $schema)
|
||||||
|
{
|
||||||
|
$this->addSQL('ALTER TABLE chill_person_person RENAME TO person');
|
||||||
|
$this->addSql('ALTER TABLE chill_person_person_id_seq RENAME TO person_id_seq');
|
||||||
|
|
||||||
|
$this->addSQL('ALTER TABLE chill_person_marital_status RENAME TO marital_status ');
|
||||||
|
|
||||||
|
$this->addSQl('ALTER TABLE chill_person_accompanying_period RENAME TO accompanying_period');
|
||||||
|
$this->addSql('ALTER TABLE chill_person_accompanying_period_id_seq RENAME TO accompanying_period_id_seq');
|
||||||
|
|
||||||
|
$this->addSQL('ALTER TABLE chill_person_closingmotive RENAME TO closingmotive');
|
||||||
|
$this->addSql('ALTER TABLE chill_person_closingmotive_id_seq RENAME TO closingmotive_id_seq');
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user