public function providerForTestGetModifyColumnRemoveDefaultValueDDL()
 {
     $t1 = new Table('test');
     $t1->setIdentifierQuoting(true);
     $c1 = new Column();
     $c1->setName('test');
     $c1->getDomain()->setType('INTEGER');
     $c1->setDefaultValue(0);
     $t1->addColumn($c1);
     $t2 = new Table('test');
     $t2->setIdentifierQuoting(true);
     $c2 = new Column();
     $c2->setName('test');
     $c2->getDomain()->setType('INTEGER');
     $t2->addColumn($c2);
     return [[ColumnComparator::computeDiff($c1, $c2)]];
 }
 public function testCompareSeveralColumnDifferences()
 {
     $t1 = new Table();
     $c1 = new Column('col1');
     $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c1->getDomain()->replaceSize(255);
     $c1->setNotNull(false);
     $t1->addColumn($c1);
     $c2 = new Column('col2');
     $c2->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $c2->setNotNull(true);
     $t1->addColumn($c2);
     $c3 = new Column('col3');
     $c3->getDomain()->copy($this->platform->getDomainForType('VARCHAR'));
     $c3->getDomain()->replaceSize(255);
     $t1->addColumn($c3);
     $t2 = new Table();
     $c4 = new Column('col1');
     $c4->getDomain()->copy($this->platform->getDomainForType('DOUBLE'));
     $c4->getDomain()->replaceScale(2);
     $c4->getDomain()->replaceSize(3);
     $c4->setNotNull(true);
     $c4->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE));
     $t2->addColumn($c4);
     $c5 = new Column('col22');
     $c5->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $c5->setNotNull(true);
     $t2->addColumn($c5);
     $c6 = new Column('col4');
     $c6->getDomain()->copy($this->platform->getDomainForType('LONGVARCHAR'));
     $c6->getDomain()->setDefaultValue(new ColumnDefaultValue('123', ColumnDefaultValue::TYPE_VALUE));
     $t2->addColumn($c6);
     // col1 was modified, col2 was renamed, col3 was removed, col4 was added
     $tc = new TableComparator();
     $tc->setFromTable($t1);
     $tc->setToTable($t2);
     $nbDiffs = $tc->compareColumns();
     $tableDiff = $tc->getTableDiff();
     $this->assertEquals(4, $nbDiffs);
     $this->assertEquals([[$c2, $c5]], $tableDiff->getRenamedColumns());
     $this->assertEquals(['col4' => $c6], $tableDiff->getAddedColumns());
     $this->assertEquals(['col3' => $c3], $tableDiff->getRemovedColumns());
     $columnDiff = ColumnComparator::computeDiff($c1, $c4);
     $this->assertEquals(['col1' => $columnDiff], $tableDiff->getModifiedColumns());
 }
Ejemplo n.º 3
0
    public function testGetModifyColumnDDLWithVarcharWithoutSizeAndPlatform()
    {
        $t1 = new Table('foo');
        $c1 = new Column('bar');
        $c1->setTable($t1);
        $c1->getDomain()->copy($this->getPlatform()->getDomainForType('VARCHAR'));
        $c1->getDomain()->replaceSize(null);
        $c1->getDomain()->replaceScale(null);
        $t1->addColumn($c1);
        $schema = <<<EOF
<database name="test">
    <table name="foo">
        <column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
        <column name="bar"/>
    </table>
</database>
EOF;
        $xtad = new XmlToAppData(null);
        $appData = $xtad->parseString($schema);
        $db = $appData->getDatabase();
        $table = $db->getTable('foo');
        $c2 = $table->getColumn('bar');
        $columnDiff = ColumnComparator::computeDiff($c1, $c2);
        $expected = false;
        $this->assertSame($expected, $columnDiff);
    }
Ejemplo n.º 4
0
 /**
  * Returns the number of differences.
  *
  * Compares the primary keys of the fromTable and the toTable,
  * and modifies the inner tableDiff if necessary.
  *
  * @param  boolean $caseInsensitive
  * @return integer
  */
 public function comparePrimaryKeys($caseInsensitive = false)
 {
     $pkDifferences = 0;
     $fromTablePk = $this->getFromTable()->getPrimaryKey();
     $toTablePk = $this->getToTable()->getPrimaryKey();
     // check for new pk columns in $toTable
     foreach ($toTablePk as $column) {
         if (!$this->getFromTable()->hasColumn($column->getName(), $caseInsensitive) || !$this->getFromTable()->getColumn($column->getName(), $caseInsensitive)->isPrimaryKey()) {
             $this->tableDiff->addAddedPkColumn($column->getName(), $column);
             $pkDifferences++;
         }
     }
     // check for removed pk columns in $toTable
     foreach ($fromTablePk as $column) {
         if (!$this->getToTable()->hasColumn($column->getName(), $caseInsensitive) || !$this->getToTable()->getColumn($column->getName(), $caseInsensitive)->isPrimaryKey()) {
             $this->tableDiff->addRemovedPkColumn($column->getName(), $column);
             $pkDifferences++;
         }
     }
     // check for column renamings
     foreach ($this->tableDiff->getAddedPkColumns() as $addedColumnName => $addedColumn) {
         foreach ($this->tableDiff->getRemovedPkColumns() as $removedColumnName => $removedColumn) {
             if (!ColumnComparator::computeDiff($addedColumn, $removedColumn, $caseInsensitive)) {
                 // no difference except the name, that's probably a renaming
                 $this->tableDiff->addRenamedPkColumn($removedColumn, $addedColumn);
                 $this->tableDiff->removeAddedPkColumn($addedColumnName);
                 $this->tableDiff->removeRemovedPkColumn($removedColumnName);
                 $pkDifferences--;
                 // skip to the next added column
                 break;
             }
         }
     }
     return $pkDifferences;
 }
Ejemplo n.º 5
0
 public function testCompareMultipleDifferences()
 {
     $c1 = new Column();
     $c1->getDomain()->copy($this->platform->getDomainForType('INTEGER'));
     $c1->setNotNull(false);
     $c2 = new Column();
     $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));
     $expectedChangedProperties = array('type' => array('INTEGER', 'DOUBLE'), 'sqlType' => array('INTEGER', 'DOUBLE'), 'scale' => array(NULL, 2), 'size' => array(NULL, 3), 'notNull' => array(false, true), 'defaultValueType' => array(NULL, ColumnDefaultValue::TYPE_VALUE), 'defaultValueValue' => array(NULL, 123));
     $this->assertEquals($expectedChangedProperties, ColumnComparator::compareColumns($c1, $c2));
 }