protected function _getPortableTableIndexesList($tableIndexes, $tableName = null) { $indexes = array(); foreach ($tableIndexes as $k) { $k['primary'] = (bool) $k['primary']; $indexes[] = $k; } return parent::_getPortableTableIndexesList($indexes, $tableName); }
private function reverseEngineerMappingFromDatabase() { if ($this->tables !== null) { return; } $tables = array(); foreach ($this->_sm->listTableNames() as $tableName) { $tables[$tableName] = $this->_sm->listTableDetails($tableName); } $this->tables = $this->manyToManyTables = $this->classToTableNames = array(); foreach ($tables as $tableName => $table) { /* @var $table \Doctrine\DBAL\Schema\Table */ if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) { $foreignKeys = $table->getForeignKeys(); } else { $foreignKeys = array(); } $allForeignKeyColumns = array(); foreach ($foreignKeys as $foreignKey) { $allForeignKeyColumns = array_merge($allForeignKeyColumns, $foreignKey->getLocalColumns()); } //trecho alterado apenas para o gerador if ($table->getPrimaryKey()) { $pkColumns = $table->getPrimaryKey()->getColumns(); } else { $pkColumns = array(); } sort($pkColumns); sort($allForeignKeyColumns); if ($pkColumns == $allForeignKeyColumns && count($foreignKeys) == 2) { $this->manyToManyTables[$tableName] = $table; } else { // lower-casing is necessary because of Oracle Uppercase Tablenames, // assumption is lower-case + underscore separated. $className = $this->getClassNameForTable($tableName); $this->tables[$tableName] = $table; $this->classToTableNames[$className] = $tableName; } } }
protected function _getPortableTableIndexesList($tableIndexes, $tableName = null) { foreach ($tableIndexes as $k => $v) { $v = array_change_key_case($v, CASE_LOWER); if ($v['key_name'] == 'PRIMARY') { $v['primary'] = true; } else { $v['primary'] = false; } $tableIndexes[$k] = $v; } return parent::_getPortableTableIndexesList($tableIndexes, $tableName); }
/** * {@inheritdoc} */ protected function _getPortableTableForeignKeysList($tableForeignKeys) { $foreignKeys = array(); foreach ($tableForeignKeys as $tableForeignKey) { $tableForeignKey = array_change_key_case($tableForeignKey, \CASE_LOWER); if (!isset($foreignKeys[$tableForeignKey['index_name']])) { $foreignKeys[$tableForeignKey['index_name']] = array('local_columns' => array($tableForeignKey['local_column']), 'foreign_table' => $tableForeignKey['foreign_table'], 'foreign_columns' => array($tableForeignKey['foreign_column']), 'name' => $tableForeignKey['index_name'], 'options' => array('onUpdate' => $tableForeignKey['on_update'], 'onDelete' => $tableForeignKey['on_delete'])); } else { $foreignKeys[$tableForeignKey['index_name']]['local_columns'][] = $tableForeignKey['local_column']; $foreignKeys[$tableForeignKey['index_name']]['foreign_columns'][] = $tableForeignKey['foreign_column']; } } return parent::_getPortableTableForeignKeysList($foreignKeys); }
/** * @license New BSD License * @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html * @param array $tableIndexes * @param string $tableName * @return array */ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null) { $buffer = array(); foreach ($tableIndexes as $row) { $colNumbers = explode(' ', $row['indkey']); $colNumbersSql = 'IN (' . join(' ,', $colNumbers) . ' )'; $columnNameSql = "SELECT attnum, attname FROM pg_attribute\n WHERE attrelid={$row['indrelid']} AND attnum {$colNumbersSql} ORDER BY attnum ASC;"; $stmt = $this->_conn->executeQuery($columnNameSql); $indexColumns = $stmt->fetchAll(); // required for getting the order of the columns right. foreach ($colNumbers as $colNum) { foreach ($indexColumns as $colRow) { if ($colNum == $colRow['attnum']) { $buffer[] = array('key_name' => $row['relname'], 'column_name' => trim($colRow['attname']), 'non_unique' => !$row['indisunique'], 'primary' => $row['indisprimary']); } } } } return parent::_getPortableTableIndexesList($buffer, $tableName); }
/** * @license New BSD License * @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html * @param array $tableIndexes * @param string $tableName * @return array */ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null) { $indexBuffer = array(); // fetch primary $stmt = $this->_conn->executeQuery("PRAGMA TABLE_INFO ('{$tableName}')"); $indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC); foreach ($indexArray as $indexColumnRow) { if ($indexColumnRow['pk'] == "1") { $indexBuffer[] = array('key_name' => 'primary', 'primary' => true, 'non_unique' => false, 'column_name' => $indexColumnRow['name']); } } // fetch regular indexes foreach ($tableIndexes as $tableIndex) { // Ignore indexes with reserved names, e.g. autoindexes if (strpos($tableIndex['name'], 'sqlite_') !== 0) { $keyName = $tableIndex['name']; $idx = array(); $idx['key_name'] = $keyName; $idx['primary'] = false; $idx['non_unique'] = $tableIndex['unique'] ? false : true; $stmt = $this->_conn->executeQuery("PRAGMA INDEX_INFO ( '{$keyName}' )"); $indexArray = $stmt->fetchAll(\PDO::FETCH_ASSOC); foreach ($indexArray as $indexColumnRow) { $idx['column_name'] = $indexColumnRow['name']; $indexBuffer[] = $idx; } } } return parent::_getPortableTableIndexesList($indexBuffer, $tableName); }
public function dropTable($name) { $this->dropAutoincrement($name); return parent::dropTable($name); }
/** * @license New BSD License * @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html * @param array $tableIndexes * @param string $tableName * @return array */ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null) { $indexBuffer = array(); // fetch primary $stmt = $this->_conn->execute("PRAGMA TABLE_INFO ('{$tableName}')"); $indexArray = $stmt->fetchAll(\Doctrine\DBAL\Connection::FETCH_ASSOC); foreach ($indexArray as $indexColumnRow) { if ($indexColumnRow['pk'] == "1") { $indexBuffer[] = array('key_name' => 'primary', 'primary' => true, 'non_unique' => false, 'column_name' => $indexColumnRow['name']); } } // fetch regular indexes foreach ($tableIndexes as $tableIndex) { $keyName = $tableIndex['name']; $idx = array(); $idx['key_name'] = $keyName; $idx['primary'] = false; $idx['non_unique'] = $tableIndex['unique'] ? false : true; $stmt = $this->_conn->execute("PRAGMA INDEX_INFO ( '{$keyName}' )"); $indexArray = $stmt->fetchAll(\Doctrine\DBAL\Connection::FETCH_ASSOC); foreach ($indexArray as $indexColumnRow) { $idx['column_name'] = $indexColumnRow['name']; $indexBuffer[] = $idx; } } return parent::_getPortableTableIndexesList($indexBuffer, $tableName); }
/** * drop an existing table * * @param string $name name of the table that should be dropped * @return void */ public function dropTable($name) { //$this->conn->beginNestedTransaction(); $result = $this->dropAutoincrement($name); $result = parent::dropTable($name); //$this->conn->completeNestedTransaction(); return $result; }
/** * Execute this migration version up or down and and return the SQL. * * @param string $direction The direction to execute the migration. * @param string $dryRun Whether to not actually execute the migration SQL and just do a dry run. * @return array $sql * @throws Exception when migration fails */ public function execute($direction, $dryRun = false) { $this->_sql = array(); $this->_connection->beginTransaction(); try { $start = microtime(true); $this->_state = self::STATE_PRE; $fromSchema = $this->_sm->createSchema(); $this->_migration->{'pre' . ucfirst($direction)}($fromSchema); if ($direction === 'up') { $this->_outputWriter->write("\n" . sprintf(' <info>++</info> migrating <comment>%s</comment>', $this->_version) . "\n"); } else { $this->_outputWriter->write("\n" . sprintf(' <info>--</info> reverting <comment>%s</comment>', $this->_version) . "\n"); } $this->_state = self::STATE_EXEC; $toSchema = clone $fromSchema; $this->_migration->{$direction}($toSchema); $this->addSql($fromSchema->getMigrateToSql($toSchema, $this->_platform)); if ($dryRun === false) { if ($this->_sql) { $count = count($this->_sql); foreach ($this->_sql as $query) { $this->_outputWriter->write(' <comment>-></comment> ' . $query); $this->_connection->executeQuery($query); } } else { $this->_outputWriter->write(sprintf('<error>Migration %s was executed but did not result in any SQL statements.</error>', $this->_version)); } if ($direction === 'up') { $this->markMigrated(); } else { $this->markNotMigrated(); } } else { foreach ($this->_sql as $query) { $this->_outputWriter->write(' <comment>-></comment> ' . $query); } } $this->_state = self::STATE_POST; $this->_migration->{'post' . ucfirst($direction)}($toSchema); $end = microtime(true); $this->_time = round($end - $start, 2); if ($direction === 'up') { $this->_outputWriter->write(sprintf("\n <info>++</info> migrated (%ss)", $this->_time)); } else { $this->_outputWriter->write(sprintf("\n <info>--</info> reverted (%ss)", $this->_time)); } $this->_connection->commit(); return $this->_sql; } catch (SkipMigrationException $e) { $this->_connection->rollback(); // now mark it as migrated if ($direction === 'up') { $this->markMigrated(); } else { $this->markNotMigrated(); } $this->_outputWriter->write(sprintf("\n <info>SS</info> skipped (Reason: %s)", $e->getMessage())); } catch (\Exception $e) { $this->_outputWriter->write(sprintf('<error>Migration %s failed during %s. Error %s</error>', $this->_version, $this->getExecutionState(), $e->getMessage())); $this->_connection->rollback(); $this->_state = self::STATE_NONE; throw $e; } $this->_state = self::STATE_NONE; }
/** * drop an existing table * * @param string $name name of the table that should be dropped * @return mixed MDB2_OK on success, a MDB2 error on failure * @access public */ public function dropTable($name) { $result = $this->_dropAutoincrement($name); $result = parent::dropTable($name); //$this->_silentCommit(); return $result; }
/** * {@inheritdoc} */ public function dropTable($name) { $this->tryMethod('dropAutoincrement', $name); parent::dropTable($name); }