/** * @param string $schema * @param Table $table * @param string $name * @param FieldDefinition $definition * * @throws DoctrineStorageException */ public function map(string $schema, Table $table, string $name, FieldDefinition $definition) { if (!$definition instanceof AssociationFieldDefinition) { throw DoctrineStorageException::invalidDefinition(AssociationFieldDefinition::class, $definition); } $table->addColumn($name, 'guid', ['notnull' => !$definition->isNullable(), 'default' => $definition->defaultValue(), 'length' => $definition->options()['length'] ?? null, 'unique' => $definition->options()['unique'] ?? false]); $table->addForeignKeyConstraint($this->tableName($schema, $definition->typeSchema()->name()), [$name], ['id']); }
/** * @param string $schema * @param Table $table * @param string $name * @param FieldDefinition $definition * * @throws DoctrineStorageException */ public function map(string $schema, Table $table, string $name, FieldDefinition $definition) { foreach ($this->mapping as $mapping) { if ($mapping->maps($definition->type())) { $mapping->map($schema, $table, $name, $definition); return; } } throw DoctrineStorageException::unableToMapType($definition->type()); }
/** * @param Schema $schema * * @throws DoctrineStorageException */ 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); }