Exemple #1
0
 /**
  * You can pass `autoIncrement` as an option and it will be converted
  * to the correct option for phinx to create the column with an
  * auto increment attribute
  *
  * {@inheritdoc}
  */
 public function addColumn($columnName, $type = null, $options = [])
 {
     if (isset($options['autoIncrement']) && $options['autoIncrement'] === true) {
         $options['identity'] = true;
         unset($options['autoIncrement']);
     }
     return parent::addColumn($columnName, $type, $options);
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function createSchemaTable()
 {
     try {
         $options = array('id' => false);
         $table = new \Phinx\Db\Table($this->getSchemaTableName(), $options, $this);
         $table->addColumn('version', 'biginteger', array('limit' => 14))->addColumn('start_time', 'timestamp')->addColumn('end_time', 'timestamp')->save();
     } catch (\Exception $exception) {
         throw new \InvalidArgumentException('There was a problem creating the schema table');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function createSchemaTable()
 {
     try {
         $options = array('id' => false, 'primary_key' => 'version');
         $table = new Table($this->getSchemaTableName(), $options, $this);
         if ($this->getConnection()->getAttribute(\PDO::ATTR_DRIVER_NAME) === 'mysql' && version_compare($this->getConnection()->getAttribute(\PDO::ATTR_SERVER_VERSION), '5.6.0', '>=')) {
             $table->addColumn('version', 'biginteger', array('limit' => 14))->addColumn('start_time', 'timestamp', array('default' => 'CURRENT_TIMESTAMP'))->addColumn('end_time', 'timestamp', array('default' => 'CURRENT_TIMESTAMP'))->save();
         } else {
             $table->addColumn('version', 'biginteger')->addColumn('start_time', 'timestamp')->addColumn('end_time', 'timestamp')->save();
         }
     } catch (\Exception $exception) {
         throw new \InvalidArgumentException('There was a problem creating the schema table: ' . $exception->getMessage());
     }
 }
 public function testAddTableWithForeignKey()
 {
     $this->mock->expects($this->any())->method('isValidColumnType')->with($this->callback(function ($column) {
         return in_array($column->getType(), array('string', 'integer'));
     }))->will($this->returnValue(true));
     $table = new Table('table', array(), $this->adapter);
     $table->addColumn('bar', 'string')->addColumn('relation', 'integer')->addForeignKey('relation', 'target_table', array('id'));
     $this->mock->expects($this->once())->method('createTable')->with($this->callback(function ($table) {
         if ($table->getName() !== 'pre_table_suf') {
             throw new \Exception(sprintf('Table::getName was not prefixed/suffixed properly: "%s"', $table->getName()));
         }
         $fks = $table->getForeignKeys();
         if (count($fks) !== 1) {
             throw new \Exception(sprintf('Table::getForeignKeys count was incorrect: %d', count($fks)));
         }
         foreach ($fks as $fk) {
             if ($fk->getReferencedTable()->getName() !== 'pre_target_table_suf') {
                 throw new \Exception(sprintf('ForeignKey::getReferencedTable was not prefixed/suffixed properly: "%s"', $fk->getReferencedTable->getName()));
             }
         }
         return true;
     }));
     $table->create();
 }
 /**
  * Add a table column.
  *
  * Type can be: string, text, integer, float, decimal, datetime, timestamp,
  * time, date, binary, boolean.
  *
  * Valid options can be: limit, default, null, precision or scale.
  *
  * @param string $columnName
  * @param null   $type
  * @param array  $options
  *
  * @return $this
  */
 public function addColumn($columnName, $type = null, $options = [])
 {
     $this->table->addColumn($columnName, $type, $options);
     return $this;
 }