You are here

function ip_geoloc_schema in IP Geolocation Views & Maps 7

Same name and namespace in other branches
  1. 8 ip_geoloc.install \ip_geoloc_schema()

Implements hook_schema().

Smart IP module provides: IP address Latitude/Longitude Country Country Code Region Region Code (usually empty for Australia) City ZIP (which we store under Postal Code)

GeoIP City provides: TBA

Google provides: TBA

Note: some of the varchar should be varbinary, see drupal.org/node/1793674

File

./ip_geoloc.install, line 180
Install and uninstall hooks for IP Geolocation Views & Maps.

Code

function ip_geoloc_schema() {
  $schema['ip_geoloc'] = array(
    'description' => 'Store visitor IP addresses and geolocation information',
    'fields' => array(
      'id' => array(
        'description' => 'Unique id',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'ip_address' => array(
        'description' => 'IP address',
        'type' => 'varchar',
        // Support IPv6 as well as standard IPv4 addresses, e.g.
        // 2001:0db8:0000:0000:0000:ff00:0042:8329
        // http://en.wikipedia.org/wiki/IPv6
        'length' => '64',
        'not null' => TRUE,
      ),
      'latitude' => array(
        'description' => 'Latitude',
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'longitude' => array(
        'description' => 'Longitude',
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'country' => array(
        'description' => 'Country',
        'type' => 'varchar',
        'length' => 64,
        'not null' => FALSE,
      ),
      'country_code' => array(
        'description' => 'ISO 3166 2-Character Country Code',
        'type' => 'varchar',
        'length' => 3,
        'not null' => FALSE,
      ),
      'region' => array(
        'description' => 'Region',
        'type' => 'varchar',
        'length' => 64,
        'not null' => FALSE,
      ),
      'region_code' => array(
        'description' => '2-Character Region Code',
        'type' => 'varchar',
        'length' => 3,
        'not null' => FALSE,
      ),
      'city' => array(
        'description' => 'City',
        'type' => 'varchar',
        'length' => 64,
        'not null' => FALSE,
      ),
      'postal_code' => array(
        'description' => 'Post code',
        'type' => 'varchar',
        'length' => 12,
        'not null' => FALSE,
      ),
      'locality' => array(
        'description' => 'Suburb',
        'type' => 'varchar',
        'length' => 64,
        'not null' => FALSE,
      ),
      'route' => array(
        'description' => 'Street',
        'type' => 'varchar',
        'length' => 64,
        'not null' => FALSE,
      ),
      'street_number' => array(
        'description' => 'Street number',
        'type' => 'varchar',
        'length' => 32,
        'not null' => FALSE,
      ),
      'administrative_area_level_1' => array(
        'description' => 'State or province',
        'type' => 'varchar',
        'length' => 64,
        'not null' => FALSE,
      ),
      'formatted_address' => array(
        'description' => 'Address',
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'indexes' => array(
      'ip_address' => array(
        'ip_address',
      ),
    ),
  );
  return $schema;
}