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 testMoreColumns()
 {
     $table = new Table('more_columns');
     $table->addPrimary(true);
     $table->setCharset('utf8');
     $table->setCollation('utf8_general_ci');
     $this->assertInstanceOf('\\Phoenix\\Database\\Element\\Table', $table->addColumn(new Column('title', 'string', ['charset' => 'utf16'])));
     $this->assertInstanceOf('\\Phoenix\\Database\\Element\\Table', $table->addColumn(new Column('alias', '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('bodytext', 'text', ['collation' => 'utf8_slovak_ci'])));
     $this->assertInstanceOf('\\Phoenix\\Database\\Element\\Table', $table->addColumn(new Column('price', 'decimal', ['length' => 8, 'decimals' => 2])));
     $queryBuilder = new MysqlQueryBuilder();
     $expectedQueries = ["CREATE TABLE `more_columns` (`id` int(11) NOT NULL AUTO_INCREMENT,`title` varchar(255) CHARACTER SET utf16 NOT NULL,`alias` varchar(255) DEFAULT NULL,`total` int(11) NOT NULL DEFAULT 0,`bodytext` text COLLATE utf8_slovak_ci NOT NULL,`price` decimal(8,2) NOT NULL,PRIMARY KEY (`id`)) DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci;"];
     $this->assertEquals($expectedQueries, $queryBuilder->createTable($table));
 }