Commit 2edb2076 authored by Binny Thomas's avatar Binny Thomas Committed by Binny Thomas
Browse files

Issue #3309635 by binnythomas: Add hook install with schema

parent 46ff8951
Loading
Loading
Loading
Loading

uber_affiliate.install

0 → 100644
+197 −0
Original line number Diff line number Diff line
<?php

/**
 * Implements of hook_schema().
 */
function uber_affiliate_schema() {
  $schema['affiliate'] = array(
    'description' => 'Affiliate info',
    'fields' => array(
      'uid' => array(
        'description' => 'Affiliate UID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'active' => array(
        'description' => 'Affiliate status',
        'type' => 'int',
        'unsigned' => TRUE,
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 1,
      ),
      'created' => array(
        'description' => 'Timestamp when user became an affiliate',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'clicks' => array(
        'description' => 'Number of clicks originating from this affiliate',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'referrals' => array(
        'description' => 'Number of users this affiliate has referred',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'payouts_owed' => array(
        'description' => 'Amount currently owed',
        'type' => 'numeric',
        'not null' => TRUE,
        'default' => 0,
        'precision' => '10',
        'scale' => '2',
      ),
      'payouts_paid' => array(
        'description' => 'Total amount of payouts this affiliate has received',
        'type' => 'numeric',
        'not null' => TRUE,
        'default' => 0,
        'precision' => '14',
        'scale' => '2',
      ),
    ),
    'primary key' => array('uid'),
    'indexes' => array(
      'active' => array('active', 'created'),
      'payouts_owed' => array('payouts_owed'),
    ),
  );

  $schema['affiliate_campaigns'] = array(
    'description' => 'Campaigns available to affiliates',
    'fields' => array(
      'cid' => array(
        'description' => 'Campaign ID',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'redirect_path' => array(
        'description' => 'Existing path this campain should redirect to.',
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'default' => '',
      ),
      'ctype' => array(
        'description' => 'Campaign type: 1 = clickthru, 2 = referral',
        'type' => 'int',
        'unsigned' => TRUE,
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 1,
      ),
      'eid' => array(
        'description' => 'Entity ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'etype' => array(
        'description' => 'Entity type',
        'type' => 'varchar',
        'length' => '50',
        'not null' => TRUE,
        'default' => 'node',
      ),
      'status' => array(
        'description' => 'Campain status: 1 = active, 0 = inactive',
        'type' => 'int',
        'unsigned' => TRUE,
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 1,
      ),
      'created' => array(
        'description' => 'Time campaign was created',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'expires' => array(
        'description' => 'Time campaign expires',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'data' => array(
        'description' => 'Data about this campaign',
        'type' => 'blob',
        'not null' => FALSE,
      ),
    ),
    'primary key' => array('cid'),
    'indexes' => array(
      'redirect_path' => array('redirect_path'),
      'ctype' => array('ctype'),
      'eid' => array('eid', 'etype'),
      'status' => array('status'),
    ),
  );

  $schema['affiliate_clicks'] = array(
    'description' => 'Affiliate click tracker',
    'fields' => array(
      'clickid' => array(
        'description' => 'Click ID',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'uid' => array(
        'description' => 'Affiliate UID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'cid' => array(
        'description' => 'Campaign ID',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'click_time' => array(
        'description' => 'Time of click',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'cookie_id' => array(
        'description' => 'Cookie ID',
        'type' => 'varchar',
        'length' => '100',
        'not null' => TRUE,
      ),
      'ip' => array(
        'description' => 'Originating IP',
        'type' => 'varchar',
        'length' => '15',
        'not null' => TRUE,
      ),
      'referrer' => array(
        'description' => 'Referring site',
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array('clickid'),
    'indexes' => array(
      'uid' => array('uid', 'cid', 'click_time'),
      'cookie_id' => array('cookie_id'),
      'ip' => array('ip'),
      'referrer' => array('referrer'),
    ),
  );

  return $schema;
}