|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Tests\Provider; |
|
6
|
|
|
|
|
7
|
|
|
use PDO; |
|
8
|
|
|
use Yiisoft\Db\Constraint\CheckConstraint; |
|
9
|
|
|
use Yiisoft\Db\Constraint\Constraint; |
|
10
|
|
|
use Yiisoft\Db\Constraint\ForeignKeyConstraint; |
|
11
|
|
|
use Yiisoft\Db\Constraint\IndexConstraint; |
|
12
|
|
|
use Yiisoft\Db\Schema\Schema; |
|
13
|
|
|
use Yiisoft\Db\Tests\Support\AnyValue; |
|
14
|
|
|
|
|
15
|
|
|
final class BaseSchemaProvider |
|
16
|
|
|
{ |
|
17
|
|
|
public function constraints(): array |
|
18
|
|
|
{ |
|
19
|
|
|
return [ |
|
20
|
|
|
'1: primary key' => [ |
|
21
|
|
|
'T_constraints_1', |
|
22
|
|
|
Schema::PRIMARY_KEY, |
|
23
|
|
|
(new Constraint())->name(AnyValue::getInstance())->columnNames(['C_id']), |
|
24
|
|
|
], |
|
25
|
|
|
'1: check' => [ |
|
26
|
|
|
'T_constraints_1', |
|
27
|
|
|
Schema::CHECKS, |
|
28
|
|
|
[ |
|
29
|
|
|
(new CheckConstraint()) |
|
30
|
|
|
->name(AnyValue::getInstance()) |
|
31
|
|
|
->columnNames(['C_check']) |
|
32
|
|
|
->expression("C_check <> ''"), |
|
33
|
|
|
], |
|
34
|
|
|
], |
|
35
|
|
|
'1: unique' => [ |
|
36
|
|
|
'T_constraints_1', |
|
37
|
|
|
Schema::UNIQUES, |
|
38
|
|
|
[(new Constraint())->name('CN_unique')->columnNames(['C_unique'])], |
|
39
|
|
|
], |
|
40
|
|
|
'1: index' => [ |
|
41
|
|
|
'T_constraints_1', |
|
42
|
|
|
Schema::INDEXES, |
|
43
|
|
|
[ |
|
44
|
|
|
(new IndexConstraint()) |
|
45
|
|
|
->name(AnyValue::getInstance()) |
|
46
|
|
|
->columnNames(['C_id']) |
|
47
|
|
|
->unique(true) |
|
48
|
|
|
->primary(true), |
|
49
|
|
|
(new IndexConstraint()) |
|
50
|
|
|
->name('CN_unique') |
|
51
|
|
|
->columnNames(['C_unique']) |
|
52
|
|
|
->primary(false) |
|
53
|
|
|
->unique(true), |
|
54
|
|
|
], |
|
55
|
|
|
], |
|
56
|
|
|
'1: default' => ['T_constraints_1', Schema::DEFAULT_VALUES, false], |
|
57
|
|
|
|
|
58
|
|
|
'2: primary key' => [ |
|
59
|
|
|
'T_constraints_2', |
|
60
|
|
|
Schema::PRIMARY_KEY, |
|
61
|
|
|
(new Constraint())->name('CN_pk')->columnNames(['C_id_1', 'C_id_2']), |
|
62
|
|
|
], |
|
63
|
|
|
'2: unique' => [ |
|
64
|
|
|
'T_constraints_2', |
|
65
|
|
|
Schema::UNIQUES, |
|
66
|
|
|
[(new Constraint())->name('CN_constraints_2_multi')->columnNames(['C_index_2_1', 'C_index_2_2'])], |
|
67
|
|
|
], |
|
68
|
|
|
'2: index' => [ |
|
69
|
|
|
'T_constraints_2', |
|
70
|
|
|
Schema::INDEXES, |
|
71
|
|
|
[ |
|
72
|
|
|
(new IndexConstraint()) |
|
73
|
|
|
->name(AnyValue::getInstance()) |
|
74
|
|
|
->columnNames(['C_id_1', 'C_id_2']) |
|
75
|
|
|
->unique(true) |
|
76
|
|
|
->primary(true), |
|
77
|
|
|
(new IndexConstraint()) |
|
78
|
|
|
->name('CN_constraints_2_single') |
|
79
|
|
|
->columnNames(['C_index_1']) |
|
80
|
|
|
->primary(false) |
|
81
|
|
|
->unique(false), |
|
82
|
|
|
(new IndexConstraint()) |
|
83
|
|
|
->name('CN_constraints_2_multi') |
|
84
|
|
|
->columnNames(['C_index_2_1', 'C_index_2_2']) |
|
85
|
|
|
->primary(false) |
|
86
|
|
|
->unique(true), |
|
87
|
|
|
], |
|
88
|
|
|
], |
|
89
|
|
|
'2: check' => ['T_constraints_2', Schema::CHECKS, []], |
|
90
|
|
|
'2: default' => ['T_constraints_2', Schema::DEFAULT_VALUES, false], |
|
91
|
|
|
|
|
92
|
|
|
'3: primary key' => ['T_constraints_3', Schema::PRIMARY_KEY, null], |
|
93
|
|
|
'3: foreign key' => [ |
|
94
|
|
|
'T_constraints_3', |
|
95
|
|
|
Schema::FOREIGN_KEYS, |
|
96
|
|
|
[ |
|
97
|
|
|
(new ForeignKeyConstraint()) |
|
98
|
|
|
->name('CN_constraints_3') |
|
99
|
|
|
->columnNames(['C_fk_id_1', 'C_fk_id_2']) |
|
100
|
|
|
->foreignTableName('T_constraints_2') |
|
101
|
|
|
->foreignColumnNames(['C_id_1', 'C_id_2']) |
|
102
|
|
|
->onDelete('CASCADE') |
|
103
|
|
|
->onUpdate('CASCADE'), |
|
104
|
|
|
], |
|
105
|
|
|
], |
|
106
|
|
|
'3: unique' => ['T_constraints_3', Schema::UNIQUES, []], |
|
107
|
|
|
'3: index' => [ |
|
108
|
|
|
'T_constraints_3', |
|
109
|
|
|
Schema::INDEXES, |
|
110
|
|
|
[ |
|
111
|
|
|
(new IndexConstraint()) |
|
112
|
|
|
->name('CN_constraints_3') |
|
113
|
|
|
->columnNames(['C_fk_id_1', 'C_fk_id_2']) |
|
114
|
|
|
->unique(false) |
|
115
|
|
|
->primary(false), |
|
116
|
|
|
], |
|
117
|
|
|
], |
|
118
|
|
|
'3: check' => ['T_constraints_3', Schema::CHECKS, []], |
|
119
|
|
|
'3: default' => ['T_constraints_3', Schema::DEFAULT_VALUES, false], |
|
120
|
|
|
|
|
121
|
|
|
'4: primary key' => [ |
|
122
|
|
|
'T_constraints_4', |
|
123
|
|
|
Schema::PRIMARY_KEY, |
|
124
|
|
|
(new Constraint())->name(AnyValue::getInstance())->columnNames(['C_id']), |
|
125
|
|
|
], |
|
126
|
|
|
'4: unique' => [ |
|
127
|
|
|
'T_constraints_4', |
|
128
|
|
|
Schema::UNIQUES, |
|
129
|
|
|
[(new Constraint())->name('CN_constraints_4')->columnNames(['C_col_1', 'C_col_2'])], |
|
130
|
|
|
], |
|
131
|
|
|
'4: check' => ['T_constraints_4', Schema::CHECKS, []], |
|
132
|
|
|
'4: default' => ['T_constraints_4', Schema::DEFAULT_VALUES, false], |
|
133
|
|
|
]; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function pdoAttributes(): array |
|
137
|
|
|
{ |
|
138
|
|
|
return [[[PDO::ATTR_EMULATE_PREPARES => true]], [[PDO::ATTR_EMULATE_PREPARES => false]]]; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function tableSchema(): array |
|
142
|
|
|
{ |
|
143
|
|
|
return [ |
|
144
|
|
|
['negative_default_values', 'negative_default_values'], |
|
145
|
|
|
['profile', 'profile'], |
|
146
|
|
|
]; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function tableSchemaCachePrefixes(): array |
|
150
|
|
|
{ |
|
151
|
|
|
$configs = [ |
|
152
|
|
|
['prefix' => '', 'name' => 'type'], |
|
153
|
|
|
['prefix' => '', 'name' => '{{%type}}'], |
|
154
|
|
|
['prefix' => 'ty', 'name' => '{{%pe}}'], |
|
155
|
|
|
]; |
|
156
|
|
|
|
|
157
|
|
|
$data = []; |
|
158
|
|
|
|
|
159
|
|
|
foreach ($configs as $config) { |
|
160
|
|
|
foreach ($configs as $testConfig) { |
|
161
|
|
|
if ($config === $testConfig) { |
|
162
|
|
|
continue; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
$description = sprintf( |
|
166
|
|
|
"%s (with '%s' prefix) against %s (with '%s' prefix)", |
|
167
|
|
|
$config['name'], |
|
168
|
|
|
$config['prefix'], |
|
169
|
|
|
$testConfig['name'], |
|
170
|
|
|
$testConfig['prefix'] |
|
171
|
|
|
); |
|
172
|
|
|
$data[$description] = [ |
|
173
|
|
|
$config['prefix'], |
|
174
|
|
|
$config['name'], |
|
175
|
|
|
$testConfig['prefix'], |
|
176
|
|
|
$testConfig['name'], |
|
177
|
|
|
]; |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
return $data; |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
|