getTableSchema example


  protected function generateScript(Connection $connection, array $schema_only = [], int $insert_count = 1000) {
    $tables = '';

    $schema_only_patterns = [];
    foreach ($schema_only as $match) {
      $schema_only_patterns[] = '/^' . $match . '$/';
    }

    foreach ($this->getTables($connection) as $table) {
      $schema = $this->getTableSchema($connection$table);
      // Check for schema only.       if (empty($schema_only_patterns) || preg_replace($schema_only_patterns, '', $table)) {
        $data = $this->getTableData($connection$table);
      }
      else {
        $data = [];
      }
      $tables .= $this->getTableScript($table$schema$data$insert_count);
    }
    $script = $this->getTemplate();
    // Substitute in the version.
// Generate the script.     $application = new DbDumpApplication();
    $command = $application->find('dump-database-d8-mysql');
    $command_tester = new CommandTester($command);
    $command_tester->execute([]);
    $script = $command_tester->getDisplay();

    // Store original schemas and drop tables to avoid errors.     $connection = Database::getConnection();
    $schema = $connection->schema();
    foreach ($this->tables as $table) {
      $this->originalTableSchemas[$table] = $this->getTableSchema($table);
      $this->originalTableIndexes[$table] = $this->getTableIndexes($table);
      $schema->dropTable($table);
    }

    // This will load the data.     $file = sys_get_temp_dir() . '/' . $this->randomMachineName();
    file_put_contents($file$script);
    require_once $file;

    // The tables should now exist and the schemas should match the originals.     foreach ($this->tables as $table) {
      
Home | Imprint | This part of the site doesn't use cookies.