Esempio n. 1
0
 /**
  * Add the slug_column to the current table
  */
 public function modifyTable()
 {
     if (!$this->getTable()->containsColumn($this->getParameter('slug_column'))) {
         $this->getTable()->addColumn(array('name' => $this->getParameter('slug_column'), 'type' => 'VARCHAR', 'size' => 255));
         // add a unique to column
         $unique = new Unique($this->getColumnForParameter('slug_column'));
         $unique->setName($this->getTable()->getCommonName() . '_slug');
         $unique->addColumn($this->getTable()->getColumn($this->getParameter('slug_column')));
         if ($this->getParameter('scope_column')) {
             $unique->addColumn($this->getTable()->getColumn($this->getParameter('scope_column')));
         }
         $this->getTable()->addUnique($unique);
     }
 }
 public function testCompareType()
 {
     $c1 = new Column('Foo');
     $i1 = new Index('Foo_Index');
     $i1->addColumn($c1);
     $c2 = new Column('Foo');
     $i2 = new Unique('Foo_Index');
     $i2->addColumn($c2);
     $this->assertTrue(PropelIndexComparator::computeDiff($i1, $i2));
 }
 /**
  * Add the slug_column to the current table
  */
 public function modifyTable()
 {
     $table = $this->getTable();
     $primary_string = $this->getParameter('primary_string');
     if (!$primary_string) {
         $this->exceptionError('Need set parameter "primary_string" in table ' . $table->getName());
     }
     if (!$table->hasColumn($primary_string)) {
         $this->exceptionError('Not found column "' . $primary_string . '" in table ' . $table->getName());
     }
     if (!$this->getTable()->containsColumn($this->getParameter('slug_column'))) {
         $this->getTable()->addColumn(array('name' => $this->getParameter('slug_column'), 'type' => 'VARCHAR', 'size' => 255));
         // add a unique to column
         $unique = new \Unique($this->getColumnForParameter('slug_column'));
         $unique->setName($this->getTable()->getCommonName() . '_slug');
         $unique->addColumn($this->getTable()->getColumn($this->getParameter('slug_column')));
         if ($this->getParameter('scope_column')) {
             $unique->addColumn($this->getTable()->getColumn($this->getParameter('scope_column')));
         }
         $this->getTable()->addUnique($unique);
     }
 }
 public function testCompareModifiedIndices()
 {
     $t1 = new Table();
     $c1 = new Column('Foo');
     $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c1->getDomain()->replaceSize(255);
     $c1->setNotNull(false);
     $t1->addColumn($c1);
     $i1 = new Index('Foo_Index');
     $i1->addColumn($c1);
     $t1->addIndex($i1);
     $t2 = new Table();
     $c2 = new Column('Foo');
     $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
     $c2->getDomain()->replaceScale(2);
     $c2->getDomain()->replaceSize(3);
     $c2->setNotNull(true);
     $c2->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
     $t2->addColumn($c2);
     $i2 = new Unique('Foo_Index');
     $i2->addColumn($c2);
     $t2->addIndex($i2);
     $tc = new PropelTableComparator();
     $tc->setFromTable($t1);
     $tc->setToTable($t2);
     $nbDiffs = $tc->compareIndices();
     $tableDiff = $tc->getTableDiff();
     $this->assertEquals(1, $nbDiffs);
     $this->assertEquals(1, count($tableDiff->getModifiedIndices()));
     $this->assertEquals(array('Foo_Index' => array($i1, $i2)), $tableDiff->getModifiedIndices());
 }
Esempio n. 5
0
 public function providerForTestGetUniqueDDL()
 {
     $table = new Table('foo');
     $column1 = new Column('bar1');
     $column1->getDomain()->copy(new Domain('FOOTYPE'));
     $table->addColumn($column1);
     $column2 = new Column('bar2');
     $column2->getDomain()->copy(new Domain('BARTYPE'));
     $table->addColumn($column2);
     $index = new Unique('babar');
     $index->addColumn($column1);
     $index->addColumn($column2);
     $table->addUnique($index);
     return array(array($index));
 }