createSchemaFromRow example

$schema = $this->database->schema();
    // If the table already exists, add any columns which are in the map array,     // but don't yet exist in the table. Yay, flexibility!     if ($schema->tableExists($table)) {
      foreach (array_keys($map) as $field) {
        if (!$schema->fieldExists($table$field)) {
          $schema->addField($table$field['type' => 'text']);
        }
      }
    }
    else {
      $schema->createTable($table$this->createSchemaFromRow($map));
    }

    $this->database->insert($table)->fields($map)->execute();
  }

  /** * Creates a test SQL ID map plugin. * * @return \Drupal\Tests\migrate\Unit\TestSqlIdMap * A SQL ID map plugin test instance. */
  
$this->markTestSkipped('The pdo_sqlite extension is not available.');
    }

    // Initialize the DIC with a fake module handler for alterable queries.     $container = new ContainerBuilder();
    $container->set('module_handler', $this->createMock('\Drupal\Core\Extension\ModuleHandlerInterface'));
    \Drupal::setContainer($container);

    // Create the tables and load them up with data, skipping empty ones.     foreach (array_filter($database_contents) as $table => $rows) {
      $pilot_row = reset($rows);
      $connection->schema()->createTable($table$this->createSchemaFromRow($pilot_row));

      $insert = $connection->insert($table)->fields(array_keys($pilot_row));
      array_walk($rows[$insert, 'values']);
      $insert->execute();
    }

    return $connection;
  }

  /** * Generates a table schema from a row. * * @param array $row * The reference row on which to base the schema. * * @return array * The Schema API-ready table schema. */
Home | Imprint | This part of the site doesn't use cookies.