Skip to content
Permalink
Browse files

Use constants where possible.

Remove duplicated primary key reflection. Primary keys are now reflected
separately.
  • Loading branch information...
markstory committed Jun 2, 2013
1 parent 2a58e16 commit 024fb658fb26bc8f253d6142d3aebbf1450beda6
@@ -148,12 +148,6 @@ public function convertFieldDescription(Table $table, $row) {
'comment' => $row['Comment'],
];
$table->addColumn($row['Field'], $field);
if (!empty($row['Key']) && $row['Key'] === 'PRI') {
$table->addConstraint('primary', [
'type' => Table::CONSTRAINT_PRIMARY,
'columns' => [$row['Field']]
]);
}
}
/**
@@ -170,25 +164,25 @@ public function convertIndexDescription(Table $table, $row) {
$name = $row['Key_name'];
if ($name === 'PRIMARY') {
$name = $type = 'primary';
$name = $type = Table::CONSTRAINT_PRIMARY;
}
$columns[] = $row['Column_name'];
if ($row['Index_type'] === 'FULLTEXT') {
$type = strtolower($row['Index_type']);
$type = Table::INDEX_FULLTEXT;
} elseif ($row['Non_unique'] == 0 && $type !== 'primary') {
$type = 'unique';
$type = Table::CONSTRAINT_UNIQUE;
} elseif ($type !== 'primary') {
$type = 'index';
$type = Table::INDEX_INDEX;
}
if (!empty($row['Sub_part'])) {
$length[$row['Column_name']] = $row['Sub_part'];
}
$isIndex = (
$type == 'index' ||
$type == 'fulltext'
$type == Table::INDEX_INDEX ||
$type == Table::INDEX_FULLTEXT
);
if ($isIndex) {
$existing = $table->index($name);
@@ -199,7 +193,7 @@ public function convertIndexDescription(Table $table, $row) {
// MySQL multi column indexes come back
// as multiple rows.
if (!empty($existing)) {
$columns = array_unique(array_merge($existing['columns'], $columns));
$columns = array_merge($existing['columns'], $columns);
$length = array_merge($existing['length'], $length);
}
if ($isIndex) {
@@ -171,12 +171,6 @@ public function convertFieldDescription(Table $table, $row) {
];
$field['length'] = $row['char_length'] ?: $field['length'];
$table->addColumn($row['name'], $field);
if (!empty($row['pk'])) {
$table->addConstraint('primary', [
'type' => Table::CONSTRAINT_PRIMARY,
'columns' => [$row['name']]
]);
}
}
/**
@@ -178,12 +178,12 @@ public function convertIndexDescription(Table $table, $row) {
}
if ($row['unique']) {
$table->addConstraint($row['name'], [
'type' => 'unique',
'type' => Table::CONSTRAINT_UNIQUE,
'columns' => $columns
]);
} else {
$table->addIndex($row['name'], [
'type' => 'index',
'type' => Table::INDEX_INDEX,
'columns' => $columns
]);
}

0 comments on commit 024fb65

Please sign in to comment.
You can’t perform that action at this time.