From 5934579d27ce6f9335fbfa53aaf0e8c3bdd77be3 Mon Sep 17 00:00:00 2001 From: mondrake Date: Sun, 6 Nov 2022 18:35:47 +0100 Subject: [PATCH 1/6] I --- .github/workflows/pr.yml | 55 ++++++++++----- tests/src/Kernel/dbal/SchemaTest.php | 101 +++++++++++++++++++++++++++ 2 files changed, 137 insertions(+), 19 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index d1c72ce3e..564308ff3 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -16,31 +16,39 @@ jobs: ################################# - mariadb-pdo: - name: "MariaDb" - runs-on: ubuntu-latest + oracle-oci8: + name: "Oracle on Oci8" + runs-on: ubuntu-20.04 env: - DRUDBAL_ENV: "dbal/mariadb" - DBAL_URL: "mysql://root:@0.0.0.0:3306/drudbal" - SIMPLETEST_DB: "dbal://root:@0.0.0.0:3306/drudbal?module=drudbal&dbal_driver=pdo_mysql" + DRUDBAL_ENV: "dbal/oci8" + DBAL_URL: "oci8://DRUDBAL:ORACLE@0.0.0.0:1521/XE" + SIMPLETEST_DB: "dbal://DRUDBAL:ORACLE@0.0.0.0:1521/XE?module=drudbal&dbal_driver=oci8#dru" + + services: + oracle: + image: gvenzl/oracle-xe:21 + env: + ORACLE_PASSWORD: oracle + ports: + - "1521:1521" + options: >- + --health-cmd healthcheck.sh + --health-interval 20s + --health-timeout 10s + --health-retries 10 strategy: fail-fast: false matrix: php-version: - "8.1" -# - "8.2" test-args: - "--group Database" - - services: - mariadb: - image: "mariadb:10.5" - env: - MYSQL_ALLOW_EMPTY_PASSWORD: yes - MYSQL_DATABASE: "drudbal" - ports: - - "3306:3306" +# - "--group Entity" +# - "--group Cache,Config" +# - "--group field,Field" +# - "--group file" +# - "--group views" steps: - name: Install PHP @@ -48,7 +56,7 @@ jobs: with: php-version: "${{ matrix.php-version }}" coverage: "none" - extensions: "pdo_mysql" + extensions: "oci8" ini-values: "zend.assertions=1" - name: Checkout Drupal @@ -73,14 +81,23 @@ jobs: composer config repositories.test-run '{"type": "path", "url": "drudbal_staging", "options": {"symlink": false}}' composer require "mondrake/drudbal:dev-test-run-branch" --no-progress --ansi - - name: Install Drupal + - name: Patch doctrine/dbal + run: | + curl https://patch-diff.githubusercontent.com/raw/mondrake/dbal/pull/6.diff | patch -d vendor/doctrine/dbal -p1 + + - name: Create Oracle schema run: | cp modules/contrib/drudbal/tests/github/install_* . + php install_oracle.php + + - name: Install Drupal + run: | vendor/bin/drush site-install standard --db-url=$SIMPLETEST_DB -y vendor/bin/drush runserver localhost:8080 --default-server=localhost:8080 & - sleep 1s + sleep 5s - name: Report installation + continue-on-error: true run: | php install_report.php vendor/bin/drush core:status diff --git a/tests/src/Kernel/dbal/SchemaTest.php b/tests/src/Kernel/dbal/SchemaTest.php index e8422e12a..f6d867eff 100644 --- a/tests/src/Kernel/dbal/SchemaTest.php +++ b/tests/src/Kernel/dbal/SchemaTest.php @@ -507,4 +507,105 @@ public function testUnsignedColumns(): void { } } + /** + * Tests handling with reserved keywords for naming tables, fields and more. + */ + public function testReservedKeywordsForNaming(): void { + $table_specification = [ + 'description' => 'A test table with an ANSI reserved keywords for naming.', + 'fields' => [ + 'primary' => [ + 'description' => 'Simple unique ID.', + 'type' => 'int', + 'not null' => TRUE, + ], + 'update' => [ + 'description' => 'A column with reserved name.', + 'type' => 'varchar', + 'length' => 255, + ], + ], + 'primary key' => ['primary'], + 'unique keys' => [ + 'having' => ['update'], + ], + 'indexes' => [ + 'in' => ['primary', 'update'], + ], + ]; + + // Creating a table. + $table_name = 'select'; + $this->schema->createTable($table_name, $table_specification); + $this->assertTrue($this->schema->tableExists($table_name)); + + // Finding all tables. + $tables = $this->schema->findTables('%'); + sort($tables); + $this->assertEquals(['config', 'select'], $tables); + + // Renaming a table. + $table_name_new = 'from'; + $this->schema->renameTable($table_name, $table_name_new); + $this->assertFalse($this->schema->tableExists($table_name)); + $this->assertTrue($this->schema->tableExists($table_name_new)); + + // Adding a field. + $field_name = 'delete'; +global $xxx; $xxx=TRUE; + $this->schema->addField($table_name_new, $field_name, ['type' => 'int', 'not null' => TRUE]); + $this->assertTrue($this->schema->fieldExists($table_name_new, $field_name)); + + // Dropping a primary key. + $this->schema->dropPrimaryKey($table_name_new); + + // Adding a primary key. + $this->schema->addPrimaryKey($table_name_new, [$field_name]); + + // Check the primary key columns. + $find_primary_key_columns = new \ReflectionMethod(get_class($this->schema), 'findPrimaryKeyColumns'); + $this->assertEquals([$field_name], $find_primary_key_columns->invoke($this->schema, $table_name_new)); + + // Dropping a primary key. + $this->schema->dropPrimaryKey($table_name_new); + + // Changing a field. + $field_name_new = 'where'; + $this->schema->changeField($table_name_new, $field_name, $field_name_new, ['type' => 'int', 'not null' => FALSE]); + $this->assertFalse($this->schema->fieldExists($table_name_new, $field_name)); + $this->assertTrue($this->schema->fieldExists($table_name_new, $field_name_new)); + + // Adding an unique key + $unique_key_name = $unique_key_introspect_name = 'unique'; + $this->schema->addUniqueKey($table_name_new, $unique_key_name, [$field_name_new]); + + // Check the unique key columns. + $introspect_index_schema = new \ReflectionMethod(get_class($this->schema), 'introspectIndexSchema'); +dump([$introspect_index_schema, $introspect_index_schema->invoke($this->schema, $table_name_new)]); + $this->assertEquals([$field_name_new], $introspect_index_schema->invoke($this->schema, $table_name_new)['unique keys'][$unique_key_introspect_name]); + + // Dropping an unique key + $this->schema->dropUniqueKey($table_name_new, $unique_key_name); + + // Dropping a field. + $this->schema->dropField($table_name_new, $field_name_new); + $this->assertFalse($this->schema->fieldExists($table_name_new, $field_name_new)); + + // Adding an index. + $index_name = $index_introspect_name = 'index'; + $this->schema->addIndex($table_name_new, $index_name, ['update'], $table_specification); + $this->assertTrue($this->schema->indexExists($table_name_new, $index_name)); + + // Check the index columns. + $this->assertEquals(['update'], $introspect_index_schema->invoke($this->schema, $table_name_new)['indexes'][$index_introspect_name]); + + // Dropping an index. + $this->schema->dropIndex($table_name_new, $index_name); + $this->assertFalse($this->schema->indexExists($table_name_new, $index_name)); + + // Dropping a table. + $this->schema->dropTable($table_name_new); + $this->assertFalse($this->schema->tableExists($table_name_new)); + } + } From e6b1faa5200b65cef40dcd80925af146a00cc54a Mon Sep 17 00:00:00 2001 From: mondrake Date: Sun, 6 Nov 2022 18:52:58 +0100 Subject: [PATCH 2/6] II --- tests/src/Kernel/dbal/SchemaTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Kernel/dbal/SchemaTest.php b/tests/src/Kernel/dbal/SchemaTest.php index f6d867eff..652fcd3ae 100644 --- a/tests/src/Kernel/dbal/SchemaTest.php +++ b/tests/src/Kernel/dbal/SchemaTest.php @@ -582,7 +582,7 @@ public function testReservedKeywordsForNaming(): void { // Check the unique key columns. $introspect_index_schema = new \ReflectionMethod(get_class($this->schema), 'introspectIndexSchema'); dump([$introspect_index_schema, $introspect_index_schema->invoke($this->schema, $table_name_new)]); - $this->assertEquals([$field_name_new], $introspect_index_schema->invoke($this->schema, $table_name_new)['unique keys'][$unique_key_introspect_name]); +// $this->assertEquals([$field_name_new], $introspect_index_schema->invoke($this->schema, $table_name_new)['unique keys'][$unique_key_introspect_name]); // Dropping an unique key $this->schema->dropUniqueKey($table_name_new, $unique_key_name); From b6d4d16a22b375d742d83e83eb34f82fdb5c80c3 Mon Sep 17 00:00:00 2001 From: mondrake Date: Sun, 6 Nov 2022 20:22:16 +0100 Subject: [PATCH 3/6] III --- tests/src/Kernel/dbal/SchemaTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/src/Kernel/dbal/SchemaTest.php b/tests/src/Kernel/dbal/SchemaTest.php index 652fcd3ae..8d2e6d0f4 100644 --- a/tests/src/Kernel/dbal/SchemaTest.php +++ b/tests/src/Kernel/dbal/SchemaTest.php @@ -581,7 +581,8 @@ public function testReservedKeywordsForNaming(): void { // Check the unique key columns. $introspect_index_schema = new \ReflectionMethod(get_class($this->schema), 'introspectIndexSchema'); -dump([$introspect_index_schema, $introspect_index_schema->invoke($this->schema, $table_name_new)]); + $dbUniqueIndexName = $this->connection()->getDbalExtension()->getDbIndexName('indexExists', $this->schema->dbalSchema(), $table_name_new, $unique_key_name); +dump([$dbUniqueIndexName, $unique_key_name, $table_name_new, $introspect_index_schema->invoke($this->schema, $table_name_new)]); // $this->assertEquals([$field_name_new], $introspect_index_schema->invoke($this->schema, $table_name_new)['unique keys'][$unique_key_introspect_name]); // Dropping an unique key From e4632465d5f55662e74dde99a0f0e308fa81be22 Mon Sep 17 00:00:00 2001 From: mondrake Date: Sun, 6 Nov 2022 20:41:48 +0100 Subject: [PATCH 4/6] IV --- src/Driver/Database/dbal/Schema.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Driver/Database/dbal/Schema.php b/src/Driver/Database/dbal/Schema.php index 57903b25e..504089097 100644 --- a/src/Driver/Database/dbal/Schema.php +++ b/src/Driver/Database/dbal/Schema.php @@ -14,6 +14,7 @@ use Drupal\Core\Database\Schema as DatabaseSchema; use Drupal\Core\Database\SchemaObjectDoesNotExistException; use Drupal\Core\Database\SchemaObjectExistsException; +use Drupal\drudbal\Driver\Database\dbal\DbalExtension\DbalExtensionInterface; /** * DruDbal implementation of \Drupal\Core\Database\Schema. @@ -42,10 +43,8 @@ class Schema extends DatabaseSchema { /** * The Dbal extension for the DBAL driver. - * - * @var \Drupal\drudbal\Driver\Database\dbal\DbalExtension\DbalExtensionInterface */ - protected $dbalExtension; + protected DbalExtensionInterface $dbalExtension; /** * Constructs a Schema object. @@ -844,7 +843,7 @@ public function fieldExists($table, $column) { * @return \Doctrine\DBAL\Schema\Schema * The DBAL schema of the database. */ - private function dbalSchema() { + public function dbalSchema() { if (!isset($this->dbalCurrentSchema)) { $this->dbalSetCurrentSchema($this->dbalSchemaManager->introspectSchema()); } From cd21202664c1920f31e2cb9bc58cd9fa5a41740e Mon Sep 17 00:00:00 2001 From: mondrake Date: Sun, 6 Nov 2022 21:21:29 +0100 Subject: [PATCH 5/6] V --- tests/src/Kernel/dbal/SchemaTest.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/src/Kernel/dbal/SchemaTest.php b/tests/src/Kernel/dbal/SchemaTest.php index 8d2e6d0f4..7fe903b73 100644 --- a/tests/src/Kernel/dbal/SchemaTest.php +++ b/tests/src/Kernel/dbal/SchemaTest.php @@ -524,6 +524,11 @@ public function testReservedKeywordsForNaming(): void { 'type' => 'varchar', 'length' => 255, ], + 'insert' => [ + 'description' => 'Another column with reserved name.', + 'type' => 'varchar', + 'length' => 255, + ], ], 'primary key' => ['primary'], 'unique keys' => [ @@ -552,7 +557,6 @@ public function testReservedKeywordsForNaming(): void { // Adding a field. $field_name = 'delete'; -global $xxx; $xxx=TRUE; $this->schema->addField($table_name_new, $field_name, ['type' => 'int', 'not null' => TRUE]); $this->assertTrue($this->schema->fieldExists($table_name_new, $field_name)); @@ -580,10 +584,11 @@ public function testReservedKeywordsForNaming(): void { $this->schema->addUniqueKey($table_name_new, $unique_key_name, [$field_name_new]); // Check the unique key columns. + // @todo this differs from core in the sense that the index name must be + // recalculated via ::getDbIndexName(). $introspect_index_schema = new \ReflectionMethod(get_class($this->schema), 'introspectIndexSchema'); - $dbUniqueIndexName = $this->connection()->getDbalExtension()->getDbIndexName('indexExists', $this->schema->dbalSchema(), $table_name_new, $unique_key_name); -dump([$dbUniqueIndexName, $unique_key_name, $table_name_new, $introspect_index_schema->invoke($this->schema, $table_name_new)]); -// $this->assertEquals([$field_name_new], $introspect_index_schema->invoke($this->schema, $table_name_new)['unique keys'][$unique_key_introspect_name]); + $dbUniqueIndexName = $this->connection()->getDbalExtension()->getDbIndexName('indexExists', $this->schema()->dbalSchema(), $table_name_new, $unique_key_name); + $this->assertEquals([$field_name_new], $introspect_index_schema->invoke($this->schema, $table_name_new)['unique keys'][$dbUniqueIndexName]); // Dropping an unique key $this->schema->dropUniqueKey($table_name_new, $unique_key_name); @@ -593,12 +598,17 @@ public function testReservedKeywordsForNaming(): void { $this->assertFalse($this->schema->fieldExists($table_name_new, $field_name_new)); // Adding an index. + // @todo this differs from core in the sense that we use a different column + // than 'update' - that would lead to duplicated index on Oracle. $index_name = $index_introspect_name = 'index'; - $this->schema->addIndex($table_name_new, $index_name, ['update'], $table_specification); + $this->schema->addIndex($table_name_new, $index_name, ['insert'], $table_specification); $this->assertTrue($this->schema->indexExists($table_name_new, $index_name)); // Check the index columns. - $this->assertEquals(['update'], $introspect_index_schema->invoke($this->schema, $table_name_new)['indexes'][$index_introspect_name]); + // @todo this differs from core in the sense that the index name must be + // recalculated via ::getDbIndexName(). + $dbIndexName = $this->connection()->getDbalExtension()->getDbIndexName('indexExists', $this->schema->dbalSchema(), $table_name_new, $index_name); + $this->assertEquals(['insert'], $introspect_index_schema->invoke($this->schema, $table_name_new)['indexes'][$dbIndexName]); // Dropping an index. $this->schema->dropIndex($table_name_new, $index_name); From 9884cf77253bd1d31ccb38974a3bfa5407486aee Mon Sep 17 00:00:00 2001 From: mondrake Date: Sun, 6 Nov 2022 21:33:35 +0100 Subject: [PATCH 6/6] VI --- tests/src/Kernel/dbal/SchemaTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/src/Kernel/dbal/SchemaTest.php b/tests/src/Kernel/dbal/SchemaTest.php index 7fe903b73..3d5edf2f1 100644 --- a/tests/src/Kernel/dbal/SchemaTest.php +++ b/tests/src/Kernel/dbal/SchemaTest.php @@ -607,7 +607,7 @@ public function testReservedKeywordsForNaming(): void { // Check the index columns. // @todo this differs from core in the sense that the index name must be // recalculated via ::getDbIndexName(). - $dbIndexName = $this->connection()->getDbalExtension()->getDbIndexName('indexExists', $this->schema->dbalSchema(), $table_name_new, $index_name); + $dbIndexName = $this->connection()->getDbalExtension()->getDbIndexName('indexExists', $this->schema()->dbalSchema(), $table_name_new, $index_name); $this->assertEquals(['insert'], $introspect_index_schema->invoke($this->schema, $table_name_new)['indexes'][$dbIndexName]); // Dropping an index.