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 = PropelColumnComparator::computeDiff($c1, $c2);
        $expected = false;
        $this->assertSame($expected, $columnDiff);
    }
 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 PropelTableComparator();
     $tc->setFromTable($t1);
     $tc->setToTable($t2);
     $nbDiffs = $tc->compareColumns();
     $tableDiff = $tc->getTableDiff();
     $this->assertEquals(4, $nbDiffs);
     $this->assertEquals(array(array($c2, $c5)), $tableDiff->getRenamedColumns());
     $this->assertEquals(array('col4' => $c6), $tableDiff->getAddedColumns());
     $this->assertEquals(array('col3' => $c3), $tableDiff->getRemovedColumns());
     $columnDiff = PropelColumnComparator::computeDiff($c1, $c4);
     $this->assertEquals(array('col1' => $columnDiff), $tableDiff->getModifiedColumns());
 }
 /**
  * Compare the primary keys of the fromTable and the toTable,
  * and modifies the inner tableDiff if necessary.
  * Returns the number of differences.
  *
  * @param boolean $caseInsensitive Whether the comparison is case insensitive.
  *                                 False by default.
  *
  * @return integer The number of primary key differences
  */
 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 (!PropelColumnComparator::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--;
             }
         }
     }
     return $pkDifferences;
 }
 public function providerForTestGetModifyColumnsDDL()
 {
     $t1 = new Table('foo');
     $c1 = new Column('bar1');
     $c1->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE'));
     $c1->getDomain()->replaceSize(2);
     $t1->addColumn($c1);
     $c2 = new Column('bar2');
     $c2->getDomain()->setType('INTEGER');
     $c2->getDomain()->setSqlType('INTEGER');
     $t1->addColumn($c2);
     $t2 = new Table('foo');
     $c3 = new Column('bar1');
     $c3->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE'));
     $c3->getDomain()->replaceSize(3);
     $t2->addColumn($c3);
     $c4 = new Column('bar2');
     $c4->getDomain()->setType('INTEGER');
     $c4->getDomain()->setSqlType('INTEGER');
     $c4->setNotNull(true);
     $t2->addColumn($c4);
     return array(array(array(PropelColumnComparator::computeDiff($c1, $c3), PropelColumnComparator::computeDiff($c2, $c4))));
 }
 public function providerForTestGetModifyColumnRemoveDefaultValueDDL()
 {
     $t1 = new Table('test');
     $c1 = new Column();
     $c1->setName('test');
     $c1->getDomain()->setType('INTEGER');
     $c1->setDefaultValue(0);
     $t1->addColumn($c1);
     $t2 = new Table('test');
     $c2 = new Column();
     $c2->setName('test');
     $c2->getDomain()->setType('INTEGER');
     $t2->addColumn($c2);
     return array(array(PropelColumnComparator::computeDiff($c1, $c2)));
 }
    public function testGetModifyColumnDDLWithChangedTypeAndDefault()
    {
        $t1 = new Table('foo');
        $c1 = new Column('bar');
        $c1->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE'));
        $c1->getDomain()->replaceSize(2);
        $t1->addColumn($c1);
        $t2 = new Table('foo');
        $c2 = new Column('bar');
        $c2->getDomain()->copy($this->getPlatform()->getDomainForType('DOUBLE'));
        $c2->getDomain()->replaceSize(3);
        $c2->getDomain()->setDefaultValue(new ColumnDefaultValue(-100, ColumnDefaultValue::TYPE_VALUE));
        $t2->addColumn($c2);
        $columnDiff = PropelColumnComparator::computeDiff($c1, $c2);
        $expected = <<<END

ALTER TABLE "foo" ALTER COLUMN "bar" TYPE DOUBLE PRECISION;

ALTER TABLE "foo" ALTER COLUMN "bar" SET DEFAULT -100;

END;
        $this->assertEquals($expected, $this->getPlatform()->getModifyColumnDDL($columnDiff));
    }