当前位置: 首页>>代码示例>>PHP>>正文


PHP Comparator::diffTable方法代码示例

本文整理汇总了PHP中Doctrine\DBAL\Schema\Comparator::diffTable方法的典型用法代码示例。如果您正苦于以下问题:PHP Comparator::diffTable方法的具体用法?PHP Comparator::diffTable怎么用?PHP Comparator::diffTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\DBAL\Schema\Comparator的用法示例。


在下文中一共展示了Comparator::diffTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createOrUpdateTable

 /**
  * Generates code for creating or updating a database table.
  * @param Doctrine\DBAL\Schema\Table $updatedTable Specifies the updated table schema.
  * @param Doctrine\DBAL\Schema\Table $existingTable Specifies the existing table schema, if applicable.
  * @param string $newTableName An updated name of the theme. 
  * @return string|boolean Returns the migration up() and down() methods code. 
  * Returns false if there the table was not changed.
  */
 public function createOrUpdateTable($updatedTable, $existingTable, $newTableName)
 {
     $tableDiff = false;
     if ($existingTable !== null) {
         // The table already exists
         //
         $comparator = new Comparator();
         $tableDiff = $comparator->diffTable($existingTable, $updatedTable);
         if ($newTableName !== $existingTable->getName()) {
             if (!$tableDiff) {
                 $tableDiff = new TableDiff($existingTable->getName());
             }
             $tableDiff->newName = $newTableName;
         }
     } else {
         // The table doesn't exist
         //
         $tableDiff = new TableDiff($updatedTable->getName(), $updatedTable->getColumns(), [], [], $updatedTable->getIndexes());
         $tableDiff->fromTable = $updatedTable;
     }
     if (!$tableDiff) {
         return false;
     }
     if (!$this->tableHasNameOrColumnChanges($tableDiff) && !$this->tableHasPrimaryKeyChanges($tableDiff)) {
         return false;
     }
     return $this->generateCreateOrUpdateCode($tableDiff, !$existingTable, $updatedTable);
 }
开发者ID:sms-system,项目名称:builder-plugin,代码行数:36,代码来源:TableMigrationCodeGenerator.php

示例2: getSchemaDiff

 public function getSchemaDiff()
 {
     $diff = new SchemaDiff();
     $comparator = new Comparator();
     $tableDiff = $comparator->diffTable($this->conn->getSchemaManager()->createSchema()->getTable($this->tableName), $this->schema->getTable($this->tableName));
     if (false !== $tableDiff) {
         $diff->changedTables[$this->tableName] = $tableDiff;
     }
     return $diff;
 }
开发者ID:BlueTM,项目名称:LexikMonologBrowserBundle,代码行数:10,代码来源:SchemaBuilder.php

示例3: testSearchPathSchemaChanges

 public function testSearchPathSchemaChanges()
 {
     $table = new Table("dbal510tbl");
     $table->addColumn('id', 'integer');
     $table->setPrimaryKey(array('id'));
     $this->_conn->getSchemaManager()->createTable($table);
     $onlineTable = $this->_conn->getSchemaManager()->listTableDetails('dbal510tbl');
     $comparator = new Comparator();
     $diff = $comparator->diffTable($onlineTable, $table);
     $this->assertFalse($diff);
 }
开发者ID:llinder,项目名称:FrameworkBenchmarks,代码行数:11,代码来源:DBAL510Test.php

示例4: up

 public function up(Schema $schema)
 {
     \Database::query('UPDATE Config SET configNamespace="" WHERE configNamespace IS NULL');
     $config = $schema->getTable('Config');
     $fromConfig = clone $config;
     $db = \Database::get();
     $platform = $db->getDatabasePlatform();
     $config->dropPrimaryKey();
     $config->setPrimaryKey(array('configNamespace', 'configGroup', 'configItem'));
     $comparator = new Comparator();
     $diff = $comparator->diffTable($fromConfig, $config);
     $sql = $platform->getAlterTableSQL($diff);
     if (is_array($sql) && count($sql)) {
         foreach ($sql as $q) {
             $db->query($q);
         }
     }
 }
开发者ID:vipkailiai,项目名称:FCVOVA,代码行数:18,代码来源:Version5704.php

示例5: testAlterTableColumnNotNull

 /**
  * @group DBAL-472
  * @group DBAL-1001
  */
 public function testAlterTableColumnNotNull()
 {
     $comparator = new Schema\Comparator();
     $tableName = 'list_table_column_notnull';
     $table = new Schema\Table($tableName);
     $table->addColumn('id', 'integer');
     $table->addColumn('foo', 'integer');
     $table->addColumn('bar', 'string');
     $table->setPrimaryKey(array('id'));
     $this->_sm->dropAndCreateTable($table);
     $columns = $this->_sm->listTableColumns($tableName);
     $this->assertTrue($columns['id']->getNotnull());
     $this->assertTrue($columns['foo']->getNotnull());
     $this->assertTrue($columns['bar']->getNotnull());
     $diffTable = clone $table;
     $diffTable->changeColumn('foo', array('notnull' => false));
     $diffTable->changeColumn('bar', array('length' => 1024));
     $this->_sm->alterTable($comparator->diffTable($table, $diffTable));
     $columns = $this->_sm->listTableColumns($tableName);
     $this->assertTrue($columns['id']->getNotnull());
     $this->assertFalse($columns['foo']->getNotnull());
     $this->assertTrue($columns['bar']->getNotnull());
 }
开发者ID:selimcr,项目名称:servigases,代码行数:27,代码来源:OracleSchemaManagerTest.php

示例6: testDetectChangeIdentifierType

 public function testDetectChangeIdentifierType()
 {
     $this->markTestSkipped('DBAL-2 was reopened, this test cannot work anymore.');
     $tableA = new Table("foo");
     $tableA->addColumn('id', 'integer', array('autoincrement' => false));
     $tableB = new Table("foo");
     $tableB->addColumn('id', 'integer', array('autoincrement' => true));
     $c = new Comparator();
     $tableDiff = $c->diffTable($tableA, $tableB);
     $this->assertType('Doctrine\\DBAL\\Schema\\TableDiff', $tableDiff);
     $this->assertArrayHasKey('id', $tableDiff->changedColumns);
 }
开发者ID:faridos,项目名称:ServerGroveLiveChat,代码行数:12,代码来源:ComparatorTest.php

示例7: testDropPrimaryKeyWithAutoincrementColumn

 /**
  * @group DBAL-464
  */
 public function testDropPrimaryKeyWithAutoincrementColumn()
 {
     $table = new Table("drop_primary_key");
     $table->addColumn('id', 'integer', array('primary' => true, 'autoincrement' => true));
     $table->addColumn('foo', 'integer', array('primary' => true));
     $table->addColumn('bar', 'integer');
     $table->setPrimaryKey(array('id', 'foo'));
     $comparator = new Comparator();
     $diffTable = clone $table;
     $diffTable->dropPrimaryKey();
     $this->assertEquals(array('ALTER TABLE drop_primary_key MODIFY id INT NOT NULL', 'ALTER TABLE drop_primary_key DROP PRIMARY KEY'), $this->_platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)));
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:15,代码来源:MySqlPlatformTest.php

示例8: testAddAutoIncrementPrimaryKey

 /**
  * @group DBAL-586
  */
 public function testAddAutoIncrementPrimaryKey()
 {
     $keyTable = new Table("foo");
     $keyTable->addColumn("id", "integer", array('autoincrement' => true));
     $keyTable->addColumn("baz", "string");
     $keyTable->setPrimaryKey(array("id"));
     $oldTable = new Table("foo");
     $oldTable->addColumn("baz", "string");
     $c = new \Doctrine\DBAL\Schema\Comparator();
     $diff = $c->diffTable($oldTable, $keyTable);
     $sql = $this->_platform->getAlterTableSQL($diff);
     $this->assertEquals(array("ALTER TABLE foo ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)"), $sql);
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:16,代码来源:MySqlPlatformTest.php

示例9: testColumnDefaultLifecycle

 /**
  * @group DBAL-44
  */
 public function testColumnDefaultLifecycle()
 {
     $table = new Table("col_def_lifecycle");
     $table->addColumn('id', 'integer', array('primary' => true, 'autoincrement' => true));
     $table->addColumn('column1', 'string', array('default' => null));
     $table->addColumn('column2', 'string', array('default' => false));
     $table->addColumn('column3', 'string', array('default' => true));
     $table->addColumn('column4', 'string', array('default' => 0));
     $table->addColumn('column5', 'string', array('default' => ''));
     $table->addColumn('column6', 'string', array('default' => 'def'));
     $table->setPrimaryKey(array('id'));
     $this->_sm->dropAndCreateTable($table);
     $columns = $this->_sm->listTableColumns('col_def_lifecycle');
     $this->assertNull($columns['id']->getDefault());
     $this->assertNull($columns['column1']->getDefault());
     $this->assertSame('', $columns['column2']->getDefault());
     $this->assertSame('1', $columns['column3']->getDefault());
     $this->assertSame('0', $columns['column4']->getDefault());
     $this->assertSame('', $columns['column5']->getDefault());
     $this->assertSame('def', $columns['column6']->getDefault());
     $diffTable = clone $table;
     $diffTable->changeColumn('column1', array('default' => false));
     $diffTable->changeColumn('column2', array('default' => null));
     $diffTable->changeColumn('column3', array('default' => false));
     $diffTable->changeColumn('column4', array('default' => null));
     $diffTable->changeColumn('column5', array('default' => false));
     $diffTable->changeColumn('column6', array('default' => 666));
     $comparator = new Comparator();
     $this->_sm->alterTable($comparator->diffTable($table, $diffTable));
     $columns = $this->_sm->listTableColumns('col_def_lifecycle');
     $this->assertSame('', $columns['column1']->getDefault());
     $this->assertNull($columns['column2']->getDefault());
     $this->assertSame('', $columns['column3']->getDefault());
     $this->assertNull($columns['column4']->getDefault());
     $this->assertSame('', $columns['column5']->getDefault());
     $this->assertSame('666', $columns['column6']->getDefault());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:40,代码来源:SchemaManagerFunctionalTestCase.php

示例10: testDetectRenameColumn

 public function testDetectRenameColumn()
 {
     $tableA = new Table("foo");
     $tableA->addColumn('foo', 'integer');
     $tableB = new Table("foo");
     $tableB->addColumn('bar', 'integer');
     $c = new Comparator();
     $tableDiff = $c->diffTable($tableA, $tableB);
     $this->assertEquals(0, count($tableDiff->addedColumns));
     $this->assertEquals(0, count($tableDiff->removedColumns));
     $this->assertArrayHasKey('foo', $tableDiff->renamedColumns);
     $this->assertEquals('bar', $tableDiff->renamedColumns['foo']->getName());
 }
开发者ID:jacques-sounvi,项目名称:addressbook,代码行数:13,代码来源:ComparatorTest.php

示例11: testDiffListGuidTableColumn

 /**
  * @group DBAL-423
  */
 public function testDiffListGuidTableColumn()
 {
     $offlineTable = new Table('list_guid_table_column');
     $offlineTable->addColumn('col_guid', 'guid');
     $this->_sm->dropAndCreateTable($offlineTable);
     $onlineTable = $this->_sm->listTableDetails('list_guid_table_column');
     $comparator = new Comparator();
     $this->assertFalse($comparator->diffTable($offlineTable, $onlineTable), "No differences should be detected with the offline vs online schema.");
 }
开发者ID:selimcr,项目名称:servigases,代码行数:12,代码来源:MySqlSchemaManagerTest.php

示例12: testDiff

 /**
  * @group DBAL-105
  */
 public function testDiff()
 {
     $table = new \Doctrine\DBAL\Schema\Table('twitter_users');
     $table->addColumn('id', 'integer', array('autoincrement' => true));
     $table->addColumn('twitterId', 'integer', array('nullable' => false));
     $table->addColumn('displayName', 'string', array('nullable' => false));
     $table->setPrimaryKey(array('id'));
     $newtable = new \Doctrine\DBAL\Schema\Table('twitter_users');
     $newtable->addColumn('id', 'integer', array('autoincrement' => true));
     $newtable->addColumn('twitter_id', 'integer', array('nullable' => false));
     $newtable->addColumn('display_name', 'string', array('nullable' => false));
     $newtable->addColumn('logged_in_at', 'datetime', array('nullable' => true));
     $newtable->setPrimaryKey(array('id'));
     $c = new Comparator();
     $tableDiff = $c->diffTable($table, $newtable);
     $this->assertInstanceOf('Doctrine\\DBAL\\Schema\\TableDiff', $tableDiff);
     $this->assertEquals(array('twitterid', 'displayname'), array_keys($tableDiff->renamedColumns));
     $this->assertEquals(array('logged_in_at'), array_keys($tableDiff->addedColumns));
     $this->assertEquals(0, count($tableDiff->removedColumns));
 }
开发者ID:llinder,项目名称:FrameworkBenchmarks,代码行数:23,代码来源:ComparatorTest.php

示例13: testAlterTableAddPrimaryKey

 /**
  * @group DBAL-400
  */
 public function testAlterTableAddPrimaryKey()
 {
     $table = new Table('alter_table_add_pk');
     $table->addColumn('id', 'integer');
     $table->addColumn('foo', 'integer');
     $table->addIndex(array('id'), 'idx_id');
     $this->_sm->createTable($table);
     $comparator = new Comparator();
     $diffTable = clone $table;
     $diffTable->dropIndex('idx_id');
     $diffTable->setPrimaryKey(array('id'));
     $this->_sm->alterTable($comparator->diffTable($table, $diffTable));
     $table = $this->_sm->listTableDetails("alter_table_add_pk");
     $this->assertFalse($table->hasIndex('idx_id'));
     $this->assertTrue($table->hasPrimaryKey());
 }
开发者ID:pnaq57,项目名称:zf2demo,代码行数:19,代码来源:MySqlSchemaManagerTest.php

示例14: testQuotesAlterTableChangeColumnLength

 /**
  * @group DBAL-835
  */
 public function testQuotesAlterTableChangeColumnLength()
 {
     $fromTable = new Table('mytable');
     $fromTable->addColumn('unquoted1', 'string', array('comment' => 'Unquoted 1', 'length' => 10));
     $fromTable->addColumn('unquoted2', 'string', array('comment' => 'Unquoted 2', 'length' => 10));
     $fromTable->addColumn('unquoted3', 'string', array('comment' => 'Unquoted 3', 'length' => 10));
     $fromTable->addColumn('create', 'string', array('comment' => 'Reserved keyword 1', 'length' => 10));
     $fromTable->addColumn('table', 'string', array('comment' => 'Reserved keyword 2', 'length' => 10));
     $fromTable->addColumn('select', 'string', array('comment' => 'Reserved keyword 3', 'length' => 10));
     $toTable = new Table('mytable');
     $toTable->addColumn('unquoted1', 'string', array('comment' => 'Unquoted 1', 'length' => 255));
     $toTable->addColumn('unquoted2', 'string', array('comment' => 'Unquoted 2', 'length' => 255));
     $toTable->addColumn('unquoted3', 'string', array('comment' => 'Unquoted 3', 'length' => 255));
     $toTable->addColumn('create', 'string', array('comment' => 'Reserved keyword 1', 'length' => 255));
     $toTable->addColumn('table', 'string', array('comment' => 'Reserved keyword 2', 'length' => 255));
     $toTable->addColumn('select', 'string', array('comment' => 'Reserved keyword 3', 'length' => 255));
     $comparator = new Comparator();
     $this->assertEquals($this->getQuotedAlterTableChangeColumnLengthSQL(), $this->_platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable)));
 }
开发者ID:selimcr,项目名称:servigases,代码行数:22,代码来源:AbstractPlatformTestCase.php

示例15: testAlterColumnComment

 /**
  * @group DBAL-1009
  *
  * @dataProvider getAlterColumnComment
  */
 public function testAlterColumnComment($comment1, $expectedComment1, $comment2, $expectedComment2)
 {
     if (!$this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && !$this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && $this->_conn->getDatabasePlatform()->getName() != 'mssql') {
         $this->markTestSkipped('Database does not support column comments.');
     }
     $offlineTable = new Table('alter_column_comment_test');
     $offlineTable->addColumn('comment1', 'integer', array('comment' => $comment1));
     $offlineTable->addColumn('comment2', 'integer', array('comment' => $comment2));
     $offlineTable->addColumn('no_comment1', 'integer');
     $offlineTable->addColumn('no_comment2', 'integer');
     $this->_sm->dropAndCreateTable($offlineTable);
     $onlineTable = $this->_sm->listTableDetails("alter_column_comment_test");
     $this->assertSame($expectedComment1, $onlineTable->getColumn('comment1')->getComment());
     $this->assertSame($expectedComment2, $onlineTable->getColumn('comment2')->getComment());
     $this->assertNull($onlineTable->getColumn('no_comment1')->getComment());
     $this->assertNull($onlineTable->getColumn('no_comment2')->getComment());
     $onlineTable->changeColumn('comment1', array('comment' => $comment2));
     $onlineTable->changeColumn('comment2', array('comment' => $comment1));
     $onlineTable->changeColumn('no_comment1', array('comment' => $comment1));
     $onlineTable->changeColumn('no_comment2', array('comment' => $comment2));
     $comparator = new Comparator();
     $tableDiff = $comparator->diffTable($offlineTable, $onlineTable);
     $this->assertInstanceOf('Doctrine\\DBAL\\Schema\\TableDiff', $tableDiff);
     $this->_sm->alterTable($tableDiff);
     $onlineTable = $this->_sm->listTableDetails("alter_column_comment_test");
     $this->assertSame($expectedComment2, $onlineTable->getColumn('comment1')->getComment());
     $this->assertSame($expectedComment1, $onlineTable->getColumn('comment2')->getComment());
     $this->assertSame($expectedComment1, $onlineTable->getColumn('no_comment1')->getComment());
     $this->assertSame($expectedComment2, $onlineTable->getColumn('no_comment2')->getComment());
 }
开发者ID:selimcr,项目名称:servigases,代码行数:35,代码来源:SchemaManagerFunctionalTestCase.php


注:本文中的Doctrine\DBAL\Schema\Comparator::diffTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。