Example #1
0
 /**
  * @param string $name
  * @param mixed $primaryKey available only for create table
  * true - if you want classic autoincrement integer primary column with name id
  * Column - if you want to define your own column (column is added to list of columns)
  * string - name of column in list of columns
  * array of strings - names of columns in list of columns
  * array of Column - list of own columns (all columns are added to list of columns)
  * other (false, null) - if your table doesn't have primary key
  * @return AbstractMigration
  * @throws IncorrectMethodUsageException
  */
 protected final function table($name, $primaryKey = true, $charset = null, $collation = null)
 {
     if ($this->table !== null) {
         throw new IncorrectMethodUsageException('Wrong use of method table(). Use one of methods create(), drop(), save() first.');
     }
     $this->primaryKey = $primaryKey;
     $this->table = new Table($name);
     $this->table->setCharset($charset ?: $this->adapter->getCharset());
     $this->table->setCollation($collation);
     return $this;
 }
Example #2
0
 public function testNoPrimaryKey()
 {
     $table = new Table('no_primary_key');
     $table->setCharset('utf16');
     $this->assertInstanceOf('\\Phoenix\\Database\\Element\\Table', $table->addColumn(new Column('title', 'string', ['null' => true])));
     $this->assertInstanceOf('\\Phoenix\\Database\\Element\\Table', $table->addColumn(new Column('total', 'integer', ['default' => 0])));
     $this->assertInstanceOf('\\Phoenix\\Database\\Element\\Table', $table->addColumn(new Column('is_deleted', 'boolean', ['default' => false])));
     $queryBuilder = new MysqlQueryBuilder();
     $expectedQueries = ["CREATE TABLE `no_primary_key` (`title` varchar(255) DEFAULT NULL,`total` int(11) NOT NULL DEFAULT 0,`is_deleted` tinyint(1) NOT NULL DEFAULT 0) DEFAULT CHARACTER SET=utf16;"];
     $this->assertEquals($expectedQueries, $queryBuilder->createTable($table));
 }