aboutsummaryrefslogtreecommitdiff
path: root/muamba.install
blob: 9482a052824f9ce70dd48f9fe06b280ade19bf9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php

/**
 * @file
 * Muamba installation functions.
 */

/**
 * Implements hook_install()
 */
function muamba_install() {
}

/**
 * Implements hook_schema()
 */
function muamba_schema() {
  $schema['muamba'] = array(
    'description' => 'The base table for muamba assets.',
    'fields'      => array(
      'mid'           => array(
        'description' => t('The primary identifier for a muamba transaction.'),
        'type'        => 'serial',
        'unsigned'    => TRUE,
        'not null'    => TRUE,
      ),
      'nid'            => array(
        'description' => t('The {node}.nid of an item.'),
        'type'        => 'int',
        'unsigned'    => TRUE,
        'not null'    => TRUE,
        'default'     => 0,
      ),
      'owner'         => array(
        'description' => t('The {user}.owner owner of an item.'),
        'type'        => 'int',
        'unsigned'    => TRUE,
        'not null'    => TRUE,
        'default'     => 0,
      ),
      'uid'           => array(
        'description' => t('The {user}.uid requesting an item.'),
        'type'        => 'int',
        'unsigned'    => TRUE,
        'not null'    => TRUE,
        'default'     => 0,
      ),
      'thread_id'     => array(
        'description' => t('The {thread}.thread_id for the transaction.'),
        'type'        => 'int',
        'unsigned'    => TRUE,
        'not null'    => TRUE,
        'default'     => 0,
      ),
      'status'        => array(
        'description' => t('Transaction status.'),
        'type'        => 'int',
        'unsigned'    => TRUE,
        'not null'    => TRUE,
        'default'     => 0,
      ),
      'active'        => array(
        'description' => t('Whether it is an active transaction.'),
        'type'        => 'int',
        'unsigned'    => TRUE,
        'not null'    => TRUE,
        'default'     => 1,
      ),
      'created'       => array(
        'description' => 'Timestamp of the transaction request',
        'type'        => 'int',
        'not null'    => TRUE,
        'unsigned'    => TRUE,
        'default'     => 0,
      ),      
      'changed'       => array(
        'description' => 'Timestamp of the latest update',
        'type'        => 'int',
        'not null'    => TRUE,
        'unsigned'    => TRUE,
        'default'     => 0,
      ),      
    ),
    'foreign keys' => array(
      'node' => array(
        'table'   => 'node',
        'columns' => array('nid' => 'nid'),
      ),
      'owner' => array(
        'table'   => 'users',
        'columns' => array('owner' => 'uid'),
      ),
      'requester' => array(
        'table'   => 'users',
        'columns' => array('uid' => 'uid'),
      ),
      'thread' => array(
        'table'   => 'pm_index',
        'columns' => array('thread_id' => 'thread_id'),
      ),
    ),
    'primary key' => array('mid'),
  );

  return $schema;
}

/**
 * Adds transactional fields to muamba data model.
 */
function muamba_update_7000(&$sandbox) {
  // Make sure to not run this update twice.
  if (db_field_exists('muamba', 'mid')) {
    return;
  }

  db_add_field('muamba', 'mid',
    array(
      'description' => t('The primary identifier for a muamba transaction.'),
      'type'        => 'int',
      'not null'    => TRUE,
    )
  );

  db_add_primary_key('muamba', array('mid'));

  db_add_field('muamba', 'status',
    array(
      'description' => t('Transaction status.'),
      'type'        => 'int',
      'unsigned'    => TRUE,
      'not null'    => TRUE,
      'default'     => 0,
    )
  );

  db_add_field('muamba', 'thread_id',
    array(
      'description' => t('The {thread}.thread_id for the transaction.'),
      'type'        => 'int',
      'unsigned'    => TRUE,
      'not null'    => TRUE,
      'default'     => 0,
    ),
    array(
      'foreign keys' => array(
        'thread' => array(
          'table'   => 'pm_index',
          'columns' => array('thread_id' => 'thread_id'),
        )
      )
    )
  );
}

/**
 * Adds autoincrement to mid field.
 */
function muamba_update_7001(&$sandbox) {
  db_change_field('muamba', 'mid', 'mid',
    array(
      'type'     => 'serial',
      'not null' => TRUE,
    )
  );
}

/**
 * Adds owner field.
 */
function muamba_update_7002(&$sandbox) {
  db_add_field('muamba', 'owner',
    array(
      'description' => t('The {user}.owner owner of an item.'),
      'type'        => 'int',
      'unsigned'    => TRUE,
      'not null'    => TRUE,
      'default'     => 0,
    )
  );
}

/**
 * Adds active field.
 */
function muamba_update_7003(&$sandbox) {
  db_add_field('muamba', 'active',
    array(
      'description' => t('Whether it is an active transaction.'),
      'type'        => 'int',
      'unsigned'    => TRUE,
      'not null'    => TRUE,
      'default'     => 1,
    )
  );
}

/**
 * Adds timestamp fields.
 */
function muamba_update_7004(&$sandbox) {
  db_add_field('muamba', 'created',
    array(
      'description' => 'Timestamp of the transaction request',
      'type'        => 'int',
      'not null'    => TRUE,
      'unsigned'    => TRUE,
      'default'     => 0,
    )
  );

  db_add_field('muamba', 'changed',
    array(
      'description' => 'Timestamp of the latest update',
      'type'        => 'int',
      'not null'    => TRUE,
      'unsigned'    => TRUE,
      'default'     => 0,
      )
  );
}