You are here

function location_schema in Location 7.3

Same name and namespace in other branches
  1. 6.3 location.install \location_schema()
  2. 7.5 location.install \location_schema()
  3. 7.4 location.install \location_schema()

Implements of hook_schema().

1 call to location_schema()
location_update_7302 in ./location.install
Adds the Country code to name table "location_country".

File

./location.install, line 34
Install, update and uninstall functions for the location module.

Code

function location_schema() {
  $schema['location'] = array(
    'description' => 'Locational data managed by location.module.',
    'fields' => array(
      'lid' => array(
        'description' => 'Primary Key: Unique location ID.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'Place Name.',
        'type' => 'varchar',
        'length' => 255,
        'default' => '',
        'not null' => TRUE,
      ),
      'street' => array(
        'description' => 'Street address, line 1.',
        'type' => 'varchar',
        'length' => 255,
        'default' => '',
        'not null' => TRUE,
      ),
      'additional' => array(
        'description' => 'Street address, line 2.',
        'type' => 'varchar',
        'length' => 255,
        'default' => '',
        'not null' => TRUE,
      ),
      'city' => array(
        'description' => 'City.',
        'type' => 'varchar',
        'length' => 255,
        'default' => '',
        'not null' => TRUE,
      ),
      'province' => array(
        'description' => 'State / Province code.',
        'type' => 'varchar',
        'length' => 16,
        'default' => '',
        'not null' => TRUE,
      ),
      'postal_code' => array(
        'description' => 'Postal / ZIP code.',
        'type' => 'varchar',
        'length' => 16,
        'default' => '',
        'not null' => TRUE,
      ),
      'country' => array(
        'description' => 'Two letter ISO country code.',
        'type' => 'char',
        'length' => 2,
        'not null' => TRUE,
        'default' => '',
      ),
      'latitude' => array(
        'description' => 'Location latitude (decimal degrees).',
        'type' => 'numeric',
        'precision' => 10,
        // @todo Shouldn't these all be 7?
        'scale' => 6,
        'not null' => TRUE,
        'default' => 0.0,
      ),
      'longitude' => array(
        'description' => 'Location longitude (decimal degrees).',
        'type' => 'numeric',
        'precision' => 10,
        'scale' => 6,
        'not null' => TRUE,
        'default' => 0.0,
      ),
      'source' => array(
        'description' => 'Source of the latitude and longitude data (Geocoder, user entered, invalid, etc.)',
        'type' => 'int',
        'size' => 'tiny',
        'default' => 0,
        'not null' => TRUE,
      ),
      // @@@ Historical civicrm field that isn't applicable to location, I think..
      'is_primary' => array(
        'description' => 'Is this the primary location of an object? (unused, civicrm legacy field?).',
        'type' => 'int',
        'size' => 'tiny',
        'default' => 0,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'lid',
    ),
  );
  $schema['location_instance'] = array(
    'description' => 'N:M join table to join locations to other tables.',
    'fields' => array(
      'nid' => array(
        'description' => 'Reference to {node}.nid.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'vid' => array(
        'description' => 'Reference to {node_revision}.vid.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'uid' => array(
        'description' => 'Reference to {users}.uid.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'genid' => array(
        'description' => 'Generic reference key.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'lid' => array(
        'description' => 'Reference to {location}.lid.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'nid' => array(
        'nid',
      ),
      'vid' => array(
        'vid',
      ),
      'uid' => array(
        'uid',
      ),
      'genid' => array(
        'genid',
      ),
      'lid' => array(
        'lid',
      ),
    ),
  );
  $schema['zipcodes'] = array(
    'description' => 'Location.module zipcode database.',
    'fields' => array(
      'zip' => array(
        'description' => 'Postal / ZIP code.',
        'type' => 'varchar',
        'length' => 16,
        'not null' => TRUE,
        'default' => '0',
      ),
      'city' => array(
        'description' => 'City.',
        'type' => 'varchar',
        'length' => 30,
        'not null' => TRUE,
        'default' => '',
      ),
      'state' => array(
        'description' => 'Province / State.',
        'type' => 'varchar',
        'length' => 30,
        'not null' => TRUE,
        'default' => '',
      ),
      'latitude' => array(
        'description' => 'Location latitude (decimal degrees).',
        'type' => 'numeric',
        'precision' => 10,
        'scale' => 6,
        'not null' => TRUE,
        'default' => 0.0,
      ),
      'longitude' => array(
        'description' => 'Location longitude (decimal degrees).',
        'type' => 'numeric',
        'precision' => 10,
        'scale' => 6,
        'not null' => TRUE,
        'default' => 0.0,
      ),
      // @@@ Not used, an artifact of the original data dump format.
      'timezone' => array(
        'description' => 'Timezone (unused).',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      // @@@ Not used, an artifact of the original data dump format.
      'dst' => array(
        'description' => 'Daylight Savings Time (unused).',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'country' => array(
        'description' => 'Two letter ISO country code.',
        'type' => 'char',
        'length' => 2,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    // @@@ This pk is invalid, see issue queue.
    // 'primary key' => array('country', 'zip').
    // @@@ These need reworked.
    'indexes' => array(
      'pc' => array(
        'country',
        'zip',
      ),
      'zip' => array(
        'zip',
      ),
      // @@@ No combined one?
      'latitude' => array(
        'latitude',
      ),
      'longitude' => array(
        'longitude',
      ),
      'country' => array(
        'country',
      ),
    ),
  );

  // Copied from system.module.
  $schema['cache_location'] = array(
    'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
    'fields' => array(
      'cid' => array(
        'description' => 'Primary Key: Unique cache ID.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'data' => array(
        'description' => 'A collection of data to cache.',
        'type' => 'blob',
        'not null' => FALSE,
        'size' => 'big',
      ),
      'expire' => array(
        'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'created' => array(
        'description' => 'A Unix timestamp indicating when the cache entry was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'headers' => array(
        'description' => 'Any custom HTTP headers to be added to cached data.',
        'type' => 'text',
        'not null' => FALSE,
      ),
      'serialized' => array(
        'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
        'type' => 'int',
        'size' => 'small',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'indexes' => array(
      'expire' => array(
        'expire',
      ),
    ),
    'primary key' => array(
      'cid',
    ),
  );

  // New location country table (needed for sorting).
  $schema['location_country'] = array(
    'description' => 'Country data managed by location.module.',
    'fields' => array(
      'code' => array(
        'description' => 'Primary Key: Two letter ISO Country Code',
        'type' => 'char',
        'length' => 2,
        'not null' => TRUE,
      ),
      'name' => array(
        'description' => 'Full Country Name ',
        'type' => 'varchar',
        'length' => 255,
        'default' => '',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'code',
    ),
  );
  return $schema;
}