Skip to content

Commit

Permalink
Fixed FK migrations and return platform methods
Browse files Browse the repository at this point in the history
  • Loading branch information
iamwildtuna committed Mar 24, 2021
1 parent b476848 commit 1f5a8a8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ doctrine:
driver_class: LapayGroup\DoctrineCockroach\Driver\CockroachDriver
```

Connection url style:
```yaml
# doctrine.yaml
doctrine:
dbal:
url: //root:@localhost:26257/database_name
platform_service: LapayGroup\DoctrineCockroach\Platforms\CockroachPlatform
driver_class: LapayGroup\DoctrineCockroach\Driver\CockroachDriver
```

```yaml
# services.yaml
services:
Expand Down
20 changes: 20 additions & 0 deletions src/Driver/CockroachDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\PDOPgSql;
use Doctrine\DBAL\Driver\PDO;
use LapayGroup\DoctrineCockroach\Platforms\CockroachPlatform;
use LapayGroup\DoctrineCockroach\Schema\CockroachSchemaManager;


Expand All @@ -28,6 +29,25 @@ public function connect(array $params, $username = null, $password = null, array
return $pdo;
}

/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new CockroachPlatform();
}

/**
* {@inheritdoc}
*/
public function createDatabasePlatformForVersion($version)
{
return new CockroachPlatform();
}

/**
* {@inheritdoc}
*/
public function getSchemaManager(Connection $conn)
{
return new CockroachSchemaManager($conn);
Expand Down
21 changes: 6 additions & 15 deletions src/Platforms/CockroachPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,20 @@ public function getIntegerTypeDeclarationSQL(array $column)
*/
public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey)
{
// Waiting for resolved https://github.com/cockroachdb/cockroach/issues/31632
$query = '';

if ($foreignKey->hasOption('match')) {
$query .= ' MATCH ' . $foreignKey->getOption('match');
}

$query .= parent::getAdvancedForeignKeyOptionsSQL($foreignKey);

// Waiting for resolved https://github.com/cockroachdb/cockroach/issues/31632
/*if ($foreignKey->hasOption('deferrable') && $foreignKey->getOption('deferrable') !== false) {
$query .= ' DEFERRABLE';
} else {
$query .= ' NOT DEFERRABLE';
if (parent::supportsForeignKeyOnUpdate() && $foreignKey->hasOption('onUpdate')) {
$query .= ' ON UPDATE ' . parent::getForeignKeyReferentialActionSQL($foreignKey->getOption('onUpdate'));
}

if (
($foreignKey->hasOption('feferred') && $foreignKey->getOption('feferred') !== false)
|| ($foreignKey->hasOption('deferred') && $foreignKey->getOption('deferred') !== false)
) {
$query .= ' INITIALLY DEFERRED';
} else {
$query .= ' INITIALLY IMMEDIATE';
}*/
if ($foreignKey->hasOption('onDelete')) {
$query .= ' ON DELETE ' . parent::getForeignKeyReferentialActionSQL($foreignKey->getOption('onDelete'));
}

return $query;
}
Expand Down

0 comments on commit 1f5a8a8

Please sign in to comment.