Skip to content

Commit

Permalink
Added 'indices' option to VersionableBehavior
Browse files Browse the repository at this point in the history
  • Loading branch information
marcj committed Apr 28, 2015
1 parent e6e18a2 commit 8b32cd2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Expand Up @@ -29,7 +29,8 @@ class VersionableBehavior extends Behavior
'log_comment' => 'false',
'version_created_at_column' => 'version_created_at',
'version_created_by_column' => 'version_created_by',
'version_comment_column' => 'version_comment'
'version_comment_column' => 'version_comment',
'indices' => 'false'
);

protected $versionTable;
Expand Down Expand Up @@ -146,6 +147,13 @@ protected function addVersionTable()
}
$versionTable->addForeignKey($fk);

if ('true' === $this->getParameter('indices')) {
foreach ($table->getIndices() as $index) {
$index = clone $index;
$versionTable->addIndex($index);
}
}

// add the version column to the primary key
$versionColumn = $versionTable->getColumn($this->getParameter('version_column'));
$versionColumn->setNotNull(true);
Expand Down
Expand Up @@ -470,6 +470,41 @@ public function testDatabaseLevelBehavior()
$this->assertContains($expected, $builder->getSQL());
}

public function testIndicesParameter()
{
$schema = <<<EOF
<database name="versionable_behavior_test_0">
<table name="versionable_behavior_test_0">
<column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
<column name="bar" type="INTEGER" />
<index>
<index-column name="bar"/>
</index>
<behavior name="versionable">
<parameter name="indices" value="true" />
</behavior>
</table>
</database>
EOF;
$expected = <<<EOF
CREATE TABLE versionable_behavior_test_0_version
(
id INTEGER NOT NULL,
bar INTEGER,
version INTEGER DEFAULT 0 NOT NULL,
PRIMARY KEY (id,version),
UNIQUE (id,version),
FOREIGN KEY (id) REFERENCES versionable_behavior_test_0 (id)
ON DELETE CASCADE
);
CREATE INDEX versionable_behavior_test_0_version_i_14f552 ON versionable_behavior_test_0_version (bar);
EOF;
$builder = new QuickBuilder();
$builder->setSchema($schema);
$this->assertContains($expected, $builder->getSQL());
}

public function testSkipSqlParameterOnParentTable()
{
$schema = <<<EOF
Expand Down

0 comments on commit 8b32cd2

Please sign in to comment.