protected function addColumn(Table $table, $name) { if (!$table->hasColumn($name)) { $column = new Column($name); // don't know how to define unsigned :( $domain = new Domain('TINYINT', 'tinyint(3) unsigned'); $column->setDomain($domain); $table->addColumn($column); $column_idx_name = $name . '_idx'; if (!$table->hasIndex($column_idx_name)) { $column_idx = new Index($column_idx_name); $column_idx->addColumn(['name' => $column->getName()]); $table->addIndex($column_idx); } } }
public function testCantGetColumn() { $table = new Table('books'); $this->assertFalse($table->hasColumn('FOO', true)); $this->assertNull($table->getColumn('FOO')); $this->assertNull($table->getColumnByPhpName('Foo')); }
/** * Adds Indexes to the specified table. * * @param Table $table The Table model class to add columns to. */ protected function addIndexes(Table $table) { $stmt = $this->dbh->query("SELECT COLUMN_NAME, INDEX_NAME FROM USER_IND_COLUMNS WHERE TABLE_NAME = '" . $table->getName() . "' ORDER BY COLUMN_NAME"); $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC); $indices = array(); foreach ($rows as $row) { $indices[$row['INDEX_NAME']][] = $row['COLUMN_NAME']; } foreach ($indices as $indexName => $columnNames) { $index = new Index($indexName); foreach ($columnNames as $columnName) { // Oracle deals with complex indices using an internal reference, so... // let's ignore this kind of index if ($table->hasColumn($columnName)) { $index->addColumn($table->getColumn($columnName)); } } // since some of the columns are pruned above, we must only add an index if it has columns if ($index->hasColumns()) { $table->addIndex($index); } } }
protected function addLogColumns(Table $table) { if ('true' === $this->getParameter('created_at') && !$table->hasColumn($this->getParameter('created_at_column'))) { $table->addColumn(array('name' => $this->getParameter('created_at_column'), 'type' => 'TIMESTAMP')); } if ('true' === $this->getParameter('created_by') && !$table->hasColumn($this->getParameter('created_by_column'))) { $table->addColumn(array('name' => $this->getParameter('created_by_column'), 'type' => 'VARCHAR', 'size' => 100)); } if ('true' === $this->getParameter('comment') && !$table->hasColumn($this->getParameter('comment_column'))) { $table->addColumn(array('name' => $this->getParameter('comment_column'), 'type' => 'VARCHAR', 'size' => 255)); } }