Example #1
0
 /**
  * @return Schema
  */
 public function build() : Schema
 {
     $schema = new Schema($this->name);
     foreach ($this->types as $type) {
         $schema->add($type);
     }
     return $schema;
 }
Example #2
0
 public function test_alter_existing_table()
 {
     $foo = new TypeSchema('foo', ['id' => new TextField(), 'foo' => new TextField()]);
     $fooSchema = new Schema('test');
     $fooSchema->add($foo);
     $bar = new TypeSchema('foo', ['id' => new TextField(), 'bar' => new TextField()]);
     $barSchema = new Schema('test');
     $barSchema->add($bar);
     $this->storage->create($fooSchema);
     $this->storage->alter($barSchema);
     $result = $this->connection->getSchemaManager()->listTableColumns('metadata_test_foo');
     $this->assertArrayHasKey('bar', $result);
 }
Example #3
0
 /**
  * @param Schema $schema
  * @return ChangeSet
  */
 public function diff(Schema $schema) : ChangeSet
 {
     $currentSchema = $this->connection->getSchemaManager()->createSchema();
     $targetSchema = clone $currentSchema;
     foreach ($schema->types() as $type) {
         $tableName = $this->tableName($schema->name(), $type->name());
         if ($targetSchema->hasTable($tableName)) {
             $targetSchema->dropTable($tableName);
         }
         $this->createTable($targetSchema, $schema->name(), $type);
     }
     $queries = $currentSchema->getMigrateToSql($targetSchema, $this->connection->getDatabasePlatform());
     return new ChangeSet($queries);
 }