Skip to content

Commit

Permalink
Added composite keys
Browse files Browse the repository at this point in the history
  • Loading branch information
c006 committed Dec 9, 2015
1 parent a65a341 commit 1cbbb1c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
14 changes: 7 additions & 7 deletions assets/AppUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
class AppUtility
{

public $string = '';
public $string = '';

private $Tab = "\t";
private $Tab = "\t";

private $Nw = "\n";
private $Nw = "\n";

private $array = [];
private $array = [];

private $dbType = '';

Expand Down Expand Up @@ -53,11 +53,11 @@ private function objectToArray($array_in)
if (is_array($array_in)) {
foreach ($array_in as $key => $value) {
if (is_object($value)) {
$array[$key] = self::objectToArray($value);
$array[ $key ] = self::objectToArray($value);
} elseif (is_array($value)) {
$array[$key] = self::objectToArray($value);
$array[ $key ] = self::objectToArray($value);
} else {
$array[$key] = $value;
$array[ $key ] = $value;
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions assets/c006-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

jQuery(function () {
jQuery('#migrationutility-databasetables').bind('change',
function () {
var val = jQuery(this).find('option:selected').text();
if (val) {
var $elm = jQuery('#migrationutility-tables');
var val2 = $elm.val().replace(val + ',', '');
val = val2 + ',' + val;
val = val.replace(/,+/gi, ',').replace(/\s+/gi, '').replace(/^,/, '');
$elm.val(val);
}
});
function () {
var val = jQuery(this).find('option:selected').text();
if (val) {
var $elm = jQuery('#migrationutility-tables');
var val2 = $elm.val().replace(val + ',', '');
val = val2 + ',' + val;
val = val.replace(/,+/gi, ',').replace(/\s+/gi, '').replace(/^,/, '');
$elm.val(val);
}
});
});
16 changes: 8 additions & 8 deletions controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use c006\utility\migration\assets\AppUtility;
use c006\utility\migration\models\MigrationUtility;
use Yii;
use yii\base\Object;
use yii\web\Controller;

/**
* Class DefaultController
Expand Down Expand Up @@ -68,8 +66,8 @@ public function actionIndex()
if (empty($table)) {
continue;
}
$columns = \Yii::$app->db->getTableSchema($table);
$prefix = \Yii::$app->db->tablePrefix;
$columns = Yii::$app->db->getTableSchema($table);
$prefix = Yii::$app->db->tablePrefix;
$table_prepared = str_replace($prefix, '', $table);
$output->tabLevel = $initialTabLevel;
foreach ($tableOptions as $dbType => $item) {
Expand All @@ -87,14 +85,17 @@ public function actionIndex()
$output->tabLevel++;
// Ordinary columns
$k = 0;
$pk = false;
foreach ($columns->columns as $column) {
$appUtility = new AppUtility($column, $dbType);
$output->addStr($appUtility->string . "',");
if ($column->isPrimaryKey) {
if ($column->isPrimaryKey && !$pk) {
$output->addStr($k . " => 'PRIMARY KEY (`" . $column->name . "`)',");
$pk = true;
} elseif ($column->isPrimaryKey && $pk) {
$output->addStr($k . " => 'KEY (`" . $column->name . "`)',");
}
$k++;

}

$output->tabLevel--;
Expand All @@ -118,7 +119,6 @@ public function actionIndex()
$str .= '\'' . $foreignKeyOnUpdate . '\' ';
$str .= ');';
$array['fk'][] = $str;

}
}
}
Expand Down Expand Up @@ -267,7 +267,7 @@ protected function mysql_direct($table)
*/
public function getTables()
{
return \Yii::$app->db->getSchema()->getTableNames('', TRUE);
return Yii::$app->db->getSchema()->getTableNames('', TRUE);
}

}
Expand Down

0 comments on commit 1cbbb1c

Please sign in to comment.