1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DH\DoctrineAuditBundle\Helper; |
4
|
|
|
|
5
|
|
|
class SchemaHelper |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Return columns of audit tables. |
9
|
|
|
* |
10
|
|
|
* @return array |
11
|
|
|
*/ |
12
|
|
|
public static function getAuditTableColumns(): array |
13
|
|
|
{ |
14
|
|
|
return [ |
15
|
|
|
'id' => [ |
16
|
|
|
'type' => DoctrineHelper::getDoctrineType('INTEGER'), |
17
|
|
|
'options' => [ |
18
|
|
|
'autoincrement' => true, |
19
|
|
|
'unsigned' => true, |
20
|
|
|
], |
21
|
|
|
], |
22
|
|
|
'type' => [ |
23
|
|
|
'type' => DoctrineHelper::getDoctrineType('STRING'), |
24
|
|
|
'options' => [ |
25
|
|
|
'notnull' => true, |
26
|
|
|
'length' => 10, |
27
|
|
|
], |
28
|
|
|
], |
29
|
|
|
'object_id' => [ |
30
|
|
|
'type' => DoctrineHelper::getDoctrineType('STRING'), |
31
|
|
|
'options' => [ |
32
|
|
|
'notnull' => true, |
33
|
|
|
], |
34
|
|
|
], |
35
|
|
|
'discriminator' => [ |
36
|
|
|
'type' => DoctrineHelper::getDoctrineType('STRING'), |
37
|
|
|
'options' => [ |
38
|
|
|
'default' => null, |
39
|
|
|
'notnull' => false, |
40
|
|
|
], |
41
|
|
|
], |
42
|
|
|
'transaction_hash' => [ |
43
|
|
|
'type' => DoctrineHelper::getDoctrineType('STRING'), |
44
|
|
|
'options' => [ |
45
|
|
|
'notnull' => false, |
46
|
|
|
'length' => 40, |
47
|
|
|
], |
48
|
|
|
], |
49
|
|
|
'diffs' => [ |
50
|
|
|
'type' => DoctrineHelper::getDoctrineType('JSON'), |
51
|
|
|
'options' => [ |
52
|
|
|
'default' => null, |
53
|
|
|
'notnull' => false, |
54
|
|
|
], |
55
|
|
|
], |
56
|
|
|
'blame_id' => [ |
57
|
|
|
'type' => DoctrineHelper::getDoctrineType('STRING'), |
58
|
|
|
'options' => [ |
59
|
|
|
'default' => null, |
60
|
|
|
'notnull' => false, |
61
|
|
|
], |
62
|
|
|
], |
63
|
|
|
'blame_user' => [ |
64
|
|
|
'type' => DoctrineHelper::getDoctrineType('STRING'), |
65
|
|
|
'options' => [ |
66
|
|
|
'default' => null, |
67
|
|
|
'notnull' => false, |
68
|
|
|
'length' => 255, |
69
|
|
|
], |
70
|
|
|
], |
71
|
|
|
'blame_user_fqdn' => [ |
72
|
|
|
'type' => DoctrineHelper::getDoctrineType('STRING'), |
73
|
|
|
'options' => [ |
74
|
|
|
'default' => null, |
75
|
|
|
'notnull' => false, |
76
|
|
|
'length' => 255, |
77
|
|
|
], |
78
|
|
|
], |
79
|
|
|
'blame_user_firewall' => [ |
80
|
|
|
'type' => DoctrineHelper::getDoctrineType('STRING'), |
81
|
|
|
'options' => [ |
82
|
|
|
'default' => null, |
83
|
|
|
'notnull' => false, |
84
|
|
|
'length' => 100, |
85
|
|
|
], |
86
|
|
|
], |
87
|
|
|
'ip' => [ |
88
|
|
|
'type' => DoctrineHelper::getDoctrineType('STRING'), |
89
|
|
|
'options' => [ |
90
|
|
|
'default' => null, |
91
|
|
|
'notnull' => false, |
92
|
|
|
'length' => 45, |
93
|
|
|
], |
94
|
|
|
], |
95
|
|
|
'created_at' => [ |
96
|
|
|
'type' => DoctrineHelper::getDoctrineType('DATETIME_IMMUTABLE'), |
97
|
|
|
'options' => [ |
98
|
|
|
'notnull' => true, |
99
|
|
|
], |
100
|
|
|
], |
101
|
|
|
]; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Return indices of an audit table. |
106
|
|
|
* |
107
|
|
|
* @param string $tablename |
108
|
|
|
* |
109
|
|
|
* @return array |
110
|
|
|
*/ |
111
|
|
|
public static function getAuditTableIndices(string $tablename): array |
112
|
|
|
{ |
113
|
|
|
return [ |
114
|
|
|
'id' => [ |
115
|
|
|
'type' => 'primary', |
116
|
|
|
], |
117
|
|
|
'type' => [ |
118
|
|
|
'type' => 'index', |
119
|
|
|
'name' => 'type_'.md5($tablename).'_idx', |
120
|
|
|
], |
121
|
|
|
'object_id' => [ |
122
|
|
|
'type' => 'index', |
123
|
|
|
'name' => 'object_id_'.md5($tablename).'_idx', |
124
|
|
|
], |
125
|
|
|
'discriminator' => [ |
126
|
|
|
'type' => 'index', |
127
|
|
|
'name' => 'discriminator_'.md5($tablename).'_idx', |
128
|
|
|
], |
129
|
|
|
'transaction_hash' => [ |
130
|
|
|
'type' => 'index', |
131
|
|
|
'name' => 'transaction_hash_'.md5($tablename).'_idx', |
132
|
|
|
], |
133
|
|
|
'blame_id' => [ |
134
|
|
|
'type' => 'index', |
135
|
|
|
'name' => 'blame_id_'.md5($tablename).'_idx', |
136
|
|
|
], |
137
|
|
|
'created_at' => [ |
138
|
|
|
'type' => 'index', |
139
|
|
|
'name' => 'created_at_'.md5($tablename).'_idx', |
140
|
|
|
], |
141
|
|
|
]; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|