/**
  * @return Schema
  */
 public function createFixtureSchema()
 {
     $schema = new Schema();
     $tableA = $schema->createTable("foo");
     $tableA->addColumn("id", 'integer');
     $tableA->addColumn("bar", 'string', array('length' => 255));
     $tableA->setPrimaryKey(array("id"));
     $schema->createSequence("foo_seq");
     $tableB = $schema->createTable("bar");
     $tableB->addColumn("id", 'integer');
     $tableB->setPrimaryKey(array("id"));
     $tableA->addForeignKeyConstraint($tableB, array("bar"), array("id"));
     return $schema;
 }
 /**
  * @group DDC-1657
  */
 public function testAutoIncremenetSequences()
 {
     $oldSchema = new Schema();
     $table = $oldSchema->createTable("foo");
     $table->addColumn("id", "integer", array("autoincrement" => true));
     $table->setPrimaryKey(array("id"));
     $oldSchema->createSequence("foo_id_seq");
     $newSchema = new Schema();
     $table = $newSchema->createTable("foo");
     $table->addColumn("id", "integer", array("autoincrement" => true));
     $table->setPrimaryKey(array("id"));
     $c = new Comparator();
     $diff = $c->compare($oldSchema, $newSchema);
     $this->assertCount(0, $diff->removedSequences);
 }
Пример #3
0
 /**
  * @group DBAL-669
  */
 public function testVisitsNamespaceVisitor()
 {
     $schema = new Schema();
     $visitor = $this->getMock('Doctrine\\DBAL\\Schema\\Visitor\\AbstractVisitor');
     $schema->createNamespace('foo');
     $schema->createNamespace('bar');
     $schema->createTable('baz');
     $schema->createTable('bla.bloo');
     $schema->createSequence('moo');
     $schema->createSequence('war');
     $visitor->expects($this->once())->method('acceptSchema')->with($schema);
     $visitor->expects($this->at(1))->method('acceptNamespace')->with('foo');
     $visitor->expects($this->at(2))->method('acceptNamespace')->with('bar');
     $visitor->expects($this->at(3))->method('acceptNamespace')->with('bla');
     $visitor->expects($this->exactly(3))->method('acceptNamespace');
     $visitor->expects($this->at(4))->method('acceptTable')->with($schema->getTable('baz'));
     $visitor->expects($this->at(5))->method('acceptTable')->with($schema->getTable('bla.bloo'));
     $visitor->expects($this->exactly(2))->method('acceptTable');
     $visitor->expects($this->at(6))->method('acceptSequence')->with($schema->getSequence('moo'));
     $visitor->expects($this->at(7))->method('acceptSequence')->with($schema->getSequence('war'));
     $visitor->expects($this->exactly(2))->method('acceptSequence');
     $this->assertNull($schema->visit($visitor));
 }
 /**
  * @group DBAL-112
  */
 public function testChangedSequence()
 {
     $schema = new Schema();
     $sequence = $schema->createSequence('baz');
     $schemaNew = clone $schema;
     /* @var $schemaNew Schema */
     $schemaNew->getSequence('baz')->setAllocationSize(20);
     $c = new \Doctrine\DBAL\Schema\Comparator();
     $diff = $c->compare($schema, $schemaNew);
     $this->assertSame($diff->changedSequences[0], $schemaNew->getSequence('baz'));
 }
 public function testSequencesCaseInsenstive()
 {
     $schemaA = new Schema();
     $schemaA->createSequence('foo');
     $schemaA->createSequence('BAR');
     $schemaA->createSequence('Baz');
     $schemaA->createSequence('new');
     $schemaB = new Schema();
     $schemaB->createSequence('FOO');
     $schemaB->createSequence('Bar');
     $schemaB->createSequence('baz');
     $schemaB->createSequence('old');
     $c = new Comparator();
     $diff = $c->compare($schemaA, $schemaB);
     $this->assertSchemaSequenceChangeCount($diff, 1, 0, 1);
 }
 /**
  * plg_send_history_send_id_seqの作成
  * @param Schema $schema
  */
 protected function createPlgplgSendHistorySendIdSeq(Schema $schema)
 {
     $seq = $schema->createSequence("plg_send_history_send_id_seq");
 }
Пример #7
0
 public function testDeepClone()
 {
     $schema = new Schema();
     $sequence = $schema->createSequence('baz');
     $tableA = $schema->createTable('foo');
     $tableA->addColumn('id', 'integer');
     $tableB = $schema->createTable('bar');
     $tableB->addColumn('id', 'integer');
     $tableB->addColumn('foo_id', 'integer');
     $tableB->addForeignKeyConstraint($tableA, array('foo_id'), array('id'));
     $schemaNew = clone $schema;
     $this->assertNotSame($sequence, $schemaNew->getSequence('baz'));
     $this->assertNotSame($tableA, $schemaNew->getTable('foo'));
     $this->assertNotSame($tableA->getColumn('id'), $schemaNew->getTable('foo')->getColumn('id'));
     $this->assertNotSame($tableB, $schemaNew->getTable('bar'));
     $this->assertNotSame($tableB->getColumn('id'), $schemaNew->getTable('bar')->getColumn('id'));
     $fk = $schemaNew->getTable('bar')->getForeignKeys();
     $fk = current($fk);
     $this->assertSame($schemaNew->getTable('bar'), $this->readAttribute($fk, '_localTable'));
 }
Пример #8
0
 protected function _handlePrimaryKey(Schema $schema, $tableName, $sequenceName = null)
 {
     $columnOptions = array();
     if ($this->conn->getDatabasePlatform()->prefersIdentityColumns()) {
         $columnOptions = array('autoincrement' => true);
     } elseif ($this->conn->getDatabasePlatform()->prefersSequences()) {
         $sequence = $schema->createSequence($sequenceName);
         // Doens't work because of the ordering used by Doctrine in dropping tables.
         //$columnOptions = array( 'default' => "nextval('" . $sequenceName . "')" );
     }
     return $columnOptions;
 }