8
8
use Doctrine \DBAL \Platforms \PostgreSQLPlatform ;
9
9
use Doctrine \DBAL \Platforms \SQLServerPlatform ;
10
10
use Doctrine \DBAL \Schema \AbstractSchemaManager ;
11
+ use Doctrine \DBAL \Schema \Name \Identifier ;
12
+ use Doctrine \DBAL \Schema \Name \UnqualifiedName ;
13
+ use Doctrine \DBAL \Schema \PrimaryKeyConstraint ;
11
14
use Doctrine \DBAL \Schema \Table ;
12
15
use PHPUnit \Framework \Attributes \Group ;
13
16
14
17
use function array_change_key_case ;
18
+ use function class_exists ;
15
19
use function count ;
16
20
use function strtolower ;
17
21
@@ -36,12 +40,24 @@ public function testIssue2059(): void
36
40
{
37
41
$ user = new Table ('ddc2059_user ' );
38
42
$ user ->addColumn ('id ' , 'integer ' );
39
- $ user ->setPrimaryKey (['id ' ]);
43
+
44
+ if (class_exists (PrimaryKeyConstraint::class)) {
45
+ $ user ->addPrimaryKeyConstraint (new PrimaryKeyConstraint (null , [new UnqualifiedName (Identifier::unquoted ('id ' ))], true ));
46
+ } else {
47
+ $ user ->setPrimaryKey (['id ' ]);
48
+ }
49
+
40
50
$ project = new Table ('ddc2059_project ' );
41
51
$ project ->addColumn ('id ' , 'integer ' );
42
52
$ project ->addColumn ('user_id ' , 'integer ' );
43
53
$ project ->addColumn ('user ' , 'string ' );
44
- $ project ->setPrimaryKey (['id ' ]);
54
+
55
+ if (class_exists (PrimaryKeyConstraint::class)) {
56
+ $ project ->addPrimaryKeyConstraint (new PrimaryKeyConstraint (null , [new UnqualifiedName (Identifier::unquoted ('id ' ))], true ));
57
+ } else {
58
+ $ project ->setPrimaryKey (['id ' ]);
59
+ }
60
+
45
61
$ project ->addForeignKeyConstraint ('ddc2059_user ' , ['user_id ' ], ['id ' ]);
46
62
47
63
$ metadata = $ this ->convertToClassMetadata ([$ project , $ user ], []);
@@ -54,7 +70,13 @@ public function testLoadMetadataFromDatabase(): void
54
70
{
55
71
$ table = new Table ('dbdriver_foo ' );
56
72
$ table ->addColumn ('id ' , 'integer ' );
57
- $ table ->setPrimaryKey (['id ' ]);
73
+
74
+ if (class_exists (PrimaryKeyConstraint::class)) {
75
+ $ table ->addPrimaryKeyConstraint (new PrimaryKeyConstraint (null , [new UnqualifiedName (Identifier::unquoted ('id ' ))], true ));
76
+ } else {
77
+ $ table ->setPrimaryKey (['id ' ]);
78
+ }
79
+
58
80
$ table ->addColumn ('bar ' , 'string ' , ['notnull ' => false , 'length ' => 200 ]);
59
81
60
82
$ this ->dropAndCreateTable ($ table );
@@ -81,13 +103,24 @@ public function testLoadMetadataWithForeignKeyFromDatabase(): void
81
103
{
82
104
$ tableB = new Table ('dbdriver_bar ' );
83
105
$ tableB ->addColumn ('id ' , 'integer ' );
84
- $ tableB ->setPrimaryKey (['id ' ]);
106
+
107
+ if (class_exists (PrimaryKeyConstraint::class)) {
108
+ $ tableB ->addPrimaryKeyConstraint (new PrimaryKeyConstraint (null , [new UnqualifiedName (Identifier::unquoted ('id ' ))], true ));
109
+ } else {
110
+ $ tableB ->setPrimaryKey (['id ' ]);
111
+ }
85
112
86
113
$ this ->dropAndCreateTable ($ tableB );
87
114
88
115
$ tableA = new Table ('dbdriver_baz ' );
89
116
$ tableA ->addColumn ('id ' , 'integer ' );
90
- $ tableA ->setPrimaryKey (['id ' ]);
117
+
118
+ if (class_exists (PrimaryKeyConstraint::class)) {
119
+ $ tableA ->addPrimaryKeyConstraint (new PrimaryKeyConstraint (null , [new UnqualifiedName (Identifier::unquoted ('id ' ))], true ));
120
+ } else {
121
+ $ tableA ->setPrimaryKey (['id ' ]);
122
+ }
123
+
91
124
$ tableA ->addColumn ('bar_id ' , 'integer ' );
92
125
$ tableA ->addForeignKeyConstraint ('dbdriver_bar ' , ['bar_id ' ], ['id ' ]);
93
126
@@ -127,11 +160,21 @@ public function testIgnoreManyToManyTableWithoutFurtherForeignKeyDetails(): void
127
160
{
128
161
$ tableB = new Table ('dbdriver_bar ' );
129
162
$ tableB ->addColumn ('id ' , 'integer ' );
130
- $ tableB ->setPrimaryKey (['id ' ]);
163
+
164
+ if (class_exists (PrimaryKeyConstraint::class)) {
165
+ $ tableB ->addPrimaryKeyConstraint (new PrimaryKeyConstraint (null , [new UnqualifiedName (Identifier::unquoted ('id ' ))], true ));
166
+ } else {
167
+ $ tableB ->setPrimaryKey (['id ' ]);
168
+ }
131
169
132
170
$ tableA = new Table ('dbdriver_baz ' );
133
171
$ tableA ->addColumn ('id ' , 'integer ' );
134
- $ tableA ->setPrimaryKey (['id ' ]);
172
+
173
+ if (class_exists (PrimaryKeyConstraint::class)) {
174
+ $ tableA ->addPrimaryKeyConstraint (new PrimaryKeyConstraint (null , [new UnqualifiedName (Identifier::unquoted ('id ' ))], true ));
175
+ } else {
176
+ $ tableA ->setPrimaryKey (['id ' ]);
177
+ }
135
178
136
179
$ tableMany = new Table ('dbdriver_bar_baz ' );
137
180
$ tableMany ->addColumn ('bar_id ' , 'integer ' );
@@ -148,7 +191,13 @@ public function testLoadMetadataFromDatabaseDetail(): void
148
191
$ table = new Table ('dbdriver_foo ' );
149
192
150
193
$ table ->addColumn ('id ' , 'integer ' , ['unsigned ' => true ]);
151
- $ table ->setPrimaryKey (['id ' ]);
194
+
195
+ if (class_exists (PrimaryKeyConstraint::class)) {
196
+ $ table ->addPrimaryKeyConstraint (new PrimaryKeyConstraint (null , [new UnqualifiedName (Identifier::unquoted ('id ' ))], true ));
197
+ } else {
198
+ $ table ->setPrimaryKey (['id ' ]);
199
+ }
200
+
152
201
$ table ->addColumn ('column_unsigned ' , 'integer ' , ['unsigned ' => true ]);
153
202
$ table ->addColumn ('column_comment ' , 'string ' , ['length ' => 16 , 'comment ' => 'test_comment ' ]);
154
203
$ table ->addColumn ('column_default ' , 'string ' , ['length ' => 16 , 'default ' => 'test_default ' ]);
0 commit comments