You are here

function commerce_stock_local_schema in Commerce Stock 8

Implements hook_schema().

File

modules/local_storage/commerce_stock_local.install, line 14
Contains install and update functions for commerce stock local.

Code

function commerce_stock_local_schema() {
  $schema['commerce_stock_transaction_type'] = [
    'description' => 'Commerce Stock transaction types',
    'fields' => [
      'id' => [
        'description' => 'Transaction type ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'name' => [
        'description' => 'Transaction type name',
        'type' => 'varchar_ascii',
        'not null' => TRUE,
        'default' => '',
        'length' => 128,
      ],
      'parent_id' => [
        'description' => 'Parent transaction type',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
    ],
    'primary key' => [
      'id',
    ],
    'foreign keys' => [
      'parent_type' => [
        'table' => 'commerce_stock_transaction_type',
        'columns' => [
          'parent_id' => 'id',
        ],
      ],
    ],
  ];
  $schema['commerce_stock_transaction'] = [
    'description' => 'Stores inventory transactions form commerce stock.',
    'fields' => [
      'id' => [
        'description' => 'Transaction ID',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'entity_id' => [
        'description' => 'Purchasable entity ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'entity_type' => [
        'description' => 'Purchasable entity type',
        'type' => 'varchar_ascii',
        'length' => EntityTypeInterface::ID_MAX_LENGTH,
        'not null' => TRUE,
      ],
      'qty' => [
        'description' => 'Transaction quantity',
        'type' => 'numeric',
        'size' => 'normal',
        'not null' => TRUE,
        'default' => 0,
        'precision' => 10,
        'scale' => 2,
      ],
      'location_id' => [
        'description' => 'Transaction location ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'location_zone' => [
        'description' => 'Transaction location zone',
        'type' => 'varchar_ascii',
        'length' => 28,
        'not null' => TRUE,
        'default' => '',
      ],
      'unit_cost' => [
        'description' => 'Amount paid per unit',
        'type' => 'numeric',
        'size' => 'normal',
        'precision' => 19,
        'scale' => 6,
      ],
      'currency_code' => [
        'description' => 'The currency code.',
        'type' => 'varchar',
        'length' => 3,
      ],
      'transaction_time' => [
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'The date & time of the transaction',
      ],
      'transaction_type_id' => [
        'description' => 'Transaction type ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      // Metadata.
      'related_tid' => [
        'description' => 'Related transaction ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
      ],
      'related_oid' => [
        'description' => 'Related order ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
      ],
      'related_uid' => [
        'description' => 'Related user ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
      ],
      'data' => [
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
        'description' => 'Serialized data array',
      ],
    ],
    'primary key' => [
      'id',
    ],
    'indexes' => [
      'entity_id__entity_type__location_id' => [
        'entity_id',
        'entity_type',
        'location_id',
      ],
    ],
    'foreign keys' => [
      'location' => [
        'table' => 'commerce_stock_location',
        'columns' => [
          'location_id' => 'location_id',
        ],
      ],
      'transaction_type' => [
        'table' => 'commerce_stock_transaction_type',
        'columns' => [
          'transaction_type_id' => 'id',
        ],
      ],
      'related_transaction' => [
        'table' => 'commerce_stock_transaction',
        'columns' => [
          'related_tid' => 'id',
        ],
      ],
      'related_order' => [
        'table' => 'commerce_order',
        'columns' => [
          'related_oid' => 'order_id',
        ],
      ],
      'related_user' => [
        'table' => 'users',
        'columns' => [
          'related_uid' => 'uid',
        ],
      ],
    ],
  ];
  $schema['commerce_stock_location_level'] = [
    'description' => 'Stock Level at a location.',
    'fields' => [
      'location_id' => [
        'description' => 'The location ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'entity_id' => [
        'description' => 'Purchasable entity ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'entity_type' => [
        'description' => 'Purchasable entity type',
        'type' => 'varchar_ascii',
        'length' => EntityTypeInterface::ID_MAX_LENGTH,
        'not null' => TRUE,
      ],
      'qty' => [
        'description' => 'The quantity',
        'type' => 'numeric',
        'size' => 'normal',
        'not null' => TRUE,
        'default' => 0,
        'precision' => 10,
        'scale' => 2,
      ],
      'last_transaction_id' => [
        'description' => 'The last transaction that was used to calculate the total quantity',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
    ],
    'primary key' => [
      'location_id',
      'entity_id',
      'entity_type',
    ],
    'foreign keys' => [
      'location' => [
        'table' => 'commerce_stock_location',
        'columns' => [
          'location_id' => 'location_id',
        ],
      ],
    ],
  ];
  return $schema;
}