コード例 #1
0
 /**
  * Gets columns query.
  *
  * @return string
  */
 private function getColumnsSql()
 {
     $columnTypeMapper = new ColumnTypeMapper();
     foreach ($this->table->getConstraints() as $constraint) {
         if ($constraint instanceof PrimaryKey) {
             $primaryKey = $constraint;
         }
     }
     if (!isset($primaryKey)) {
         // TODO find better solution
         $primaryKey = new PrimaryKey();
         $primaryKey->setTable($this->table);
         $this->table->addConstraint($primaryKey);
     }
     $sql = '';
     if (!$primaryKey->isMulti() && $primaryKey->isAutoCreateColumn()) {
         $sql = sprintf('%s %s NOT NULL,', $primaryKey->getColumns(), $primaryKey->isAutoIncrement() ? 'serial' : 'integer');
     }
     foreach ($this->table->getColumns() as $column) {
         if ($column instanceof CustomColumn) {
             $columnType = $column->getType();
         } else {
             $columnType = $columnTypeMapper->getNative($column->getType());
         }
         $sql .= sprintf('%s %s%s %s %s,', $column->getName(), $columnType, $this->getTypeConstraints($column), $column->isNotNull() ? 'NOT NULL' : '', null === $column->getDefault() ? '' : 'DEFAULT' . ' ' . $this->addQuotesIfNeeded($column, $column->getDefault()));
     }
     return rtrim($sql, ',');
 }
コード例 #2
0
 public function testCreateTableWithNotAutoIncrementPrimaryKey()
 {
     $primaryKey = new PrimaryKey();
     $primaryKey->disableAutoIncrement();
     $table = new Table('foo');
     $table->addConstraint($primaryKey);
     $this->getCreateTableCommand()->setTable($table)->execute();
     $getTableCommand = new GetTableCommand();
     $getTableCommand->setConnection($this->connection);
     $getTableCommand->setTableName('foo');
     $tableInfo = $getTableCommand->execute();
     $this->assertEquals('integer', $tableInfo->getColumn('foo_id')->getType());
 }
コード例 #3
0
ファイル: PrimaryKeyTest.php プロジェクト: czogori/rentgen
 public function testIfIsNotMultiPrimaryKey()
 {
     $primaryKey = new PrimaryKey(array('foo'));
     $this->assertFalse($primaryKey->isMulti());
 }
コード例 #4
0
ファイル: SchemaTable.php プロジェクト: czogori/dami
 /**
  * Create schema table if not exists.
  *
  * @return void
  */
 private function createIfNotExists()
 {
     $table = new Table('schema_migration');
     if ($this->info->isTableExists($table)) {
         return;
     }
     $primaryKey = new PrimaryKey(array('version'));
     $primaryKey->disableAutoIncrement();
     $table->addConstraint($primaryKey);
     $table->addColumn(new BigIntegerColumn('version'))->addColumn(new DateTimeColumn('created_at', array('nullable' => false, 'default' => 'now()')));
     $this->manipulation->create($table);
 }