2016-01-03 03:18:37 +03:00
|
|
|
<?php
|
|
|
|
namespace console\db;
|
|
|
|
|
|
|
|
use yii\db\Migration as YiiMigration;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property string $tableOptions
|
|
|
|
*/
|
|
|
|
class Migration extends YiiMigration {
|
|
|
|
|
|
|
|
public function getTableOptions($engine = 'InnoDB') {
|
|
|
|
$tableOptions = null;
|
|
|
|
if ($this->db->driverName === 'mysql') {
|
2017-12-23 00:32:36 +03:00
|
|
|
$tableOptions = 'CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE=' . $engine;
|
2016-01-03 03:18:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return $tableOptions;
|
|
|
|
}
|
|
|
|
|
2016-08-21 01:24:23 +03:00
|
|
|
public function createTable($table, $columns, $options = null) {
|
|
|
|
if ($options === null) {
|
|
|
|
$options = $this->getTableOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::createTable($table, $columns, $options);
|
|
|
|
}
|
|
|
|
|
2018-07-07 15:01:18 +03:00
|
|
|
protected function primary(string ...$columns): string {
|
|
|
|
foreach ($columns as &$column) {
|
|
|
|
$column = $this->db->quoteColumnName($column);
|
2016-02-14 20:50:10 +03:00
|
|
|
}
|
|
|
|
|
2018-07-07 15:01:18 +03:00
|
|
|
return ' PRIMARY KEY (' . implode(', ', $columns) . ') ';
|
2016-02-14 20:50:10 +03:00
|
|
|
}
|
|
|
|
|
2016-01-03 03:18:37 +03:00
|
|
|
}
|