protected function MediaMigrationDatabaseTraitTest::createSourceDatabaseStructure in Media Migration 8
Creates the required tables with the expected structure.
1 call to MediaMigrationDatabaseTraitTest::createSourceDatabaseStructure()
- MediaMigrationDatabaseTraitTest::setUp in tests/
src/ Kernel/ Plugin/ migrate/ source/ d7/ MediaMigrationDatabaseTraitTest.php
File
- tests/
src/ Kernel/ Plugin/ migrate/ source/ d7/ MediaMigrationDatabaseTraitTest.php, line 398
Class
- MediaMigrationDatabaseTraitTest
- @coversDefaultClass \Drupal\media_migration\Plugin\migrate\source\d7\MediaMigrationDatabaseTrait
Namespace
Drupal\Tests\media_migration\Kernel\Plugin\migrate\source\d7Code
protected function createSourceDatabaseStructure() {
// Managed file table.
$this->sourceDatabase
->schema()
->createTable('file_managed', [
'fields' => [
'fid' => [
'type' => 'serial',
'not null' => TRUE,
'size' => 'normal',
'unsigned' => TRUE,
],
'uid' => [
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'default' => '0',
'unsigned' => TRUE,
],
'filename' => [
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '',
],
'uri' => [
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '',
],
'filemime' => [
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '',
],
'filesize' => [
'type' => 'int',
'not null' => TRUE,
'size' => 'big',
'default' => '0',
'unsigned' => TRUE,
],
'status' => [
'type' => 'int',
'not null' => TRUE,
'size' => 'tiny',
'default' => '0',
],
'timestamp' => [
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'default' => '0',
'unsigned' => TRUE,
],
],
'primary key' => [
'fid',
],
'unique keys' => [
'uri' => [
'uri',
],
],
'indexes' => [
'uid' => [
'uid',
],
'status' => [
'status',
],
'timestamp' => [
'timestamp',
],
],
'mysql_character_set' => 'utf8',
]);
// File usage table.
$this->sourceDatabase
->schema()
->createTable('file_usage', [
'fields' => [
'fid' => [
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'unsigned' => TRUE,
],
'module' => [
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '',
],
'type' => [
'type' => 'varchar',
'not null' => TRUE,
'length' => '64',
'default' => '',
],
'id' => [
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'default' => '0',
'unsigned' => TRUE,
],
'count' => [
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'default' => '0',
'unsigned' => TRUE,
],
],
'primary key' => [
'fid',
'type',
'id',
'module',
],
'indexes' => [
'type_id' => [
'type',
'id',
],
'fid_count' => [
'fid',
'count',
],
'fid_module' => [
'fid',
[
'module',
'191',
],
],
],
'mysql_character_set' => 'utf8',
]);
// Users table.
$this->sourceDatabase
->schema()
->createTable('users', [
'fields' => [
'uid' => [
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'default' => '0',
'unsigned' => TRUE,
],
'name' => [
'type' => 'varchar',
'not null' => TRUE,
'length' => '60',
'default' => '',
],
'pass' => [
'type' => 'varchar',
'not null' => TRUE,
'length' => '128',
'default' => '',
],
'mail' => [
'type' => 'varchar',
'not null' => FALSE,
'length' => '254',
'default' => '',
],
'theme' => [
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '',
],
'signature' => [
'type' => 'varchar',
'not null' => TRUE,
'length' => '255',
'default' => '',
],
'signature_format' => [
'type' => 'varchar',
'not null' => FALSE,
'length' => '255',
],
'created' => [
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'default' => '0',
],
'access' => [
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'default' => '0',
],
'login' => [
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'default' => '0',
],
'status' => [
'type' => 'int',
'not null' => TRUE,
'size' => 'tiny',
'default' => '0',
],
'timezone' => [
'type' => 'varchar',
'not null' => FALSE,
'length' => '32',
],
'language' => [
'type' => 'varchar',
'not null' => TRUE,
'length' => '12',
'default' => '',
],
'picture' => [
'type' => 'int',
'not null' => TRUE,
'size' => 'normal',
'default' => '0',
],
'init' => [
'type' => 'varchar',
'not null' => FALSE,
'length' => '254',
'default' => '',
],
'data' => [
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
],
],
'primary key' => [
'uid',
],
'unique keys' => [
'name' => [
'name',
],
],
'indexes' => [
'access' => [
'access',
],
'created' => [
'created',
],
'mail' => [
[
'mail',
'191',
],
],
'picture' => [
'picture',
],
],
'mysql_character_set' => 'utf8',
]);
// Add data.
$this->sourceDatabase
->insert('file_managed')
->fields([
'fid',
'uid',
'filename',
'uri',
'filemime',
'filesize',
'status',
'timestamp',
])
->values([
'fid' => 1,
'uid' => 1,
'filename' => 'blue.png',
'uri' => 'public://blue.png',
'filemime' => 'image/png',
'filesize' => 9061,
'status' => 1,
'timestamp' => 1587725909,
])
->values([
'fid' => 2,
'uid' => 2,
'filename' => 'green.jpg',
'uri' => 'public://field/image/green.jpg',
'filemime' => 'image/jpeg',
'filesize' => 11050,
'status' => 1,
'timestamp' => 1587730322,
])
->values([
'fid' => 3,
'uid' => 2,
'filename' => 'LICENSE.txt',
'uri' => 'public://LICENSE.txt',
'filemime' => 'text/plain',
'filesize' => 18002,
'status' => 1,
'timestamp' => 1587731111,
])
->execute();
}