Skip to content

Commit

Permalink
Merge 471cf31 into ba856dc
Browse files Browse the repository at this point in the history
  • Loading branch information
HavokInspiration committed Jan 31, 2016
2 parents ba856dc + 471cf31 commit ccb3c69
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Template/Bake/config/snapshot.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/

use Cake\Database\Schema\Table;

$wantedOptions = array_flip(['length', 'limit', 'default', 'unsigned', 'null', 'comment', 'autoIncrement', 'precision']);
$tableMethod = $this->Migration->tableMethod($action);
$columnMethod = $this->Migration->columnMethod($action);
Expand Down Expand Up @@ -91,7 +93,7 @@ class <%= $name %> extends AbstractMigration
$constraints[$table] = $tableConstraints;

foreach ($constraints[$table] as $name => $constraint):
if ($constraint['type'] !== 'unique'):
if ($constraint['type'] === Table::CONSTRAINT_FOREIGN):
$foreignKeys[] = $constraint['columns'];
endif;
if ($constraint['columns'] !== $primaryKeysColumns): %>
Expand All @@ -110,13 +112,13 @@ class <%= $name %> extends AbstractMigration
sort($foreignKeys);
$indexColumns = $index['columns'];
sort($indexColumns);
if (in_array($foreignKeys, $indexColumns)):
if (!in_array($indexColumns, $foreignKeys)):
%>
->addIndex(
[<%
echo $this->Migration->stringifyList($index['columns'], ['indent' => 5]);
%>]
)
->addIndex(
[<%
echo $this->Migration->stringifyList($index['columns'], ['indent' => 5]);
%>]
)
<%- endif;
endforeach; %>
-><%= $tableMethod %>();
Expand Down
6 changes: 6 additions & 0 deletions tests/Fixture/ArticlesFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class ArticlesFixture extends TestFixture
'product_id' => ['type' => 'integer', 'length' => 11],
'created' => ['type' => 'timestamp', 'null' => true, 'default' => null],
'modified' => ['type' => 'timestamp', 'null' => true, 'default' => null],
'_indexes' => [
'title_idx' => [
'type' => 'index',
'columns' => ['title']
]
],
'_constraints' => [
'primary' => ['type' => 'primary', 'columns' => ['id']],
'category_article_idx' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public function up()
'product_id',
]
)
->addIndex(
[
'title',
]
)
->create();

$table = $this->table('categories');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function up()
'product_id',
]
)
->addIndex(
[
'title',
]
)
->create();

$table = $this->table('categories');
Expand Down
5 changes: 5 additions & 0 deletions tests/comparisons/Migration/pgsql/test_plugin_blog_pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function up()
'product_id',
]
)
->addIndex(
[
'title',
]
)
->create();

$this->table('articles')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public function up()
'product_id',
]
)
->addIndex(
[
'title',
]
)
->create();

$table = $this->table('categories');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public function up()
'product_id',
]
)
->addIndex(
[
'title',
]
)
->create();

$table = $this->table('categories');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public function up()
'product_id',
]
)
->addIndex(
[
'title',
]
)
->create();

$this->table('articles')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public function up()
'product_id',
]
)
->addIndex(
[
'title',
]
)
->create();

$table = $this->table('categories');
Expand Down
5 changes: 5 additions & 0 deletions tests/comparisons/Migration/test_not_empty_snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function up()
'product_id',
]
)
->addIndex(
[
'title',
]
)
->create();

$table = $this->table('categories');
Expand Down
5 changes: 5 additions & 0 deletions tests/comparisons/Migration/test_plugin_blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function up()
'product_id',
]
)
->addIndex(
[
'title',
]
)
->create();

$this->table('articles')
Expand Down

0 comments on commit ccb3c69

Please sign in to comment.