本文整理汇总了PHP中Doctrine\DBAL\Schema\Comparator::compareSchemas方法的典型用法代码示例。如果您正苦于以下问题:PHP Comparator::compareSchemas方法的具体用法?PHP Comparator::compareSchemas怎么用?PHP Comparator::compareSchemas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Schema\Comparator
的用法示例。
在下文中一共展示了Comparator::compareSchemas方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCompareChangedIndexFieldPositions
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);
}
示例2: setupSchema
/**
* 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');
}
}
}
}
示例3: migrate
/**
* 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);
}
}
示例4: testCompareChangedBinaryColumn
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));
}
示例5: testCompareChangedColumn
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));
}