Commit bf892f21faaa74898474ec8d810cc2f8971b1bc7

Authored by Eduardo Santos
Committed by Eduardo Santos
2 parents f408a131 e5799f9a
Exists in master and in 1 other branch 3.1

Corrige erro de execuçao do migration para o caso de a coluna ja estar definida

src/Cacic/CommonBundle/DoctrineMigrations/Version20140424182701.php
... ... @@ -23,6 +23,7 @@ class Version20140424182701 extends AbstractMigration implements ContainerAwareI
23 23 {
24 24 // this up() migration is auto-generated, please modify it to your needs
25 25 $this->abortIf($this->connection->getDatabasePlatform()->getName() != "postgresql", "Migration can only be executed safely on 'postgresql'.");
  26 + $sm = $this->connection->getSchemaManager();
26 27  
27 28 $logger = $this->container->get('logger');
28 29 $rootDir = $this->container->get('kernel')->getRootDir();
... ... @@ -30,7 +31,11 @@ class Version20140424182701 extends AbstractMigration implements ContainerAwareI
30 31 $upgradeSQL1 = file_get_contents($upgrade1);
31 32  
32 33 // Altera o modelo de dados
33   - $this->addSql("ALTER TABLE computador_coleta ADD dt_hr_inclusao TIMESTAMP(0) WITHOUT TIME ZONE");
  34 + $columns = $sm->listTableColumns('computador_coleta');
  35 + if (!array_key_exists('dt_hr_inclusao', $columns)) {
  36 + $logger->debug("Adicionando coluna dt_hr_inclusao na tabela computador_coleta");
  37 + $this->addSql("ALTER TABLE computador_coleta ADD dt_hr_inclusao TIMESTAMP(0) WITHOUT TIME ZONE");
  38 + }
34 39  
35 40 $logger->debug("Arquivo de atualização: $upgrade1");
36 41  
... ...