<?php

/**
 * @file
 * Install and update hooks for commerce_autosku
 */

function commerce_autosku_schema() {
  $schema['commerce_autosku_patterns'] = array(
  'description' => 'TODO: please describe this table!',
  'export' => array(
    'key' => 'product_type',
    'key name' => 'Product Type',
    'api' => array(
      'owner' => 'commerce_autosku',
      'api' => 'autosku_pattern',
      'minimum_version' => 1,
      'current_version' => 1,
    )
  ),
  'fields' => array(
    'product_type' => array(
      'description' => 'Product type identifier.',
      'type' => 'varchar',
      'length' => 32,
      'not null' => TRUE,
    ),
    'pattern' => array(
      'description' => 'Token replacement pattern.',
      'type' => 'varchar',
      'length' => 255,
      'not null' => TRUE,
    ),
    'advanced' => array(
      'description' => 'Serialized array of additional settings.',
      'type' => 'blob',
      'not null' => FALSE,
      'size' => 'big',
      'serialize' => TRUE,
    )
  ),
  'primary key' => array('product_type'),
);
  return $schema;
}

/**
 * Change pattern field from 128 to 255 characters in commerce_autosku_patterns.
 */
function commerce_autosku_update_7101(&$sandbox) {
  $spec = array(
    'description' => 'Token replacement pattern.',
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
  );
  db_change_field('commerce_autosku_patterns', 'pattern', 'pattern', $spec);
}

/**
 * Change product_type field from 55 to 32 characters in commerce_autosku_patterns.
 */
function commerce_autosku_update_7102(&$sandbox) {
  $spec = array(
    'description' => 'Product type identifier.',
    'type' => 'varchar',
    'length' => 32,
    'not null' => TRUE,
  );
  db_change_field('commerce_autosku_patterns', 'product_type', 'product_type', $spec);
}

function commerce_autosku_update_7103() {
  $spec = array(
    'description' => 'Token replacement pattern.',
    'type' => 'text',
    'size' => 'big',
    'not null' => TRUE,
  );
  db_change_field('commerce_autosku_patterns', 'pattern', 'pattern', $spec);
}
