From 6979ef5fbea40b84659d7b252e61060b66133d20 Mon Sep 17 00:00:00 2001 From: 77web Date: Tue, 1 Aug 2023 23:07:16 +0900 Subject: [PATCH 1/6] updated dependency to doctrine/dbal v3 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index e34094d..526e501 100644 --- a/composer.json +++ b/composer.json @@ -2,9 +2,9 @@ "name": "linkage/doctrine-row-level-security", "type": "library", "require": { - "doctrine/dbal": "^2.13", + "doctrine/dbal": "^3.0", "doctrine/orm": "^2.14", - "php": ">=8.1" + "php": ">=8.2" }, "require-dev": { "phpunit/phpunit": "^10.0", From 94d56709dea0af94f2eee7b5ba5cad97e569950d Mon Sep 17 00:00:00 2001 From: 77web Date: Tue, 1 Aug 2023 23:09:25 +0900 Subject: [PATCH 2/6] migrated deprecated methods to new one in Comparator --- src/RowLevelSecurityAwareComparator.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/RowLevelSecurityAwareComparator.php b/src/RowLevelSecurityAwareComparator.php index 147048a..79c446b 100644 --- a/src/RowLevelSecurityAwareComparator.php +++ b/src/RowLevelSecurityAwareComparator.php @@ -22,7 +22,7 @@ public function __construct() public function compareSchemas(Schema $fromSchema, Schema $toSchema): RowLevelSecurityAwareSchemaDiff|SchemaDiff { - $baseDiff = $this->delegate->compare($fromSchema, $toSchema); + $baseDiff = $this->delegate->compareSchemas($fromSchema, $toSchema); $hasRlsDiff = false; foreach ($toSchema->getTables() as $toTable) { @@ -32,7 +32,7 @@ public function compareSchemas(Schema $fromSchema, Schema $toSchema): RowLevelSe // 新規テーブルは差分がある扱いなのでcreateのイベントリスナに任せる continue; } - $tableDiff = $this->diffTable($fromTable, $toTable); + $tableDiff = $this->compareTable($fromTable, $toTable); if ($tableDiff instanceof RowLevelSecurityAwareTableDiff) { $baseDiff->changedTables[$tableDiff->name] = $tableDiff; $hasRlsDiff = true; @@ -42,13 +42,12 @@ public function compareSchemas(Schema $fromSchema, Schema $toSchema): RowLevelSe return $hasRlsDiff ? new RowLevelSecurityAwareSchemaDiff($baseDiff) : $baseDiff; } - public function diffTable(Table $fromTable, Table $toTable): TableDiff|bool + public function compareTable(Table $fromTable, Table $toTable): TableDiff { - $baseDiff = $this->delegate->diffTable($fromTable, $toTable); + $baseTableDiff = $this->delegate->compareTables($fromTable, $toTable); if ($toTable->hasOption(RowLevelSecurityConfig::RLS_OPTION_NAME) && !$fromTable->hasOption(RowLevelSecurityConfig::RLS_OPTION_NAME)) { // RLSがなかったテーブルにRLSを足した時 - $baseTableDiff = $baseDiff instanceof TableDiff ? $baseDiff : new TableDiff($toTable->getName(), fromTable: $fromTable); $rlsTableDiff = new RowLevelSecurityAwareTableDiff($baseTableDiff); $rlsTableDiff->addedRowLevelSecurity = $toTable->getOption(RowLevelSecurityConfig::RLS_OPTION_NAME); @@ -56,13 +55,12 @@ public function diffTable(Table $fromTable, Table $toTable): TableDiff|bool } if (!$toTable->hasOption(RowLevelSecurityConfig::RLS_OPTION_NAME) && $fromTable->hasOption(RowLevelSecurityConfig::RLS_OPTION_NAME)) { // RLSがあったテーブルのRLSを消した時 - $baseTableDiff = $baseDiff instanceof TableDiff ? $baseDiff : new TableDiff($toTable->getName(), fromTable: $fromTable); $rlsTableDiff = new RowLevelSecurityAwareTableDiff($baseTableDiff); $rlsTableDiff->removedRowLevelSecurity = $fromTable->getOption(RowLevelSecurityConfig::RLS_OPTION_NAME); return $rlsTableDiff; } - return $baseDiff; + return $baseTableDiff; } } From 402789ffe5cbe7ba5422139a45659f0a104c14b0 Mon Sep 17 00:00:00 2001 From: 77web Date: Tue, 1 Aug 2023 23:12:08 +0900 Subject: [PATCH 3/6] migrated method return type declaration --- src/RowLevelSecurityAwareComparator.php | 4 ++-- src/RowLevelSecurityAwarePostgreSqlSchemaManager.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/RowLevelSecurityAwareComparator.php b/src/RowLevelSecurityAwareComparator.php index 79c446b..7998de2 100644 --- a/src/RowLevelSecurityAwareComparator.php +++ b/src/RowLevelSecurityAwareComparator.php @@ -11,7 +11,7 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; -class RowLevelSecurityAwareComparator +class RowLevelSecurityAwareComparator extends Comparator { private readonly Comparator $delegate; @@ -44,7 +44,7 @@ public function compareSchemas(Schema $fromSchema, Schema $toSchema): RowLevelSe public function compareTable(Table $fromTable, Table $toTable): TableDiff { - $baseTableDiff = $this->delegate->compareTables($fromTable, $toTable); + $baseTableDiff = $this->delegate->compareTable($fromTable, $toTable); if ($toTable->hasOption(RowLevelSecurityConfig::RLS_OPTION_NAME) && !$fromTable->hasOption(RowLevelSecurityConfig::RLS_OPTION_NAME)) { // RLSがなかったテーブルにRLSを足した時 diff --git a/src/RowLevelSecurityAwarePostgreSqlSchemaManager.php b/src/RowLevelSecurityAwarePostgreSqlSchemaManager.php index c889962..14b999b 100644 --- a/src/RowLevelSecurityAwarePostgreSqlSchemaManager.php +++ b/src/RowLevelSecurityAwarePostgreSqlSchemaManager.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; +use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\PostgreSqlSchemaManager; use Doctrine\DBAL\Schema\Table; @@ -53,7 +54,7 @@ public function listTableDetails($name): Table return $table; } - public function createComparator(): RowLevelSecurityAwareComparator + public function createComparator(): Comparator { return new RowLevelSecurityAwareComparator(); } From 89fec93e2d6097bca7f822fa301e0ddd2f1ef798 Mon Sep 17 00:00:00 2001 From: 77web Date: Tue, 1 Aug 2023 23:16:29 +0900 Subject: [PATCH 4/6] changed Comparator from decorator to subclass (to follow method return type declaration change) --- src/RowLevelSecurityAwareComparator.php | 13 ++++++------- ...RowLevelSecurityAwarePostgreSqlSchemaManager.php | 8 +++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/RowLevelSecurityAwareComparator.php b/src/RowLevelSecurityAwareComparator.php index 7998de2..0b9350d 100644 --- a/src/RowLevelSecurityAwareComparator.php +++ b/src/RowLevelSecurityAwareComparator.php @@ -4,6 +4,7 @@ namespace Linkage\DoctrineRowLevelSecurity; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\SchemaDiff; @@ -13,16 +14,14 @@ class RowLevelSecurityAwareComparator extends Comparator { - private readonly Comparator $delegate; - - public function __construct() + public function __construct(AbstractPlatform $platform) { - $this->delegate = new Comparator(); + parent::__construct($platform); } public function compareSchemas(Schema $fromSchema, Schema $toSchema): RowLevelSecurityAwareSchemaDiff|SchemaDiff { - $baseDiff = $this->delegate->compareSchemas($fromSchema, $toSchema); + $baseDiff = parent::compareSchemas($fromSchema, $toSchema); $hasRlsDiff = false; foreach ($toSchema->getTables() as $toTable) { @@ -34,7 +33,7 @@ public function compareSchemas(Schema $fromSchema, Schema $toSchema): RowLevelSe } $tableDiff = $this->compareTable($fromTable, $toTable); if ($tableDiff instanceof RowLevelSecurityAwareTableDiff) { - $baseDiff->changedTables[$tableDiff->name] = $tableDiff; + $baseDiff->changedTables[$tableDiff->getOldTable()] = $tableDiff; $hasRlsDiff = true; } } @@ -44,7 +43,7 @@ public function compareSchemas(Schema $fromSchema, Schema $toSchema): RowLevelSe public function compareTable(Table $fromTable, Table $toTable): TableDiff { - $baseTableDiff = $this->delegate->compareTable($fromTable, $toTable); + $baseTableDiff = parent::compareTable($fromTable, $toTable); if ($toTable->hasOption(RowLevelSecurityConfig::RLS_OPTION_NAME) && !$fromTable->hasOption(RowLevelSecurityConfig::RLS_OPTION_NAME)) { // RLSがなかったテーブルにRLSを足した時 diff --git a/src/RowLevelSecurityAwarePostgreSqlSchemaManager.php b/src/RowLevelSecurityAwarePostgreSqlSchemaManager.php index 14b999b..ca8c2c8 100644 --- a/src/RowLevelSecurityAwarePostgreSqlSchemaManager.php +++ b/src/RowLevelSecurityAwarePostgreSqlSchemaManager.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Exception\DriverException; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\PostgreSqlSchemaManager; @@ -14,9 +15,10 @@ class RowLevelSecurityAwarePostgreSqlSchemaManager extends PostgreSqlSchemaManager { public function __construct( - Connection $conn + Connection $conn, + AbstractPlatform $platform, ) { - parent::__construct($conn); + parent::__construct($conn, $platform); } public function listTableDetails($name): Table @@ -56,6 +58,6 @@ public function listTableDetails($name): Table public function createComparator(): Comparator { - return new RowLevelSecurityAwareComparator(); + return new RowLevelSecurityAwareComparator($this->_platform); } } From 0c292a3e75eb246ad9b6c97efc724c4b7d6de65a Mon Sep 17 00:00:00 2001 From: 77web Date: Tue, 1 Aug 2023 23:20:27 +0900 Subject: [PATCH 5/6] migrated TableDiff:$name to TableDiff::getOldTable()->getName() --- src/RowLevelSecurityAwareComparator.php | 2 +- src/RowLevelSecurityAwareTableDiff.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/RowLevelSecurityAwareComparator.php b/src/RowLevelSecurityAwareComparator.php index 0b9350d..82a138d 100644 --- a/src/RowLevelSecurityAwareComparator.php +++ b/src/RowLevelSecurityAwareComparator.php @@ -33,7 +33,7 @@ public function compareSchemas(Schema $fromSchema, Schema $toSchema): RowLevelSe } $tableDiff = $this->compareTable($fromTable, $toTable); if ($tableDiff instanceof RowLevelSecurityAwareTableDiff) { - $baseDiff->changedTables[$tableDiff->getOldTable()] = $tableDiff; + $baseDiff->changedTables[$tableDiff->getOldTable()->getName()] = $tableDiff; $hasRlsDiff = true; } } diff --git a/src/RowLevelSecurityAwareTableDiff.php b/src/RowLevelSecurityAwareTableDiff.php index ee8c766..39b816b 100644 --- a/src/RowLevelSecurityAwareTableDiff.php +++ b/src/RowLevelSecurityAwareTableDiff.php @@ -15,7 +15,7 @@ public function __construct( TableDiff $baseDiff, ) { parent::__construct( - $baseDiff->name, + $baseDiff->getOldTable()->getName(), $baseDiff->addedColumns, $baseDiff->changedColumns, $baseDiff->removedColumns, @@ -37,7 +37,7 @@ public function getRowLevelSecuritySqls(): array $using = $this->addedRowLevelSecurity['using'] ?? '## TODO 手動設定要 ##'; return $sqlFactory->createEnableSqls( $this->addedRowLevelSecurity['name'], - $this->name, + $this->getOldTable()->getName(), $this->addedRowLevelSecurity['role'], $using, ); @@ -45,7 +45,7 @@ public function getRowLevelSecuritySqls(): array if ($this->removedRowLevelSecurity !== null) { return $sqlFactory->createDisableSqls( $this->removedRowLevelSecurity['name'], - $this->name, + $this->getOldTable()->getName(), ); } From 66ed33b3f554ddecf49209e3ffec69a926a903fc Mon Sep 17 00:00:00 2001 From: 77web Date: Wed, 2 Aug 2023 09:43:55 +0900 Subject: [PATCH 6/6] fix: RowLevlSecurityAwarePostgreSqlSchemaManager needs platform as 2nd argument --- src/RowLevelSecurityAwarePostgreSqlConnection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RowLevelSecurityAwarePostgreSqlConnection.php b/src/RowLevelSecurityAwarePostgreSqlConnection.php index 20a38d9..084a45b 100644 --- a/src/RowLevelSecurityAwarePostgreSqlConnection.php +++ b/src/RowLevelSecurityAwarePostgreSqlConnection.php @@ -11,6 +11,6 @@ class RowLevelSecurityAwarePostgreSqlConnection extends Connection { public function getSchemaManager(): AbstractSchemaManager { - return new RowLevelSecurityAwarePostgreSqlSchemaManager($this); + return new RowLevelSecurityAwarePostgreSqlSchemaManager($this, $this->getDatabasePlatform()); } }