dropTable example

$this->kernel->shutdown();
    }

    // Remove all prefixed tables.     $original_connection_info = Database::getConnectionInfo('simpletest_original_default');
    $original_prefix = $original_connection_info['default']['prefix'] ?? NULL;
    $test_connection_info = Database::getConnectionInfo('default');
    $test_prefix = $test_connection_info['default']['prefix'] ?? NULL;
    if ($original_prefix != $test_prefix) {
      $tables = Database::getConnection()->schema()->findTables('%');
      foreach ($tables as $table) {
        if (Database::getConnection()->schema()->dropTable($table)) {
          unset($tables[$table]);
        }
      }
    }

    // Free up memory: Own properties.     $this->classLoader = NULL;
    $this->vfsRoot = NULL;
    $this->configImporter = NULL;

    // Clean FileCache cache.
if (!$platform instanceof AbstractPlatform) {
            throw new \RuntimeException('Database platform can not be detected');
        }

        return $platform;
    }

    private function cleanup(Schema $schema): void
    {
        foreach ($schema->getTables() as $table) {
            if ($table->getComment() === self::COMMENT) {
                $schema->dropTable($table->getName());

                continue;
            }

            foreach ($table->getForeignKeys() as $foreignKey) {
                if (\str_starts_with($foreignKey->getName(), 'fk_ce_')) {
                    $table->removeForeignKey($foreignKey->getName());
                }
            }

            foreach ($table->getColumns() as $column) {
                

  protected function cleanupEnvironment() {
    // Remove all prefixed tables.     $original_connection_info = Database::getConnectionInfo('simpletest_original_default');
    $original_prefix = $original_connection_info['default']['prefix'];
    $test_connection_info = Database::getConnectionInfo('default');
    $test_prefix = $test_connection_info['default']['prefix'];
    if ($original_prefix != $test_prefix) {
      $tables = Database::getConnection()->schema()->findTables('%');
      foreach ($tables as $table) {
        if (Database::getConnection()->schema()->dropTable($table)) {
          unset($tables[$table]);
        }
      }
    }

    // Delete test site directory.     \Drupal::service('file_system')->deleteRecursive($this->siteDirectory, [$this, 'filePreDeleteCallback']);
  }

  /** * {@inheritdoc} */
    }
    $this->assertRowAbsent('outer');
    $this->assertRowAbsent('inner');
    $this->assertRowAbsent('inner2');
  }

  /** * Tests that transactions can continue to be used if a query fails. */
  public function testQueryFailureInTransaction() {
    $transaction = $this->connection->startTransaction('test_transaction');
    $this->connection->schema()->dropTable('test');

    // Test a failed query using the query() method.     try {
      $this->connection->query('SELECT [age] FROM {test} WHERE [name] = :name', [':name' => 'David'])->fetchField();
      $this->fail('Using the query method should have failed.');
    }
    catch (\Exception $e) {
      // Just continue testing.     }

    // Test a failed select query.
$this->forge->addKey('name');
        $this->forge->addKey('uid');
        $this->forge->addKey(['deleted_at', 'id']);
        $this->forge->addKey('created_at');

        $this->forge->createTable('factories');
    }

    public function down()
    {
        $this->forge->dropTable('factories');
    }
}
if (class_exists(DefaultSchemaManagerFactory::class)) {
            $config->setSchemaManagerFactory(new DefaultSchemaManagerFactory());
        }

        $this->driverConnection = DriverManager::getConnection($params$config);
        $this->connection = new PostgreSqlConnection(['table_name' => 'queue_table']$this->driverConnection);
        $this->connection->setup();
    }

    protected function tearDown(): void
    {
        $this->createSchemaManager()->dropTable('queue_table');
        $this->driverConnection->close();
    }

    public function testPostgreSqlConnectionSendAndGet()
    {
        $this->connection->send('{"message": "Hi"}', ['type' => DummyMessage::class]);

        $encoded = $this->connection->get();
        $this->assertEquals('{"message": "Hi"}', $encoded['body']);
        $this->assertEquals(['type' => DummyMessage::class]$encoded['headers']);

        
/** @var CalculatedPrice $versionPrice */
        $versionPrice = $entity->get('price');
        static::assertInstanceOf(CalculatedPrice::class$versionPrice);

        static::assertEquals(500.20, $versionPrice->getUnitPrice());
        static::assertEquals(500.30, $versionPrice->getTotalPrice());
        static::assertEquals(7.00, $versionPrice->getCalculatedTaxes()->getAmount());

        $this->connection->rollBack();

        $this->connection->executeStatement(CalculatedPriceFieldTestDefinition::dropTable());
        // We have created a table so the transaction rollback don't work -> we have to do it manually         $this->connection->executeStatement('DELETE FROM version_commit WHERE version_id = ?', [Uuid::fromHexToBytes($versionId)]);

        $this->connection->beginTransaction();
    }

    public function testICanVersionCalculatedFields(): void
    {
        static::markTestSkipped('Fixed with next-1434');

        $id1 = Uuid::randomHex();
        

class ProfileFieldCheckRequirementsTest extends MigrateDrupal6TestBase {

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    $this->sourceDatabase->schema()->dropTable('profile_fields');
  }

  /** * Tests exception is thrown when profile_fields tables do not exist. */
  public function testCheckRequirements() {
    $this->expectException(RequirementsException::class);
    $this->expectExceptionMessage('Profile module not enabled on source site');
    $this->getMigration('user_profile_field')
      ->getSourcePlugin()
      ->checkRequirements();
  }
/** * Create the tables required for the sample data. * * @param \Drupal\Core\Database\Connection $connection * The connection to use to create the tables. */
  public function createTables(Connection $connection) {
    $tables = $this->routingTableDefinition();
    $schema = $connection->schema();

    foreach ($tables as $name => $table) {
      $schema->dropTable($name);
      $schema->createTable($name$table);
    }
  }

  /** * Drop the tables used for the sample data. * * @param \Drupal\Core\Database\Connection $connection * The connection to use to drop the tables. */
  public function dropTables(Connection $connection) {
    

  protected function uninstallSchema(string $module): void {
    $tables = $this->moduleHandler->invoke($module, 'schema') ?? [];
    $schema = $this->connection->schema();
    foreach (array_keys($tables) as $table) {
      if ($schema->tableExists($table)) {
        $schema->dropTable($table);
      }
    }
  }

}
Database::getConnection('default')->schema()->createTable('drupal_install_test', $spec);
    parent::setUpSettings();

    // Ensure that the error message translation is working.     // cSpell:disable     $this->assertSession()->responseContains('Beheben Sie alle Probleme unten, um die Installation fortzusetzen. Informationen zur Konfiguration der Datenbankserver finden Sie in der <a href="https://www.drupal.org/docs/installing-drupal">Installationshandbuch</a>, oder kontaktieren Sie Ihren Hosting-Anbieter.');
    $this->assertSession()->responseContains('<strong>CREATE</strong> ein Test-Tabelle auf Ihrem Datenbankserver mit dem Befehl <em class="placeholder">CREATE TABLE {drupal_install_test} (id int NOT NULL PRIMARY KEY)</em> fehlgeschlagen.');
    // cSpell:enable
    // Now do it successfully.     Database::getConnection('default')->schema()->dropTable('drupal_install_test');
    parent::setUpSettings();
  }

  /** * Verifies the expected behaviors of the installation result. */
  public function testInstaller() {
    $this->assertSession()->addressEquals('user/1');
    $this->assertSession()->statusCodeEquals(200);

    // Verify German was configured but not English.
->execute();
  }

  /** * {@inheritdoc} */
  protected function tearDown(): void {
    // We overwrite this function because the regular teardown will not drop the     // tables from a specified schema.     $tables = $this->testingFakeConnection->schema()->findTables('%');
    foreach ($tables as $table) {
      if ($this->testingFakeConnection->schema()->dropTable($table)) {
        unset($tables[$table]);
      }
    }

    $this->assertEmpty($this->testingFakeConnection->schema()->findTables('%'));

    Database::removeConnection('testing_fake');

    parent::tearDown();
  }

  
class ModuleInstallerTest extends KernelTestBase {

  /** * Tests that routes are rebuilt during install and uninstall of modules. * * @covers ::install * @covers ::uninstall */
  public function testRouteRebuild() {
    // Remove the routing table manually to ensure it can be created lazily     // properly.     Database::getConnection()->schema()->dropTable('router');

    $this->container->get('module_installer')->install(['router_test']);
    $route = $this->container->get('router.route_provider')->getRouteByName('router_test.1');
    $this->assertEquals('/router_test/test1', $route->getPath());

    $this->container->get('module_installer')->uninstall(['router_test']);
    $this->expectException(RouteNotFoundException::class);
    $this->container->get('router.route_provider')->getRouteByName('router_test.1');
  }

  /** * Tests config changes by hook_install() are saved for dependent modules. * * @covers ::install */
/** * {@inheritdoc} */
  public function onEntityTypeDelete(EntityTypeInterface $entity_type) {
    $this->checkEntityType($entity_type);
    $schema_handler = $this->database->schema();

    // Delete entity and field tables.     $table_names = $this->getTableNames($entity_type$this->fieldStorageDefinitions, $this->getTableMapping($entity_type));
    foreach ($table_names as $table_name) {
      if ($schema_handler->tableExists($table_name)) {
        $schema_handler->dropTable($table_name);
      }
    }

    // Delete the field schema data.     foreach ($this->fieldStorageDefinitions as $field_storage_definition) {
      $this->deleteFieldSchemaData($field_storage_definition);
    }

    // Delete the entity schema.     $this->deleteEntitySchemaData($entity_type);
  }

  

    }

    // Execute the data migration query.     $this->connection->insert($new_table)
      ->from($select)
      ->execute();

    $old_count = $this->connection->query('SELECT COUNT(*) FROM {' . $table . '}')->fetchField();
    $new_count = $this->connection->query('SELECT COUNT(*) FROM {' . $new_table . '}')->fetchField();
    if ($old_count == $new_count) {
      $this->dropTable($table);
      $this->renameTable($new_table$table);
    }
  }

  /** * Find out the schema of a table. * * This function uses introspection methods provided by the database to * create a schema array. This is useful, for example, during update when * the old schema is not available. * * @param $table * Name of the table. * * @return array * An array representing the schema. * * @throws \Exception * If a column of the table could not be parsed. */
Home | Imprint | This part of the site doesn't use cookies.