-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiming_monitor.install
182 lines (163 loc) · 4.58 KB
/
timing_monitor.install
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
<?php
/**
* @file
* Install, update and uninstall functions for the timing_monitor module.
*/
use Drupal\Core\Database\Database;
/**
* Implements hook_schema().
*/
function timing_monitor_schema() {
$schema['timing_monitor_log'] = timing_monitor__timing_monitor_log_spec();
return $schema;
}
/**
* Spec for timing_monitor_log.
*/
function timing_monitor__timing_monitor_log_spec() {
return [
'description' => 'Table that contains logs of api events.',
'fields' => [
'id' => [
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique event ID.',
],
'uid' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The {users}.uid of the user who triggered the event.',
],
'session_uuid' => [
'type' => 'varchar_ascii',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'UUID for a unique session',
],
'type' => [
'type' => 'varchar_ascii',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Type of log message, for example "user" or "page not found."',
],
'marker' => [
'type' => 'varchar_ascii',
'length' => 128,
'not null' => FALSE,
'default' => NULL,
'description' => 'Type of marker. Can be start, mark, finish',
],
'message' => [
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
'description' => 'Text of log message to be passed into the t() function.',
],
'variables' => [
'type' => 'blob',
'not null' => TRUE,
'size' => 'big',
'description' => 'Serialized array of variables that match the message string and that is passed into the t() function.',
],
'path' => [
'type' => 'text',
'not null' => FALSE,
'description' => 'Api path.',
],
'method' => [
'type' => 'text',
'not null' => FALSE,
'description' => 'Method used for the call.',
],
'timer' => [
'type' => 'float',
'unsigned' => TRUE,
'size' => 'big',
'not null' => TRUE,
'description' => 'Timer for this entry',
],
'duration' => [
'type' => 'float',
'unsigned' => TRUE,
'size' => 'big',
'not null' => FALSE,
'description' => 'Duration if we have a start',
],
'timestamp' => [
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Unix timestamp of when event occurred.',
],
],
'primary key' => ['id'],
'indexes' => [
'type' => ['type'],
'uid' => ['uid'],
'uuid' => ['session_uuid'],
],
];
}
/**
* Add fields to schema.
*/
function timing_monitor_update_9001() {
$schema = Database::getConnection()->schema();
$schema->addField('timing_monitor_log', 'marker', [
'type' => 'varchar_ascii',
'length' => 64,
'not null' => FALSE,
'default' => NULL,
'description' => 'Type of marker. Can be start, mark, finish',
]);
$schema->addField('timing_monitor_log', 'duration', [
'type' => 'float',
'unsigned' => TRUE,
'size' => 'big',
'not null' => FALSE,
'description' => 'Duration if we have a start',
]);
}
/**
* Remove unused fields to schema.
*/
function timing_monitor_update_9002() {
$schema = Database::getConnection()->schema();
$schema->dropField('timing_monitor_log', 'severity');
$schema->dropIndex('timing_monitor_log', 'severity');
}
/**
* Update index on timing_monitor_log.
*/
function timing_monitor_update_9003() {
$schema = Database::getConnection()->schema();
$spec = timing_monitor__timing_monitor_log_spec();
$schema->addIndex('timing_monitor_log', 'uuid', ['session_uuid'], $spec);
}
/**
* Update config entity.
*/
function timing_monitor_update_9004() {
$config = \Drupal::configFactory()->getEditable('timing_monitor.settings');
$data = $config->getRawData();
if (isset($data['dependencies'])) {
unset($data['dependencies']);
}
$config->setData($data);
$config->save();
}
/**
* Update table/col definitions.
*
*/
function timing_monitor_update_10001() {
$database = \Drupal::database();
$schema = $database->schema();
$log_table = timing_monitor__timing_monitor_log_spec();
$schema->changeField('timing_monitor_log', 'type', 'type', $log_table['fields']['type']);
$schema->changeField('timing_monitor_log', 'marker', 'marker', $log_table['fields']['marker']);
}