You are here

function computing_schema in Drupal Computing 7

Same name and namespace in other branches
  1. 7.2 computing.install \computing_schema()

Implements hook_schema().

See also

[#1744340] for information about large input/output causes PHP out of memory.

2 calls to computing_schema()
computing_update_7004 in ./computing.install
computing_update_7005 in ./computing.install

File

./computing.install, line 12
Drupal Computing installation file.

Code

function computing_schema() {
  $schema = array();
  $schema['computing_record'] = array(
    'description' => 'Stores computing command record.',
    'fields' => array(
      // core fields
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Unique auto increment computing record id',
      ),
      'app' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'length' => 50,
        'description' => 'Application that generates/executes a set of commands',
      ),
      'command' => array(
        'type' => 'varchar',
        'not null' => TRUE,
        'length' => 50,
        'description' => 'Command to be executed, no parameters',
      ),
      'description' => array(
        'type' => 'varchar',
        'not null' => FALSE,
        'length' => 200,
        'description' => 'Human readable text to explain the command to users',
      ),
      'uid' => array(
        'type' => 'int',
        'not null' => FALSE,
        'unsigned' => TRUE,
        'description' => "FK User's {users}.uid, if any. If no uid, set to null",
      ),
      'nid' => array(
        'type' => 'int',
        'not null' => FALSE,
        'unsigned' => TRUE,
        'description' => "Related node if for this command, if any. If no nid, set it to null",
      ),
      'created' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
        'description' => 'Unix timestamp this command is created',
      ),
      // parameters and results
      'input' => array(
        'type' => 'blob',
        'size' => 'big',
        'not null' => FALSE,
        'description' => 'Input parameters for this command. Serialized PHP object.',
      ),
      'output' => array(
        'type' => 'blob',
        'size' => 'big',
        'not null' => FALSE,
        'description' => 'Return results for this command. Serialized PHP object.',
      ),
      // the json input/output is useful because then we know it's json and can display them in readable format.
      // use the name inputjson rather than input_json in order to facilitate Gson in Java.
      // attention: both inputjson/outputjson could be too big to handle in PHP due to PHP memory_limit.
      // if that happens, you should save extra data to your own db tables, rather than dump them into input/output json.
      'inputjson' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
        'description' => 'JSON input parameters for this command.',
      ),
      'outputjson' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
        'description' => 'JSON output parameters for this command.',
      ),
      'id1' => array(
        'type' => 'int',
        'not null' => FALSE,
        'description' => "Optional ID, suggested for input",
      ),
      'id2' => array(
        'type' => 'int',
        'not null' => FALSE,
        'description' => "Optional ID, suggested for output",
      ),
      'id3' => array(
        'type' => 'int',
        'not null' => FALSE,
        'description' => "Optional ID, suggested for input",
      ),
      'id4' => array(
        'type' => 'int',
        'not null' => FALSE,
        'description' => "Optional ID, suggested for output",
      ),
      'ids1' => array(
        'type' => 'varchar',
        'length' => 20,
        'not null' => FALSE,
        'description' => "Optional string ID, suggested for input",
      ),
      'ids2' => array(
        'type' => 'varchar',
        'length' => 20,
        'not null' => FALSE,
        'description' => "Optional string ID, suggested for output",
      ),
      'ids3' => array(
        'type' => 'varchar',
        'length' => 20,
        'not null' => FALSE,
        'description' => "Optional string ID, suggested for input",
      ),
      'ids4' => array(
        'type' => 'varchar',
        'length' => 20,
        'not null' => FALSE,
        'description' => "Optional string ID, suggested for output",
      ),
      'number1' => array(
        'type' => 'float',
        'not null' => FALSE,
        'description' => "Optional number, suggested for input",
      ),
      'number2' => array(
        'type' => 'float',
        'not null' => FALSE,
        'description' => "Optional number, suggested for output",
      ),
      'number3' => array(
        'type' => 'float',
        'not null' => FALSE,
        'description' => "Optional number, suggested for input",
      ),
      'number4' => array(
        'type' => 'float',
        'not null' => FALSE,
        'description' => "Optional number, suggested for output",
      ),
      'string1' => array(
        'type' => 'varchar',
        'length' => 2000,
        'not null' => FALSE,
        'description' => "Optional string, suggested for input",
      ),
      'string2' => array(
        'type' => 'varchar',
        'length' => 2000,
        'not null' => FALSE,
        'description' => "Optional string, suggested for output",
      ),
      'string3' => array(
        'type' => 'varchar',
        'length' => 2000,
        'not null' => FALSE,
        'description' => "Optional string, suggested for input",
      ),
      'string4' => array(
        'type' => 'varchar',
        'length' => 2000,
        'not null' => FALSE,
        'description' => "Optional string, suggested for output",
      ),
      // currently not used.
      // 'dependency'  => array('type' => 'int', 'not null' => FALSE, 'unsigned' => TRUE, 'description' => 'For serialized execution sequence, this links to the id of dependent command',),
      // 'session'     => array('type' => 'varchar', 'length' => 100, 'not null' => FALSE, 'description' => "Optional session id to identify the session of a command",), // session id, not implemented yet.
      // running status, message, control, misc
      'status' => array(
        'type' => 'char',
        'length' => 4,
        'not null' => FALSE,
        'description' => 'Status code of the command, see code in Java',
      ),
      'control' => array(
        'type' => 'char',
        'length' => 4,
        'not null' => FALSE,
        'description' => 'Control signal to send to the running command, see code in Java',
      ),
      'message' => array(
        'type' => 'text',
        'not null' => FALSE,
        'description' => 'Human readable message for users about the execution results',
      ),
      'weight' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'unsigned' => FALSE,
        'description' => 'Similar to the module weight, 0 is normal, small number has higher priority',
      ),
      'agent' => array(
        'type' => 'varchar',
        'length' => 20,
        'not null' => FALSE,
        'description' => "The agent that execute the command, usually is the machine id",
      ),
      'start' => array(
        'type' => 'int',
        'not null' => FALSE,
        'unsigned' => TRUE,
        'description' => 'Timestamp when the command is executed, perhaps has timezone difference from created',
      ),
      'end' => array(
        'type' => 'int',
        'not null' => FALSE,
        'unsigned' => TRUE,
        'description' => 'Timestamp when the command is done',
      ),
      'updated' => array(
        'type' => 'int',
        'not null' => FALSE,
        'unsigned' => TRUE,
        'description' => 'Signal timestamp, used to show how much time is spent running up to the checkpoint',
      ),
      'progress' => array(
        'type' => 'float',
        'not null' => FALSE,
        'unsigned' => TRUE,
        'description' => '(0,1) float number to show the progress of the command',
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'indexes' => array(
      'app_index' => array(
        'app',
      ),
      'priority_index' => array(
        'weight',
        'created',
      ),
    ),
    'foreign keys' => array(
      'user_uid' => array(
        'table' => 'users',
        'columns' => array(
          'uid' => 'uid',
        ),
      ),
    ),
  );
  return $schema;
}