You are here

function salesforce_mapping_schema in Salesforce Suite 7.3

Implements hook_schema().

1 call to salesforce_mapping_schema()
salesforce_mapping_update_7301 in modules/salesforce_mapping/salesforce_mapping.install
Update Salesforce Mappings with new record type configuration.

File

modules/salesforce_mapping/salesforce_mapping.install, line 34
Install and uninstall instructions for salesforce_mapping.

Code

function salesforce_mapping_schema() {

  // Salesforce mapping table.
  $schema['salesforce_mapping'] = array(
    'description' => 'Drupal to Salesforce mappings',
    'fields' => array(
      'salesforce_mapping_id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique salesforce_mapping entity ID.',
      ),
      'name' => array(
        'description' => 'The machine-readable name of this salesforce_mapping type.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
      'label' => array(
        'description' => 'The human-readable name of this salesforce_mapping type.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
      'type' => array(
        'description' => 'The type/bundle of this salesforce_mapping.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'sync_triggers' => array(
        'description' => 'Indicates when the sync should take place.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0x0,
        'size' => 'tiny',
      ),
      'salesforce_object_type' => array(
        'description' => 'The Salesforce object type for this mapping.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'salesforce_record_types_allowed' => array(
        'description' => 'The Salesforce record types available for this mapping.',
        'type' => 'blob',
        'size' => 'big',
        'serialize' => TRUE,
      ),
      'salesforce_record_type_default' => array(
        'description' => 'The default Salesforce record type for this mapping.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'drupal_entity_type' => array(
        'description' => 'The Drupal entity type for this mapping (e.g. "node", "user").',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'drupal_bundle' => array(
        'description' => 'The Drupal bundle for this mapping (e.g. "page", "user")',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'dedupe_key' => array(
        'description' => 'The SF field to be used as primary key for upserts',
        'type' => 'varchar',
        'length' => '128',
        'not null' => TRUE,
        'default' => '',
      ),
      'field_mappings' => array(
        'type' => 'text',
        'serialize' => TRUE,
        'size' => 'big',
        'description' => 'A serialized object that stores the field mappings.',
      ),
      'pull_trigger_date' => array(
        'description' => 'The Saleforce field to trigger pulls from.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => 'LastModifiedDate',
      ),
      'push_async' => array(
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Indicates this mapping should be processed asynchronously.',
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the salesforce_mapping was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
        'description' => 'The weight of this salesforce_mapping type in relation to others.',
      ),
      // Following fields are for supporting exportable status.
      'locked' => array(
        'description' => 'A boolean indicating whether the administrator may delete this mapping.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'size' => 'tiny',
      ),
      'status' => array(
        'type' => 'int',
        'not null' => TRUE,
        // Set the default to ENTITY_CUSTOM without using the constant as it is
        // not safe to use it at this point.
        'default' => 0x1,
        'size' => 'tiny',
        'description' => 'The exportable status of the entity.',
      ),
      'module' => array(
        'description' => 'The name of the providing module if the entity has been defined in code.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'salesforce_mapping_id',
    ),
    'unique keys' => array(
      'name' => array(
        'name',
      ),
    ),
    'indexes' => array(
      'name_sf_type_drupal_type' => array(
        'drupal_entity_type',
        'drupal_bundle',
        'salesforce_object_type',
      ),
    ),
  );

  // Object mapping table.
  $schema['salesforce_mapping_object'] = array(
    'description' => 'Drupal to Salesforce object mappings',
    'fields' => array(
      'salesforce_mapping_object_id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique salesforce_mapping_object entity ID.',
      ),
      'revision_id' => array(
        'description' => 'The current {salesforce_mapping_object_revision}.revision_id version identifier.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'salesforce_id' => array(
        'description' => 'Salesforce object identifier',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'entity_id' => array(
        'description' => 'Drupal entity Id.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'entity_type' => array(
        'description' => 'Drupal entity type.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the object mapping was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'entity_updated' => array(
        'description' => 'The Unix timestamp when the mapped Drupal entity was last updated.',
        'type' => 'int',
        'not null' => FALSE,
        'default' => 0,
      ),
      'last_sync' => array(
        'description' => 'The Unix timestamp when the record was last synced with Salesforce.',
        'type' => 'int',
        'not null' => FALSE,
        'default' => 0,
      ),
      'last_sync_action' => array(
        'description' => 'The last sync action (typically push or pull).',
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
      ),
      'last_sync_status' => array(
        'description' => 'The last sync status.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
        'unsigned' => TRUE,
      ),
      'last_sync_message' => array(
        'description' => 'The message returned from the last sync activity',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'salesforce_mapping_object_id',
    ),
    'indexes' => array(
      'drupal_entity' => array(
        'entity_type',
        'entity_id',
      ),
      'salesforce_object' => array(
        'salesforce_id',
      ),
      'salesforce_mapping_object_revision' => array(
        'revision_id',
      ),
    ),
    'unique keys' => array(
      'salesforce' => array(
        'salesforce_id',
      ),
      'salesforce_drupal' => array(
        'entity_type',
        'entity_id',
      ),
      'revision_id' => array(
        'revision_id',
      ),
    ),
    'foreign keys' => array(
      'salesforce_mapping_object_revision' => array(
        'table' => 'salesforce_mapping_object_revision',
        'columns' => array(
          'revision_id' => 'revision_id',
        ),
      ),
    ),
  );
  $schema['salesforce_mapping_object_revision'] = array(
    'description' => 'Stores information about each saved version of a {salesforce_mapping_object}.',
    'fields' => array(
      'salesforce_mapping_object_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Primary Key: Unique salesforce_mapping_object entity ID.',
      ),
      'revision_id' => array(
        'description' => 'The current {salesforce_mapping_object_revision}.revision_id version identifier.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'salesforce_id' => array(
        'description' => 'Salesforce object identifier',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'entity_id' => array(
        'description' => 'Drupal entity Id.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'entity_type' => array(
        'description' => 'Drupal entity type.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the object mapping was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'entity_updated' => array(
        'description' => 'The Unix timestamp when the mapped Drupal entity was last updated.',
        'type' => 'int',
        'not null' => FALSE,
        'default' => 0,
      ),
      'last_sync' => array(
        'description' => 'The Unix timestamp when the record was last synced with Salesforce.',
        'type' => 'int',
        'not null' => FALSE,
        'default' => 0,
      ),
      'last_sync_action' => array(
        'description' => 'The last sync action (typically push or pull).',
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
      ),
      'last_sync_status' => array(
        'description' => 'The last sync status.',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 1,
        // 1 = Success
        'unsigned' => TRUE,
      ),
      'last_sync_message' => array(
        'description' => 'The message returned from the last sync activity',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'revision_id',
    ),
    'indexes' => array(
      'drupal_entity' => array(
        'entity_type',
        'entity_id',
      ),
      'salesforce_object' => array(
        'salesforce_id',
      ),
      'salesforce_mapping_object_id' => array(
        'salesforce_mapping_object_id',
      ),
    ),
    'foreign keys' => array(
      'salesforce_mapping_object' => array(
        'table' => 'salesforce_mapping_object',
        'columns' => array(
          'salesforce_mapping_object_id' => 'salesforce_mapping_object_id',
        ),
      ),
    ),
  );
  return $schema;
}