public function testCompareChangedIndexFieldPositions()
 {
     $schema1 = new Schema(array('bugdb' => new Table('bugdb', array('integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer'))), array('primary' => new Index('primary', array('integerfield1', 'integerfield2'), true)))));
     $schema2 = new Schema(array('bugdb' => new Table('bugdb', array('integerfield1' => new Column('integerfield1', Type::getType('integer')), 'integerfield2' => new Column('integerfield2', Type::getType('integer'))), array('primary' => new Index('primary', array('integerfield2', 'integerfield1'), true)))));
     $expected = new SchemaDiff(array(), array('bugdb' => new TableDiff('bugdb', array(), array(), array(), array(), array('primary' => new Index('primary', array('integerfield2', 'integerfield1'), true)))));
     $actual = Comparator::compareSchemas($schema1, $schema2);
     $this->assertEquals($expected, $actual);
 }
Exemplo n.º 2
0
 /**
  * Creates all required tables from schema if they don't exist
  */
 protected function setupSchema(array $files, $clean = false)
 {
     foreach ($files as $rname => $filepath) {
         $this->msg('Using schema from ' . basename($filepath), 1);
         $this->status('');
         if (($list = (include $filepath)) === false) {
             throw new \Aimeos\MW\Setup\Exception(sprintf('Unable to get list from file "%1$s"', $filepath));
         }
         $dbal = $this->getConnection($rname)->getRawObject();
         if (!$dbal instanceof \Doctrine\DBAL\Connection) {
             throw new \Aimeos\MW\Setup\Exception('Not a DBAL connection');
         }
         $dbalschema = new \Doctrine\DBAL\Schema\Schema();
         $dbalManager = $dbal->getSchemaManager();
         $platform = $dbal->getDatabasePlatform();
         $schema = $this->getSchema($rname);
         if (isset($list['table'])) {
             foreach ((array) $list['table'] as $name => $fcn) {
                 $this->msg(sprintf('Checking table "%1$s": ', $name), 2);
                 $table = $dbalManager->listTableDetails($name);
                 $tables = $table->getColumns() !== array() ? array($table) : array();
                 $tableSchema = new \Doctrine\DBAL\Schema\Schema($tables);
                 $schemaDiff = \Doctrine\DBAL\Schema\Comparator::compareSchemas($tableSchema, $fcn(clone $dbalschema));
                 $stmts = $this->remove($this->exclude($schemaDiff, $list), $clean)->toSaveSql($platform);
                 $this->executeList($stmts, $rname);
                 $this->status('done');
             }
         }
         if (isset($list['sequence']) && $schema->supports($schema::HAS_SEQUENCES)) {
             $sequences = $dbalManager->listSequences();
             foreach ((array) $list['sequence'] as $name => $fcn) {
                 $this->msg(sprintf('Checking sequence "%1$s": ', $name), 2);
                 $seqSchema = new \Doctrine\DBAL\Schema\Schema(array(), $sequences);
                 $schemaDiff = \Doctrine\DBAL\Schema\Comparator::compareSchemas($seqSchema, $fcn(clone $dbalschema));
                 $stmts = $this->remove($schemaDiff, $clean)->toSaveSql($platform);
                 $this->executeList($stmts, $rname);
                 $this->status('done');
             }
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Migrates the database.
  *
  * @return Schema
  */
 public function migrate()
 {
     $diff = Comparator::compareSchemas($this->manager->createSchema(), $this->schema);
     foreach ($diff->toSaveSql($this->connection->getDatabasePlatform()) as $query) {
         $this->connection->executeQuery($query);
     }
 }
Exemplo n.º 4
0
 public function testCompareChangedBinaryColumn()
 {
     $oldSchema = new Schema();
     $tableFoo = $oldSchema->createTable('foo');
     $tableFoo->addColumn('id', 'binary');
     $newSchema = new Schema();
     $table = $newSchema->createTable('foo');
     $table->addColumn('id', 'binary', array('length' => 42, 'fixed' => true));
     $expected = new SchemaDiff();
     $expected->fromSchema = $oldSchema;
     $tableDiff = $expected->changedTables['foo'] = new TableDiff('foo');
     $tableDiff->fromTable = $tableFoo;
     $columnDiff = $tableDiff->changedColumns['id'] = new ColumnDiff('id', $table->getColumn('id'));
     $columnDiff->fromColumn = $tableFoo->getColumn('id');
     $columnDiff->changedProperties = array('length', 'fixed');
     $this->assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema));
 }
Exemplo n.º 5
0
 public function testCompareChangedColumn()
 {
     $oldSchema = new Schema();
     $tableFoo = $oldSchema->createTable('foo');
     $tableFoo->addColumn('id', 'integer');
     $newSchema = new Schema();
     $table = $newSchema->createTable('foo');
     $table->addColumn('id', 'string');
     $expected = new SchemaDiff();
     $expected->fromSchema = $oldSchema;
     $tableDiff = $expected->changedTables['foo'] = new TableDiff('foo');
     $tableDiff->fromTable = $tableFoo;
     $columnDiff = $tableDiff->changedColumns['id'] = new ColumnDiff('id', $table->getColumn('id'));
     $columnDiff->fromColumn = $tableFoo->getColumn('id');
     $columnDiff->changedProperties = array('type');
     $this->assertEquals($expected, Comparator::compareSchemas($oldSchema, $newSchema));
 }