protected function getTestTable($name, $options=array()) { $table = new \Doctrine\DBAL\Schema\Table($name, array(), array(), array(), false, $options); $table->setSchemaConfig($this->_sm->createSchemaConfig()); $table->addColumn('id', 'integer', array('notnull' => true)); $table->setPrimaryKey(array('id')); $table->addColumn('test', 'string', array('length' => 255)); $table->addColumn('foreign_key_test', 'integer'); return $table; }
protected function getTestCompositeTable($name) { $table = new Table($name, array(), array(), array(), false, array()); $table->setSchemaConfig($this->_sm->createSchemaConfig()); $table->addColumn('id', 'integer', array('notnull' => true)); $table->addColumn('other_id', 'integer', array('notnull' => true)); $table->setPrimaryKey(array('id', 'other_id')); $table->addColumn('test', 'string', array('length' => 255)); return $table; }
/** * Executes the changes. */ public function executeChanges() { $platform = $this->db->getDatabasePlatform(); if (!empty($this->dropTables)) { foreach ($this->dropTables as $t) { $this->sm->dropTable($this->prefix . $t); } } $sql = $this->schema->toSql($platform); if (!empty($sql)) { foreach ($sql as $s) { $this->db->executeUpdate($s); } } //reset schema $this->schema = new Schema([], [], $this->sm->createSchemaConfig()); $this->dropTables = $this->addTables = []; }
/** * Create schema instance from metadata * * @param array $metadata * @return \Doctrine\DBAL\Schema\Schema */ public function getSchemaFromMetadata(array $metadata) { $entityMetadataSchemaConfig = $this->schemaManager->createSchemaConfig(); $schema = new Schema([], [], $entityMetadataSchemaConfig); $pivotTables = []; foreach ($metadata as $entityMetadata) { $this->generateTableFromMetadata($schema, $entityMetadata['table']); // create version table if (!empty($entityMetadata['versionTable'])) { $this->generateTableFromMetadata($schema, $entityMetadata['versionTable']); } foreach ($entityMetadata['relations'] as $relationMetadata) { if (!empty($relationMetadata['pivotTable'])) { // create pivot table for many to many relations if (!in_array($relationMetadata['pivotTable']['name'], $pivotTables)) { $this->generateTableFromMetadata($schema, $relationMetadata['pivotTable']); } $pivotTables[] = $relationMetadata['pivotTable']['name']; } } } return $schema; }