mirror of
https://github.com/farmOS/farmOS.git
synced 2024-02-23 11:37:38 +01:00
271 lines
7.1 KiB
Text
271 lines
7.1 KiB
Text
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Farm plan install.
|
|
*/
|
|
|
|
/**
|
|
* Implements hook_schema().
|
|
*/
|
|
function farm_plan_schema() {
|
|
$schema['farm_plan'] = array(
|
|
'description' => 'Farm plans',
|
|
'fields' => array(
|
|
'id' => array(
|
|
'description' => 'Plan ID',
|
|
'type' => 'serial',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
'name' => array(
|
|
'description' => 'Plan name',
|
|
'type' => 'varchar',
|
|
'length' => '255',
|
|
'not null' => FALSE,
|
|
),
|
|
'type' => array(
|
|
'description' => 'Plan type',
|
|
'type' => 'varchar',
|
|
'length' => '255',
|
|
'not null' => FALSE,
|
|
),
|
|
'uid' => array(
|
|
'description' => 'Plan owner',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
),
|
|
'created' => array(
|
|
'description' => 'Timestamp when the plan was created',
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
),
|
|
'changed' => array(
|
|
'description' => 'Timestamp when the plan was last modified',
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'default' => 0,
|
|
),
|
|
'active' => array(
|
|
'description' => 'Boolean indicating whether the plan is active.',
|
|
'type' => 'int',
|
|
'size' => 'tiny',
|
|
'not null' => TRUE,
|
|
'default' => 1,
|
|
),
|
|
),
|
|
'primary key' => array('id'),
|
|
'indexes' => array(
|
|
'name' => array('name'),
|
|
'type_index' => array('type'),
|
|
'uid' => array('uid'),
|
|
'created' => array('created'),
|
|
'modified' => array('changed'),
|
|
'active' => array('active'),
|
|
),
|
|
);
|
|
$schema['farm_plan_type'] = array(
|
|
'description' => 'Stores information about all defined plan types.',
|
|
'fields' => array(
|
|
'id' => array(
|
|
'description' => 'Primary Key: Unique plan type ID.',
|
|
'type' => 'serial',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
'type' => array(
|
|
'description' => 'The machine-readable name of this plan type.',
|
|
'type' => 'varchar',
|
|
'length' => 32,
|
|
'not null' => TRUE,
|
|
),
|
|
'label' => array(
|
|
'description' => 'The human-readable name of this plan type.',
|
|
'type' => 'varchar',
|
|
'length' => 255,
|
|
'not null' => TRUE,
|
|
'default' => '',
|
|
),
|
|
|
|
// The following fields are required to make types exportable via
|
|
// Entity API and Ctools.
|
|
'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' => 0x01,
|
|
'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('id'),
|
|
'unique keys' => array(
|
|
'type' => array('type'),
|
|
),
|
|
);
|
|
$schema['farm_plan_area'] = array(
|
|
'description' => 'Areas that are linked to a plan.',
|
|
'fields' => array(
|
|
'plan_id' => array(
|
|
'description' => 'Plan ID',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
'area_id' => array(
|
|
'description' => 'Area ID',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
),
|
|
'primary key' => array('plan_id', 'area_id'),
|
|
);
|
|
$schema['farm_plan_asset'] = array(
|
|
'description' => 'Assets that are linked to a plan.',
|
|
'fields' => array(
|
|
'plan_id' => array(
|
|
'description' => 'Plan ID',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
'asset_id' => array(
|
|
'description' => 'Asset ID',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
),
|
|
'primary key' => array('plan_id', 'asset_id'),
|
|
);
|
|
$schema['farm_plan_log'] = array(
|
|
'description' => 'Logs that are linked to a plan.',
|
|
'fields' => array(
|
|
'plan_id' => array(
|
|
'description' => 'Plan ID',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
'log_id' => array(
|
|
'description' => 'Log ID',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
),
|
|
'primary key' => array('plan_id', 'log_id'),
|
|
);
|
|
$schema['farm_plan_user'] = array(
|
|
'description' => 'People that are linked to a plan.',
|
|
'fields' => array(
|
|
'plan_id' => array(
|
|
'description' => 'Plan ID',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
'user_id' => array(
|
|
'description' => 'User ID',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
),
|
|
'primary key' => array('plan_id', 'user_id'),
|
|
);
|
|
return $schema;
|
|
}
|
|
|
|
/**
|
|
* Add new database schemas for maintaining links between plans and other farmOS
|
|
* records (areas, assets, logs, and people).
|
|
*/
|
|
function farm_plan_update_7000(&$sandbox) {
|
|
$schema['farm_plan_area'] = array(
|
|
'description' => 'Areas that are linked to a plan.',
|
|
'fields' => array(
|
|
'plan_id' => array(
|
|
'description' => 'Plan ID',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
'area_id' => array(
|
|
'description' => 'Area ID',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
),
|
|
'primary key' => array('plan_id', 'area_id'),
|
|
);
|
|
$schema['farm_plan_asset'] = array(
|
|
'description' => 'Assets that are linked to a plan.',
|
|
'fields' => array(
|
|
'plan_id' => array(
|
|
'description' => 'Plan ID',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
'asset_id' => array(
|
|
'description' => 'Asset ID',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
),
|
|
'primary key' => array('plan_id', 'asset_id'),
|
|
);
|
|
$schema['farm_plan_log'] = array(
|
|
'description' => 'Logs that are linked to a plan.',
|
|
'fields' => array(
|
|
'plan_id' => array(
|
|
'description' => 'Plan ID',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
'log_id' => array(
|
|
'description' => 'Log ID',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
),
|
|
'primary key' => array('plan_id', 'log_id'),
|
|
);
|
|
$schema['farm_plan_user'] = array(
|
|
'description' => 'People that are linked to a plan.',
|
|
'fields' => array(
|
|
'plan_id' => array(
|
|
'description' => 'Plan ID',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
'user_id' => array(
|
|
'description' => 'User ID',
|
|
'type' => 'int',
|
|
'unsigned' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
),
|
|
'primary key' => array('plan_id', 'user_id'),
|
|
);
|
|
foreach ($schema as $table => $data) {
|
|
db_create_table($table, $data);
|
|
}
|
|
}
|