Skip to content

Commit

Permalink
Merge pull request #13 from krome162504/add-options-on-foreign-key
Browse files Browse the repository at this point in the history
add on delete/update options on foreignKeys query
  • Loading branch information
digilist authored Aug 24, 2018
2 parents 50c4bdc + fddc691 commit a9c233d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/Converter/Tests/ConditionalConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Digilist\SnakeDumper\Converter\Tests;

use Digilist\SnakeDumper\Converter\ConditionalConverter;
use Digilist\SnakeDumper\Converter\Service\DataConverter;
use PHPUnit\Framework\TestCase;

class ConditionalConverterTest extends \PHPUnit_Framework_TestCase
class ConditionalConverterTest extends TestCase
{

public function testConditionalIfTrue()
Expand Down
3 changes: 2 additions & 1 deletion src/Converter/Tests/RandomConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

use Digilist\SnakeDumper\Converter\RandomConverter;
use Digilist\SnakeDumper\Exception\InvalidArgumentException;
use PHPUnit\Framework\TestCase;

/**
* @package Digilist\SnakeDumper\Converter\Tests
* @author moellers
*/
class RandomConverterTest extends \PHPUnit_Framework_TestCase
class RandomConverterTest extends TestCase
{

public function testEqualBounds()
Expand Down
10 changes: 8 additions & 2 deletions src/Dumper/Sql/Dumper/StructureDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ public function dumpTableStructure(array $tables)
public function dumpConstraints(array $tables) {
foreach ($tables as $table) {
foreach ($table->getForeignKeys() as $constraint) {
$options = '';
if ($onUpdate = $constraint->onUpdate()) {
$options .= ' ON UPDATE ' . $onUpdate;
}
if ($onDelete = $constraint->onDelete()) {
$options .= ' ON DELETE ' . $onDelete;
}
$constraint = $this->platform->getCreateConstraintSQL($constraint, $table);

$this->dumpOutput->writeln($constraint . ';');
$this->dumpOutput->writeln($constraint . $options . ';');
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/Dumper/Sql/Tests/AbstractSqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace Digilist\SnakeDumper\Dumper\Sql\Tests;

use Digilist\SnakeDumper\Configuration\DatabaseConfiguration;
use Digilist\SnakeDumper\Dumper\Sql\ConnectionHandler;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use PHPUnit\Framework\TestCase;

abstract class AbstractSqlTest extends \PHPUnit_Framework_TestCase
abstract class AbstractSqlTest extends TestCase
{

const DBNAME = 'snakedumper';
Expand Down Expand Up @@ -75,7 +74,7 @@ protected function createTestSchema($randomTables = false)
customer_id INTEGER,
product VARCHAR(100),
amount REAL,
CONSTRAINT customer_id FOREIGN KEY (customer_id) REFERENCES Customer(id)
CONSTRAINT customer_id FOREIGN KEY (customer_id) REFERENCES Customer(id) ON UPDATE CASCADE ON DELETE SET NULL
)');
$pdo->query('CREATE INDEX billing_product ON Billing (product)');

Expand Down
3 changes: 2 additions & 1 deletion src/Dumper/Sql/Tests/TableFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
use Digilist\SnakeDumper\Configuration\Table\TableConfiguration;
use Digilist\SnakeDumper\Dumper\Sql\TableFilter;
use Doctrine\DBAL\Schema\Table;
use PHPUnit\Framework\TestCase;

class TableFilterTest extends \PHPUnit_Framework_TestCase
class TableFilterTest extends TestCase
{

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Dumper/Sql/Tests/test_dump.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ CREATE TABLE `RandomTable` (`id` INT AUTO_INCREMENT NOT NULL, `name` VARCHAR(10)
INSERT INTO `Customer` (`id`, `name`) VALUES ('1', 'Foobar'), ('2', 'Foobar'), ('3', 'Foobar');
INSERT INTO `Customer` (`id`, `name`) VALUES ('4', 'Foobar');
INSERT INTO `Billing` (`id`, `customer_id`, `product`, `amount`) VALUES ('1', '1', 'IT', '42'), ('2', '1', NULL, '1337'), ('3', '2', 'Some stuff', '1337');
ALTER TABLE `Billing` ADD CONSTRAINT `customer_id` FOREIGN KEY (`customer_id`) REFERENCES `Customer` (`id`);
ALTER TABLE `Billing` ADD CONSTRAINT `customer_id` FOREIGN KEY (`customer_id`) REFERENCES `Customer` (`id`) ON UPDATE CASCADE ON DELETE SET NULL;

0 comments on commit a9c233d

Please sign in to comment.