Skip to content

Commit

Permalink
make it possible to disable fks
Browse files Browse the repository at this point in the history
  • Loading branch information
lsmith77 committed Sep 11, 2013
1 parent 6ee9fb6 commit ef4a9fb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Jackalope/Transport/DoctrineDBAL/Query/QOMWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(NodeTypeManagerInterface $manager, Connection $conn,
$this->nodeTypeManager = $manager;
$this->platform = $conn->getDatabasePlatform();
$this->namespaces = $namespaces;
$this->schema = new RepositorySchema;
$this->schema = new RepositorySchema(array(), $this->conn);
}

/**
Expand Down
16 changes: 10 additions & 6 deletions src/Jackalope/Transport/DoctrineDBAL/RepositorySchema.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Jackalope\Transport\DoctrineDBAL;

use Doctrine\DBAL\Schema\Schema as Schema;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Table;
use PHPCR\RepositoryException;
Expand Down Expand Up @@ -133,9 +133,11 @@ protected function addNodesReferencesTable(Table $nodes)
$references->addColumn('target_id', 'integer');
$references->setPrimaryKey(array('source_id', 'source_property_name', 'target_id'));
$references->addIndex(array('target_id'));
$references->addForeignKeyConstraint($nodes, array('source_id'), array('id'), array('onDelete' => 'CASCADE'));
// TODO: this should be reenabled on RDBMS with deferred FK support
//$references->addForeignKeyConstraint($nodes, array('target_id'), array('id'));
if (!empty($this->options['disable_fk'])) {
$references->addForeignKeyConstraint($nodes, array('source_id'), array('id'), array('onDelete' => 'CASCADE'));
// TODO: this should be reenabled on RDBMS with deferred FK support
//$references->addForeignKeyConstraint($nodes, array('target_id'), array('id'));
}
}

protected function addNodesWeakreferencesTable(Table $nodes)
Expand All @@ -146,8 +148,10 @@ protected function addNodesWeakreferencesTable(Table $nodes)
$weakreferences->addColumn('target_id', 'integer');
$weakreferences->setPrimaryKey(array('source_id', 'source_property_name', 'target_id'));
$weakreferences->addIndex(array('target_id'));
$weakreferences->addForeignKeyConstraint($nodes, array('source_id'), array('id'), array('onDelete' => 'CASCADE'));
$weakreferences->addForeignKeyConstraint($nodes, array('target_id'), array('id'), array('onDelete' => 'CASCADE'));
if (!empty($this->options['disable_fk'])) {
$weakreferences->addForeignKeyConstraint($nodes, array('source_id'), array('id'), array('onDelete' => 'CASCADE'));
$weakreferences->addForeignKeyConstraint($nodes, array('target_id'), array('id'), array('onDelete' => 'CASCADE'));
}
}

protected function addTypeNodesTable()
Expand Down
4 changes: 3 additions & 1 deletion tests/Jackalope/Transport/DoctrineDBAL/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Jackalope\Transport\DoctrineDBAL;

use Doctrine\DBAL\Platforms\SqlitePlatform;
use Jackalope\Test\TestCase;

class ClientTest extends TestCase
Expand All @@ -21,7 +22,8 @@ public function setUp()
parent::setUp();

$conn = $this->getConnection();
$schema = new RepositorySchema;
$options = array('disable_fks' => $conn->getDatabasePlatform() instanceof SqlitePlatform);
$schema = new RepositorySchema($options, $conn);
// do not use reset as we want to ignore exceptions on drop
foreach ($schema->toDropSql($conn->getDatabasePlatform()) as $statement) {
try {
Expand Down
3 changes: 2 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
));

// recreate database schema
$repositorySchema = new \Jackalope\Transport\DoctrineDBAL\RepositorySchema(array(), $dbConn);
$options = array('disable_fks' => $dbConn->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform);
$repositorySchema = new \Jackalope\Transport\DoctrineDBAL\RepositorySchema($options, $dbConn);
$repositorySchema->reset();

// some constants
Expand Down

0 comments on commit ef4a9fb

Please sign in to comment.