You are here

function abjs_schema in A/B Test JS 8

Same name and namespace in other branches
  1. 7 abjs.install \abjs_schema()
  2. 2.0.x abjs.install \abjs_schema()

Implements hook_schema().

File

./abjs.install, line 31
Install, update and uninstall functions for the abjs module.

Code

function abjs_schema() {
  $schema = [];

  // Validate if exists the principal table, else create.
  if (\Drupal::database()
    ->schema()
    ->tableExists('abjs_test')) {
    return $schema;
  }
  $schema['abjs_test'] = [
    'description' => 'The table for a/b tests.',
    'fields' => [
      'tid' => [
        'description' => 'The primary identifier for a test.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'name' => [
        'description' => 'The name of this test.',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ],
      'active' => [
        'description' => 'Boolean indicating whether the test is active or not.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'created' => [
        'description' => 'The Unix timestamp when the test was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'created_by' => [
        'description' => 'The uid of the user who created the test.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'changed' => [
        'description' => 'The Unix timestamp when the test was most recently saved.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'changed_by' => [
        'description' => 'The uid of the user who last modified the test.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => [
      'tid',
    ],
  ];
  $schema['abjs_experience'] = [
    'description' => 'The table for a/b test experiences.',
    'fields' => [
      'eid' => [
        'description' => 'The primary identifier for an experience.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'name' => [
        'description' => 'The name of this experience.',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ],
      'script' => [
        'description' => 'The JavaScript for this experience.',
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
      ],
      'created' => [
        'description' => 'The Unix timestamp when the experience was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'created_by' => [
        'description' => 'The uid of the user who created the experience.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'changed' => [
        'description' => 'The Unix timestamp when the experience was most recently saved.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'changed_by' => [
        'description' => 'The uid of the user who last modified the experience.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => [
      'eid',
    ],
  ];
  $schema['abjs_condition'] = [
    'description' => 'The table for a/b test conditions.',
    'fields' => [
      'cid' => [
        'description' => 'The primary identifier for a condition.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'name' => [
        'description' => 'The name of this condition.',
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ],
      'script' => [
        'description' => 'The JavaScript for this condition.',
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
      ],
      'created' => [
        'description' => 'The Unix timestamp when the condition was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'created_by' => [
        'description' => 'The uid of the user who created the condition.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'changed' => [
        'description' => 'The Unix timestamp when the condition was most recently saved.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'changed_by' => [
        'description' => 'The uid of the user who last modified the condition.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'primary key' => [
      'cid',
    ],
  ];
  $schema['abjs_test_experience'] = [
    'description' => 'The table associating a/b tests with experiences.',
    'fields' => [
      'teid' => [
        'description' => 'The primary identifier for the test_experience table.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'tid' => [
        'description' => 'The test.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'eid' => [
        'description' => 'The experience.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'fraction' => [
        'description' => 'The fraction of this test assigned to this experience.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ],
    ],
    'foreign keys' => [
      'test' => [
        'table' => 'test',
        'columns' => [
          'tid' => 'tid',
        ],
      ],
      'experience' => [
        'table' => 'experience',
        'columns' => [
          'eid' => 'eid',
        ],
      ],
    ],
    'primary key' => [
      'teid',
    ],
  ];
  $schema['abjs_test_condition'] = [
    'description' => 'The table associating a/b tests with conditions.',
    'fields' => [
      'tcid' => [
        'description' => 'The primary identifier for the test_condition table.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'tid' => [
        'description' => 'The test.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'cid' => [
        'description' => 'The condition.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'foreign keys' => [
      'test' => [
        'table' => 'test',
        'columns' => [
          'tid' => 'tid',
        ],
      ],
      'condition' => [
        'table' => 'condition',
        'columns' => [
          'cid' => 'cid',
        ],
      ],
    ],
    'primary key' => [
      'tcid',
    ],
  ];
  return $schema;
}