예제 #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
 public function testIfIsNotMultiPrimaryKey()
 {
     $primaryKey = new PrimaryKey(array('foo'));
     $this->assertFalse($primaryKey->isMulti());
 }
예제 #4
0
 /**
  * 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);
 }