Dumplie\Metadata\Infrastructure\Doctrine\Dbal\DoctrineStorage::create PHP Method

create() public method

public create ( Schema $schema )
$schema Dumplie\Metadata\Schema
    public function create(Schema $schema)
    {
        $currentDbSchema = $this->connection->getSchemaManager()->createSchema();
        $dbSchema = new DBALSchema($currentDbSchema->getTables(), $currentDbSchema->getSequences(), $this->connection->getSchemaManager()->createSchemaConfig());
        foreach ($schema->types() as $type) {
            $tableName = $this->tableName($schema->name(), $type->name());
            if ($dbSchema->hasTable($tableName)) {
                throw DoctrineStorageException::tableAlreadyExists($tableName);
            }
            $this->createTable($dbSchema, $schema->name(), $type);
        }
        $queries = $dbSchema->toSql($this->connection->getDatabasePlatform());
        $this->executeQueries($queries);
    }

Usage Example

示例#1
0
 public function test_delete()
 {
     $uuid = (string) Uuid::uuid4();
     $this->storage->create($this->schema);
     $this->storage->save('test', 'foo', $uuid, ['text' => 'value']);
     $this->storage->delete('test', 'foo', $uuid);
     $this->assertFalse($this->storage->has('test', 'foo', $uuid));
 }