Browse Source

fix mssql tests

Maurits van der Schee 5 years ago
parent
commit
1a1200a1ba

+ 29
- 9
api.php View File

2178
                 return "ALTER TABLE $p1 $p4";
2178
                 return "ALTER TABLE $p1 $p4";
2179
             case 'pgsql':
2179
             case 'pgsql':
2180
             case 'sqlsrv':
2180
             case 'sqlsrv':
2181
-                $p4 = $newColumn->getPk() ? "ADD PRIMARY KEY ($p2)" : "DROP CONSTRAINT $p3";
2181
+                $p4 = $newColumn->getPk() ? "ADD CONSTRAINT $p3 PRIMARY KEY ($p2)" : "DROP CONSTRAINT $p3";
2182
                 return "ALTER TABLE $p1 $p4";
2182
                 return "ALTER TABLE $p1 $p4";
2183
         }
2183
         }
2184
     }
2184
     }
2203
     {
2203
     {
2204
         $p1 = $this->quote($tableName);
2204
         $p1 = $this->quote($tableName);
2205
         $p2 = $this->quote($columnName);
2205
         $p2 = $this->quote($columnName);
2206
-        $p3 = $this->pdo->quote($tableName . '_' . $columnName . '_seq');
2207
-
2206
+        
2208
         switch ($this->driver) {
2207
         switch ($this->driver) {
2209
             case 'mysql':
2208
             case 'mysql':
2210
                 return "select 1";
2209
                 return "select 1";
2211
             case 'pgsql':
2210
             case 'pgsql':
2211
+                $p3 = $this->pdo->quote($tableName . '_' . $columnName . '_seq');
2212
                 return "SELECT setval($p3, (SELECT max($p2)+1 FROM $p1));";
2212
                 return "SELECT setval($p3, (SELECT max($p2)+1 FROM $p1));";
2213
             case 'sqlsrv':
2213
             case 'sqlsrv':
2214
-                return "ALTER SEQUENCE $p3 RESTART WITH (SELECT max($p2)+1 FROM $p1)";
2214
+                $p3 = $this->quote($tableName . '_' . $columnName . '_seq');
2215
+                $p4 = $this->pdo->query("SELECT max($p2)+1 FROM $p1")->fetchColumn();
2216
+                return "ALTER SEQUENCE $p3 RESTART WITH $p4";
2215
         }
2217
         }
2216
     }
2218
     }
2217
 
2219
 
2234
                 }
2236
                 }
2235
                 return "ALTER TABLE $p1 ALTER COLUMN $p2 $p4";
2237
                 return "ALTER TABLE $p1 ALTER COLUMN $p2 $p4";
2236
             case 'sqlsrv':
2238
             case 'sqlsrv':
2237
-                $p3 = $this->pdo->quote($tableName . '_' . $columnName . '_seq');
2238
-                $p4 = $this->quote('DF_' . $tableName . '_' . $columnName);
2239
+                $p3 = $this->quote($tableName . '_' . $columnName . '_seq');
2240
+                $p4 = $this->quote($tableName . '_' . $columnName . '_def');
2239
                 if ($newColumn->getPk()) {
2241
                 if ($newColumn->getPk()) {
2240
                     return "ALTER TABLE $p1 ADD CONSTRAINT $p4 DEFAULT NEXT VALUE FOR $p3 FOR $p2";
2242
                     return "ALTER TABLE $p1 ADD CONSTRAINT $p4 DEFAULT NEXT VALUE FOR $p3 FOR $p2";
2241
                 } else {
2243
                 } else {
2301
         $p2 = $this->quote($newColumn->getName());
2303
         $p2 = $this->quote($newColumn->getName());
2302
         $p3 = $this->getColumnType($newColumn, false);
2304
         $p3 = $this->getColumnType($newColumn, false);
2303
 
2305
 
2304
-        return "ALTER TABLE $p1 ADD COLUMN $p2 $p3";
2306
+        switch ($this->driver) {
2307
+            case 'mysql':
2308
+            case 'pgsql':
2309
+                return "ALTER TABLE $p1 ADD COLUMN $p2 $p3";
2310
+            case 'sqlsrv':
2311
+                return "ALTER TABLE $p1 ADD $p2 $p3";
2312
+        }
2305
     }
2313
     }
2306
 
2314
 
2307
     private function getRemoveTableSQL(String $tableName): String
2315
     private function getRemoveTableSQL(String $tableName): String
2308
     {
2316
     {
2309
         $p1 = $this->quote($tableName);
2317
         $p1 = $this->quote($tableName);
2310
 
2318
 
2311
-        return "DROP TABLE $p1 CASCADE;";
2319
+        switch ($this->driver) {
2320
+            case 'mysql':
2321
+            case 'pgsql':
2322
+                return "DROP TABLE $p1 CASCADE;";
2323
+            case 'sqlsrv':
2324
+                return "DROP TABLE $p1;";
2325
+        }
2312
     }
2326
     }
2313
 
2327
 
2314
     private function getRemoveColumnSQL(String $tableName, String $columnName): String
2328
     private function getRemoveColumnSQL(String $tableName, String $columnName): String
2316
         $p1 = $this->quote($tableName);
2330
         $p1 = $this->quote($tableName);
2317
         $p2 = $this->quote($columnName);
2331
         $p2 = $this->quote($columnName);
2318
 
2332
 
2319
-        return "ALTER TABLE $p1 DROP COLUMN $p2 CASCADE;";
2333
+        switch ($this->driver) {
2334
+            case 'mysql':
2335
+            case 'pgsql':
2336
+                return "ALTER TABLE $p1 DROP COLUMN $p2 CASCADE;";
2337
+            case 'sqlsrv':
2338
+                return "ALTER TABLE $p1 DROP COLUMN $p2;";
2339
+        }
2320
     }
2340
     }
2321
 
2341
 
2322
     public function renameTable(String $tableName, String $newTableName)
2342
     public function renameTable(String $tableName, String $newTableName)

+ 31
- 9
src/Tqdev/PhpCrudApi/Database/GenericDefinition.php View File

163
                 return "ALTER TABLE $p1 $p4";
163
                 return "ALTER TABLE $p1 $p4";
164
             case 'pgsql':
164
             case 'pgsql':
165
             case 'sqlsrv':
165
             case 'sqlsrv':
166
-                $p4 = $newColumn->getPk() ? "ADD PRIMARY KEY ($p2)" : "DROP CONSTRAINT $p3";
166
+                $p4 = $newColumn->getPk() ? "ADD CONSTRAINT $p3 PRIMARY KEY ($p2)" : "DROP CONSTRAINT $p3";
167
                 return "ALTER TABLE $p1 $p4";
167
                 return "ALTER TABLE $p1 $p4";
168
         }
168
         }
169
     }
169
     }
188
     {
188
     {
189
         $p1 = $this->quote($tableName);
189
         $p1 = $this->quote($tableName);
190
         $p2 = $this->quote($columnName);
190
         $p2 = $this->quote($columnName);
191
-        $p3 = $this->pdo->quote($tableName . '_' . $columnName . '_seq');
192
-
191
+        
193
         switch ($this->driver) {
192
         switch ($this->driver) {
194
             case 'mysql':
193
             case 'mysql':
195
                 return "select 1";
194
                 return "select 1";
196
             case 'pgsql':
195
             case 'pgsql':
196
+                $p3 = $this->pdo->quote($tableName . '_' . $columnName . '_seq');
197
                 return "SELECT setval($p3, (SELECT max($p2)+1 FROM $p1));";
197
                 return "SELECT setval($p3, (SELECT max($p2)+1 FROM $p1));";
198
             case 'sqlsrv':
198
             case 'sqlsrv':
199
-                return "ALTER SEQUENCE $p3 RESTART WITH (SELECT max($p2)+1 FROM $p1)";
199
+                $p3 = $this->quote($tableName . '_' . $columnName . '_seq');
200
+                $p4 = $this->pdo->query("SELECT max($p2)+1 FROM $p1")->fetchColumn();
201
+                return "ALTER SEQUENCE $p3 RESTART WITH $p4";
200
         }
202
         }
201
     }
203
     }
202
 
204
 
219
                 }
221
                 }
220
                 return "ALTER TABLE $p1 ALTER COLUMN $p2 $p4";
222
                 return "ALTER TABLE $p1 ALTER COLUMN $p2 $p4";
221
             case 'sqlsrv':
223
             case 'sqlsrv':
222
-                $p3 = $this->pdo->quote($tableName . '_' . $columnName . '_seq');
223
-                $p4 = $this->quote('DF_' . $tableName . '_' . $columnName);
224
+                $p3 = $this->quote($tableName . '_' . $columnName . '_seq');
225
+                $p4 = $this->quote($tableName . '_' . $columnName . '_def');
224
                 if ($newColumn->getPk()) {
226
                 if ($newColumn->getPk()) {
225
                     return "ALTER TABLE $p1 ADD CONSTRAINT $p4 DEFAULT NEXT VALUE FOR $p3 FOR $p2";
227
                     return "ALTER TABLE $p1 ADD CONSTRAINT $p4 DEFAULT NEXT VALUE FOR $p3 FOR $p2";
226
                 } else {
228
                 } else {
286
         $p2 = $this->quote($newColumn->getName());
288
         $p2 = $this->quote($newColumn->getName());
287
         $p3 = $this->getColumnType($newColumn, false);
289
         $p3 = $this->getColumnType($newColumn, false);
288
 
290
 
289
-        return "ALTER TABLE $p1 ADD COLUMN $p2 $p3";
291
+        
292
+        switch ($this->driver) {
293
+            case 'mysql':
294
+            case 'pgsql':
295
+                return "ALTER TABLE $p1 ADD COLUMN $p2 $p3";
296
+            case 'sqlsrv':
297
+                return "ALTER TABLE $p1 ADD $p2 $p3";
298
+        }
290
     }
299
     }
291
 
300
 
292
     private function getRemoveTableSQL(String $tableName): String
301
     private function getRemoveTableSQL(String $tableName): String
293
     {
302
     {
294
         $p1 = $this->quote($tableName);
303
         $p1 = $this->quote($tableName);
295
 
304
 
296
-        return "DROP TABLE $p1 CASCADE;";
305
+        switch ($this->driver) {
306
+            case 'mysql':
307
+            case 'pgsql':
308
+                return "DROP TABLE $p1 CASCADE;";
309
+            case 'sqlsrv':
310
+                return "DROP TABLE $p1;";
311
+        }
297
     }
312
     }
298
 
313
 
299
     private function getRemoveColumnSQL(String $tableName, String $columnName): String
314
     private function getRemoveColumnSQL(String $tableName, String $columnName): String
301
         $p1 = $this->quote($tableName);
316
         $p1 = $this->quote($tableName);
302
         $p2 = $this->quote($columnName);
317
         $p2 = $this->quote($columnName);
303
 
318
 
304
-        return "ALTER TABLE $p1 DROP COLUMN $p2 CASCADE;";
319
+        
320
+        switch ($this->driver) {
321
+            case 'mysql':
322
+            case 'pgsql':
323
+                return "ALTER TABLE $p1 DROP COLUMN $p2 CASCADE;";
324
+            case 'sqlsrv':
325
+                return "ALTER TABLE $p1 DROP COLUMN $p2;";
326
+        }
305
     }
327
     }
306
 
328
 
307
     public function renameTable(String $tableName, String $newTableName)
329
     public function renameTable(String $tableName, String $newTableName)

+ 104
- 61
tests/fixtures/blog_sqlsrv.sql View File

1
-IF (OBJECT_ID('FK_kunsthåndværk_users', 'F') IS NOT NULL)
1
+IF (OBJECT_ID('kunsthåndværk_user_id_fkey', 'F') IS NOT NULL)
2
 BEGIN
2
 BEGIN
3
-ALTER TABLE [kunsthåndværk] DROP	CONSTRAINT [FK_kunsthåndværk_users]
3
+ALTER TABLE [kunsthåndværk] DROP	CONSTRAINT [kunsthåndværk_user_id_fkey]
4
 END
4
 END
5
 GO
5
 GO
6
 
6
 
7
-IF (OBJECT_ID('FK_barcodes_products', 'F') IS NOT NULL)
7
+IF (OBJECT_ID('barcodes_product_id_fkey', 'F') IS NOT NULL)
8
 BEGIN
8
 BEGIN
9
-ALTER TABLE [barcodes] DROP	CONSTRAINT [FK_barcodes_products]
9
+ALTER TABLE [barcodes] DROP	CONSTRAINT [barcodes_product_id_fkey]
10
 END
10
 END
11
 GO
11
 GO
12
 
12
 
13
-IF (OBJECT_ID('FK_posts_users', 'F') IS NOT NULL)
13
+IF (OBJECT_ID('posts_user_id_fkey', 'F') IS NOT NULL)
14
 BEGIN
14
 BEGIN
15
-ALTER TABLE [posts] DROP	CONSTRAINT [FK_posts_users]
15
+ALTER TABLE [posts] DROP	CONSTRAINT [posts_user_id_fkey]
16
 END
16
 END
17
 GO
17
 GO
18
 
18
 
19
-IF (OBJECT_ID('FK_posts_categories', 'F') IS NOT NULL)
19
+IF (OBJECT_ID('posts_category_id_fkey', 'F') IS NOT NULL)
20
 BEGIN
20
 BEGIN
21
-ALTER TABLE [posts] DROP	CONSTRAINT [FK_posts_categories]
21
+ALTER TABLE [posts] DROP	CONSTRAINT [posts_category_id_fkey]
22
 END
22
 END
23
 GO
23
 GO
24
 
24
 
25
-IF (OBJECT_ID('FK_post_tags_tags', 'F') IS NOT NULL)
25
+IF (OBJECT_ID('post_tags_tag_id_fkey', 'F') IS NOT NULL)
26
 BEGIN
26
 BEGIN
27
-ALTER TABLE [post_tags] DROP	CONSTRAINT [FK_post_tags_tags]
27
+ALTER TABLE [post_tags] DROP	CONSTRAINT [post_tags_tag_id_fkey]
28
 END
28
 END
29
 GO
29
 GO
30
 
30
 
31
-IF (OBJECT_ID('FK_post_tags_posts', 'F') IS NOT NULL)
31
+IF (OBJECT_ID('post_tags_post_id_fkey', 'F') IS NOT NULL)
32
 BEGIN
32
 BEGIN
33
-ALTER TABLE [post_tags] DROP	CONSTRAINT [FK_post_tags_posts]
33
+ALTER TABLE [post_tags] DROP	CONSTRAINT [post_tags_post_id_fkey]
34
 END
34
 END
35
 GO
35
 GO
36
 
36
 
37
-IF (OBJECT_ID('FK_comments_posts', 'F') IS NOT NULL)
37
+IF (OBJECT_ID('comments_post_id_fkey', 'F') IS NOT NULL)
38
 BEGIN
38
 BEGIN
39
-ALTER TABLE [comments] DROP	CONSTRAINT [FK_comments_posts]
39
+ALTER TABLE [comments] DROP	CONSTRAINT [comments_post_id_fkey]
40
 END
40
 END
41
 GO
41
 GO
42
 
42
 
43
-IF (OBJECT_ID('FK_comments_categories', 'F') IS NOT NULL)
43
+IF (OBJECT_ID('comments_category_id_fkey', 'F') IS NOT NULL)
44
 BEGIN
44
 BEGIN
45
-ALTER TABLE [comments] DROP	CONSTRAINT [FK_comments_categories]
45
+ALTER TABLE [comments] DROP	CONSTRAINT [comments_category_id_fkey]
46
 END
46
 END
47
 GO
47
 GO
48
 
48
 
136
 END
136
 END
137
 GO
137
 GO
138
 
138
 
139
+DROP SEQUENCE IF EXISTS [categories_id_seq]
140
+GO
141
+CREATE SEQUENCE [categories_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
142
+GO
143
+
139
 CREATE TABLE [categories](
144
 CREATE TABLE [categories](
140
-	[id] [int] IDENTITY,
145
+	[id] [int] NOT NULL CONSTRAINT [categories_id_def] DEFAULT NEXT VALUE FOR [categories_id_seq],
141
 	[name] [nvarchar](255) NOT NULL,
146
 	[name] [nvarchar](255) NOT NULL,
142
 	[icon] [image],
147
 	[icon] [image],
143
-	PRIMARY KEY CLUSTERED([id] ASC)
148
+	CONSTRAINT [categories_pkey] PRIMARY KEY CLUSTERED([id] ASC)
144
 )
149
 )
145
 GO
150
 GO
146
 
151
 
152
+DROP SEQUENCE IF EXISTS [comments_id_seq]
153
+GO
154
+CREATE SEQUENCE [comments_id_seq] AS bigint START WITH 1 INCREMENT BY 1 NO CACHE
155
+GO
156
+
147
 CREATE TABLE [comments](
157
 CREATE TABLE [comments](
148
-	[id] [bigint] IDENTITY,
158
+	[id] [bigint] NOT NULL CONSTRAINT [comments_id_def] DEFAULT NEXT VALUE FOR [comments_id_seq],
149
 	[post_id] [int] NOT NULL,
159
 	[post_id] [int] NOT NULL,
150
 	[message] [nvarchar](255) NOT NULL,
160
 	[message] [nvarchar](255) NOT NULL,
151
 	[category_id] [int] NOT NULL,
161
 	[category_id] [int] NOT NULL,
152
-	PRIMARY KEY CLUSTERED([id] ASC)
162
+	CONSTRAINT [comments_pkey] PRIMARY KEY CLUSTERED([id] ASC)
153
 )
163
 )
154
 GO
164
 GO
155
 
165
 
166
+DROP SEQUENCE IF EXISTS [post_tags_id_seq]
167
+GO
168
+CREATE SEQUENCE [post_tags_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
169
+GO
170
+
156
 CREATE TABLE [post_tags](
171
 CREATE TABLE [post_tags](
157
-	[id] [int] IDENTITY,
172
+	[id] [int] NOT NULL CONSTRAINT [post_tags_id_def] DEFAULT NEXT VALUE FOR [post_tags_id_seq],
158
 	[post_id] [int] NOT NULL,
173
 	[post_id] [int] NOT NULL,
159
 	[tag_id] [int] NOT NULL,
174
 	[tag_id] [int] NOT NULL,
160
-	PRIMARY KEY CLUSTERED([id] ASC)
175
+	CONSTRAINT [post_tags_pkey] PRIMARY KEY CLUSTERED([id] ASC)
161
 )
176
 )
162
 GO
177
 GO
163
 
178
 
179
+DROP SEQUENCE IF EXISTS [posts_id_seq]
180
+GO
181
+CREATE SEQUENCE [posts_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
182
+GO
183
+
164
 CREATE TABLE [posts](
184
 CREATE TABLE [posts](
165
-	[id] [int] IDENTITY,
185
+	[id] [int] NOT NULL CONSTRAINT [posts_id_def] DEFAULT NEXT VALUE FOR [posts_id_seq],
166
 	[user_id] [int] NOT NULL,
186
 	[user_id] [int] NOT NULL,
167
 	[category_id] [int] NOT NULL,
187
 	[category_id] [int] NOT NULL,
168
 	[content] [nvarchar](255) NOT NULL,
188
 	[content] [nvarchar](255) NOT NULL,
169
-	PRIMARY KEY CLUSTERED([id] ASC)
189
+	CONSTRAINT [posts_pkey] PRIMARY KEY CLUSTERED([id] ASC)
170
 )
190
 )
171
 GO
191
 GO
172
 
192
 
193
+DROP SEQUENCE IF EXISTS [tags_id_seq]
194
+GO
195
+CREATE SEQUENCE [tags_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
196
+GO
197
+
173
 CREATE TABLE [tags](
198
 CREATE TABLE [tags](
174
-	[id] [int] IDENTITY,
199
+	[id] [int] NOT NULL CONSTRAINT [tags_id_def] DEFAULT NEXT VALUE FOR [tags_id_seq],
175
 	[name] [nvarchar](255) NOT NULL,
200
 	[name] [nvarchar](255) NOT NULL,
176
 	[is_important] [bit] NOT NULL,
201
 	[is_important] [bit] NOT NULL,
177
-	PRIMARY KEY CLUSTERED([id] ASC)
202
+	CONSTRAINT [tags_pkey] PRIMARY KEY CLUSTERED([id] ASC)
178
 )
203
 )
179
 GO
204
 GO
180
 
205
 
206
+DROP SEQUENCE IF EXISTS [users_id_seq]
207
+GO
208
+CREATE SEQUENCE [users_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
209
+GO
210
+
181
 CREATE TABLE [users](
211
 CREATE TABLE [users](
182
-	[id] [int] IDENTITY,
212
+	[id] [int] NOT NULL CONSTRAINT [users_id_def] DEFAULT NEXT VALUE FOR [users_id_seq],
183
 	[username] [nvarchar](255) NOT NULL,
213
 	[username] [nvarchar](255) NOT NULL,
184
 	[password] [nvarchar](255) NOT NULL,
214
 	[password] [nvarchar](255) NOT NULL,
185
 	[location] [geometry],
215
 	[location] [geometry],
186
-	CONSTRAINT [PK_users]
187
-	PRIMARY KEY CLUSTERED([id] ASC)
216
+	CONSTRAINT [users_pkey] PRIMARY KEY CLUSTERED([id] ASC)
188
 )
217
 )
189
 GO
218
 GO
190
 
219
 
220
+DROP SEQUENCE IF EXISTS [countries_id_seq]
221
+GO
222
+CREATE SEQUENCE [countries_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
223
+GO
224
+
191
 CREATE TABLE [countries](
225
 CREATE TABLE [countries](
192
-	[id] [int] IDENTITY,
226
+	[id] [int] NOT NULL CONSTRAINT [countries_id_def] DEFAULT NEXT VALUE FOR [countries_id_seq],
193
 	[name] [nvarchar](255) NOT NULL,
227
 	[name] [nvarchar](255) NOT NULL,
194
 	[shape] [geometry] NOT NULL,
228
 	[shape] [geometry] NOT NULL,
195
-	CONSTRAINT [PK_countries]
196
-	PRIMARY KEY CLUSTERED([id] ASC)
229
+	CONSTRAINT [countries_pkey] PRIMARY KEY CLUSTERED([id] ASC)
197
 )
230
 )
198
 GO
231
 GO
199
 
232
 
233
+DROP SEQUENCE IF EXISTS [events_id_seq]
234
+GO
235
+CREATE SEQUENCE [events_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
236
+GO
237
+
200
 CREATE TABLE [events](
238
 CREATE TABLE [events](
201
-	[id] [int] IDENTITY,
239
+	[id] [int] NOT NULL CONSTRAINT [events_id_def] DEFAULT NEXT VALUE FOR [events_id_seq],
202
 	[name] [nvarchar](255) NOT NULL,
240
 	[name] [nvarchar](255) NOT NULL,
203
 	[datetime] [datetime2](0),
241
 	[datetime] [datetime2](0),
204
 	[visitors] [bigint],
242
 	[visitors] [bigint],
205
-	CONSTRAINT [PK_events]
206
-	PRIMARY KEY CLUSTERED([id] ASC)
243
+	CONSTRAINT [events_pkey] PRIMARY KEY CLUSTERED([id] ASC)
207
 )
244
 )
208
 GO
245
 GO
209
 
246
 
212
 SELECT top 100 PERCENT name, COUNT_BIG(name) AS [count] FROM tags, post_tags WHERE tags.id = post_tags.tag_id GROUP BY name ORDER BY [count] DESC, name
249
 SELECT top 100 PERCENT name, COUNT_BIG(name) AS [count] FROM tags, post_tags WHERE tags.id = post_tags.tag_id GROUP BY name ORDER BY [count] DESC, name
213
 GO
250
 GO
214
 
251
 
252
+DROP SEQUENCE IF EXISTS [products_id_seq]
253
+GO
254
+CREATE SEQUENCE [products_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
255
+GO
256
+
215
 CREATE TABLE [products](
257
 CREATE TABLE [products](
216
-	[id] [int] IDENTITY,
258
+	[id] [int] NOT NULL CONSTRAINT [products_id_def] DEFAULT NEXT VALUE FOR [products_id_seq],
217
 	[name] [nvarchar](255) NOT NULL,
259
 	[name] [nvarchar](255) NOT NULL,
218
 	[price] [decimal](10,2) NOT NULL,
260
 	[price] [decimal](10,2) NOT NULL,
219
 	[properties] [xml] NOT NULL,
261
 	[properties] [xml] NOT NULL,
220
 	[created_at] [datetime2](0) NOT NULL,
262
 	[created_at] [datetime2](0) NOT NULL,
221
 	[deleted_at] [datetime2](0),
263
 	[deleted_at] [datetime2](0),
222
-	CONSTRAINT [PK_products]
223
-	PRIMARY KEY CLUSTERED([id] ASC)
264
+	CONSTRAINT [products_pkey] PRIMARY KEY CLUSTERED([id] ASC)
224
 )
265
 )
225
 GO
266
 GO
226
 
267
 
268
+DROP SEQUENCE IF EXISTS [barcodes_id_seq]
269
+GO
270
+CREATE SEQUENCE [barcodes_id_seq] AS int START WITH 1 INCREMENT BY 1 NO CACHE
271
+GO
272
+
227
 CREATE TABLE [barcodes](
273
 CREATE TABLE [barcodes](
228
-	[id] [int] IDENTITY,
274
+	[id] [int] NOT NULL CONSTRAINT [barcodes_id_def] DEFAULT NEXT VALUE FOR [barcodes_id_seq],
229
 	[product_id] [int] NOT NULL,
275
 	[product_id] [int] NOT NULL,
230
 	[hex] [nvarchar](255) NOT NULL,
276
 	[hex] [nvarchar](255) NOT NULL,
231
 	[bin] [varbinary](max) NOT NULL,
277
 	[bin] [varbinary](max) NOT NULL,
232
-	CONSTRAINT [PK_barcodes]
233
-	PRIMARY KEY CLUSTERED([id] ASC)
278
+	CONSTRAINT [barcodes_pkey] PRIMARY KEY CLUSTERED([id] ASC)
234
 )
279
 )
235
 GO
280
 GO
236
 
281
 
239
 	[Umlauts ä_ö_ü-COUNT] [int] NOT NULL,
284
 	[Umlauts ä_ö_ü-COUNT] [int] NOT NULL,
240
 	[user_id] [int] NOT NULL,
285
 	[user_id] [int] NOT NULL,
241
 	[invisible] [nvarchar](36),
286
 	[invisible] [nvarchar](36),
242
-	CONSTRAINT [PK_kunsthåndværk]
243
-	PRIMARY KEY CLUSTERED([id] ASC)
287
+	CONSTRAINT [kunsthåndværk_pkey] PRIMARY KEY CLUSTERED([id] ASC)
244
 )
288
 )
245
 GO
289
 GO
246
 
290
 
247
 CREATE TABLE [invisibles](
291
 CREATE TABLE [invisibles](
248
 	[id] [nvarchar](36) NOT NULL,
292
 	[id] [nvarchar](36) NOT NULL,
249
-	CONSTRAINT [PK_invisibles]
250
-	PRIMARY KEY CLUSTERED([id] ASC)
293
+	CONSTRAINT [invisibles_pkey] PRIMARY KEY CLUSTERED([id] ASC)
251
 )
294
 )
252
 GO
295
 GO
253
 
296
 
321
 INSERT [nopk] ([id]) VALUES ('e42c77c6-06a4-4502-816c-d112c7142e6d')
364
 INSERT [nopk] ([id]) VALUES ('e42c77c6-06a4-4502-816c-d112c7142e6d')
322
 GO
365
 GO
323
 
366
 
324
-ALTER TABLE [comments]  WITH CHECK ADD 	CONSTRAINT [FK_comments_posts] FOREIGN KEY([post_id])
367
+ALTER TABLE [comments]  WITH CHECK ADD 	CONSTRAINT [comments_post_id_fkey] FOREIGN KEY([post_id])
325
 REFERENCES [posts] ([id])
368
 REFERENCES [posts] ([id])
326
 GO
369
 GO
327
-ALTER TABLE [comments] CHECK	CONSTRAINT [FK_comments_posts]
370
+ALTER TABLE [comments] CHECK	CONSTRAINT [comments_post_id_fkey]
328
 GO
371
 GO
329
 
372
 
330
-ALTER TABLE [comments]  WITH CHECK ADD 	CONSTRAINT [FK_comments_categories] FOREIGN KEY([category_id])
373
+ALTER TABLE [comments]  WITH CHECK ADD 	CONSTRAINT [comments_category_id_fkey] FOREIGN KEY([category_id])
331
 REFERENCES [categories] ([id])
374
 REFERENCES [categories] ([id])
332
 GO
375
 GO
333
-ALTER TABLE [comments] CHECK	CONSTRAINT [FK_comments_categories]
376
+ALTER TABLE [comments] CHECK	CONSTRAINT [comments_category_id_fkey]
334
 GO
377
 GO
335
 
378
 
336
-ALTER TABLE [post_tags]  WITH CHECK ADD 	CONSTRAINT [FK_post_tags_posts] FOREIGN KEY([post_id])
379
+ALTER TABLE [post_tags]  WITH CHECK ADD 	CONSTRAINT [post_tags_post_id_fkey] FOREIGN KEY([post_id])
337
 REFERENCES [posts] ([id])
380
 REFERENCES [posts] ([id])
338
 GO
381
 GO
339
-ALTER TABLE [post_tags] CHECK	CONSTRAINT [FK_post_tags_posts]
382
+ALTER TABLE [post_tags] CHECK	CONSTRAINT [post_tags_post_id_fkey]
340
 GO
383
 GO
341
 
384
 
342
-ALTER TABLE [post_tags]  WITH CHECK ADD 	CONSTRAINT [FK_post_tags_tags] FOREIGN KEY([tag_id])
385
+ALTER TABLE [post_tags]  WITH CHECK ADD 	CONSTRAINT [post_tags_tag_id_fkey] FOREIGN KEY([tag_id])
343
 REFERENCES [tags] ([id])
386
 REFERENCES [tags] ([id])
344
 GO
387
 GO
345
-ALTER TABLE [post_tags] CHECK	CONSTRAINT [FK_post_tags_tags]
388
+ALTER TABLE [post_tags] CHECK	CONSTRAINT [post_tags_tag_id_fkey]
346
 GO
389
 GO
347
 
390
 
348
-ALTER TABLE [posts]  WITH CHECK ADD 	CONSTRAINT [FK_posts_categories] FOREIGN KEY([category_id])
391
+ALTER TABLE [posts]  WITH CHECK ADD 	CONSTRAINT [posts_category_id_fkey] FOREIGN KEY([category_id])
349
 REFERENCES [categories] ([id])
392
 REFERENCES [categories] ([id])
350
 GO
393
 GO
351
-ALTER TABLE [posts] CHECK	CONSTRAINT [FK_posts_categories]
394
+ALTER TABLE [posts] CHECK	CONSTRAINT [posts_category_id_fkey]
352
 GO
395
 GO
353
 
396
 
354
-ALTER TABLE [posts]  WITH CHECK ADD 	CONSTRAINT [FK_posts_users] FOREIGN KEY([user_id])
397
+ALTER TABLE [posts]  WITH CHECK ADD 	CONSTRAINT [posts_user_id_fkey] FOREIGN KEY([user_id])
355
 REFERENCES [users] ([id])
398
 REFERENCES [users] ([id])
356
 GO
399
 GO
357
-ALTER TABLE [posts] CHECK	CONSTRAINT [FK_posts_users]
400
+ALTER TABLE [posts] CHECK	CONSTRAINT [posts_user_id_fkey]
358
 GO
401
 GO
359
 
402
 
360
-ALTER TABLE [barcodes]  WITH CHECK ADD 	CONSTRAINT [FK_barcodes_products] FOREIGN KEY([product_id])
403
+ALTER TABLE [barcodes]  WITH CHECK ADD 	CONSTRAINT [barcodes_product_id_fkey] FOREIGN KEY([product_id])
361
 REFERENCES [products] ([id])
404
 REFERENCES [products] ([id])
362
 GO
405
 GO
363
-ALTER TABLE [barcodes] CHECK	CONSTRAINT [FK_barcodes_products]
406
+ALTER TABLE [barcodes] CHECK	CONSTRAINT [barcodes_product_id_fkey]
364
 GO
407
 GO
365
 
408
 
366
 ALTER TABLE [kunsthåndværk]  WITH CHECK ADD 	CONSTRAINT [UC_kunsthåndværk_Umlauts ä_ö_ü-COUNT] UNIQUE([Umlauts ä_ö_ü-COUNT])
409
 ALTER TABLE [kunsthåndværk]  WITH CHECK ADD 	CONSTRAINT [UC_kunsthåndværk_Umlauts ä_ö_ü-COUNT] UNIQUE([Umlauts ä_ö_ü-COUNT])
367
 GO
410
 GO
368
 
411
 
369
-ALTER TABLE [kunsthåndværk]  WITH CHECK ADD 	CONSTRAINT [FK_kunsthåndværk_users] FOREIGN KEY([user_id])
412
+ALTER TABLE [kunsthåndværk]  WITH CHECK ADD 	CONSTRAINT [kunsthåndværk_user_id_fkey] FOREIGN KEY([user_id])
370
 REFERENCES [users] ([id])
413
 REFERENCES [users] ([id])
371
 GO
414
 GO
372
-ALTER TABLE [kunsthåndværk] CHECK	CONSTRAINT [FK_kunsthåndværk_users]
415
+ALTER TABLE [kunsthåndværk] CHECK	CONSTRAINT [kunsthåndværk_user_id_fkey]
373
 GO
416
 GO

+ 0
- 35
tests/functional/003_columns/004_update_barcodes_id_column.log.skip View File

1
-PUT /columns/barcodes/id
2
-
3
-{"name":"id2","type":"bigint"}
4
-===
5
-200
6
-Content-Type: application/json
7
-Content-Length: 4
8
-
9
-true
10
-===
11
-GET /columns/barcodes/id2
12
-===
13
-200
14
-Content-Type: application/json
15
-Content-Length: 40
16
-
17
-{"name":"id2","type":"bigint","pk":true}
18
-===
19
-PUT /columns/barcodes/id2
20
-
21
-{"name":"id","type":"integer"}
22
-===
23
-200
24
-Content-Type: application/json
25
-Content-Length: 4
26
-
27
-true
28
-===
29
-GET /columns/barcodes/id
30
-===
31
-200
32
-Content-Type: application/json
33
-Content-Length: 40
34
-
35
-{"name":"id","type":"integer","pk":true}

+ 0
- 35
tests/functional/003_columns/005_update_barcodes_product_id_nullable.log.skip View File

1
-PUT /columns/barcodes/product_id
2
-
3
-{"nullable":true}
4
-===
5
-200
6
-Content-Type: application/json
7
-Content-Length: 4
8
-
9
-true
10
-===
11
-GET /columns/barcodes/product_id
12
-===
13
-200
14
-Content-Type: application/json
15
-Content-Length: 70
16
-
17
-{"name":"product_id","type":"integer","nullable":true,"fk":"products"}
18
-===
19
-PUT /columns/barcodes/product_id
20
-
21
-{"nullable":false}
22
-===
23
-200
24
-Content-Type: application/json
25
-Content-Length: 4
26
-
27
-true
28
-===
29
-GET /columns/barcodes/product_id
30
-===
31
-200
32
-Content-Type: application/json
33
-Content-Length: 54
34
-
35
-{"name":"product_id","type":"integer","fk":"products"}

+ 0
- 61
tests/functional/003_columns/006_update_events_visitors_pk.log.skip View File

1
-PUT /columns/events/visitors
2
-
3
-{"pk":true}
4
-===
5
-200
6
-Content-Type: application/json
7
-Content-Length: 4
8
-
9
-true
10
-===
11
-GET /columns/events/visitors
12
-===
13
-200
14
-Content-Type: application/json
15
-Content-Length: 46
16
-
17
-{"name":"visitors","type":"integer","pk":true}
18
-===
19
-GET /columns/events/id
20
-===
21
-200
22
-Content-Type: application/json
23
-Content-Length: 30
24
-
25
-{"name":"id","type":"integer"}
26
-===
27
-PUT /columns/events/visitors
28
-
29
-{"pk":false}
30
-===
31
-200
32
-Content-Type: application/json
33
-Content-Length: 4
34
-
35
-true
36
-===
37
-GET /columns/events/visitors
38
-===
39
-200
40
-Content-Type: application/json
41
-Content-Length: 36
42
-
43
-{"name":"visitors","type":"integer"}
44
-===
45
-PUT /columns/events/id
46
-
47
-{"pk":true}
48
-===
49
-200
50
-Content-Type: application/json
51
-Content-Length: 4
52
-
53
-true
54
-===
55
-GET /columns/events/id
56
-===
57
-200
58
-Content-Type: application/json
59
-Content-Length: 40
60
-
61
-{"name":"id","type":"integer","pk":true}

+ 0
- 35
tests/functional/003_columns/007_update_barcodes_product_id_fk.log.skip View File

1
-PUT /columns/barcodes/product_id
2
-
3
-{"fk":""}
4
-===
5
-200
6
-Content-Type: application/json
7
-Content-Length: 4
8
-
9
-true
10
-===
11
-GET /columns/barcodes/product_id
12
-===
13
-200
14
-Content-Type: application/json
15
-Content-Length: 38
16
-
17
-{"name":"product_id","type":"integer"}
18
-===
19
-PUT /columns/barcodes/product_id
20
-
21
-{"fk":"products"}
22
-===
23
-200
24
-Content-Type: application/json
25
-Content-Length: 4
26
-
27
-true
28
-===
29
-GET /columns/barcodes/product_id
30
-===
31
-200
32
-Content-Type: application/json
33
-Content-Length: 54
34
-
35
-{"name":"product_id","type":"integer","fk":"products"}

+ 0
- 35
tests/functional/003_columns/008_update_barcodes_table.log.skip View File

1
-PUT /columns/barcodes
2
-
3
-{"name":"barcodes2"}
4
-===
5
-200
6
-Content-Type: application/json
7
-Content-Length: 4
8
-
9
-true
10
-===
11
-GET /columns/barcodes2
12
-===
13
-200
14
-Content-Type: application/json
15
-Content-Length: 217
16
-
17
-{"name":"barcodes2","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"}]}
18
-===
19
-PUT /columns/barcodes2
20
-
21
-{"name":"barcodes"}
22
-===
23
-200
24
-Content-Type: application/json
25
-Content-Length: 4
26
-
27
-true
28
-===
29
-GET /columns/barcodes
30
-===
31
-200
32
-Content-Type: application/json
33
-Content-Length: 216
34
-
35
-{"name":"barcodes","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"}]}

+ 0
- 35
tests/functional/003_columns/009_update_barcodes_hex_type.log.skip View File

1
-PUT /columns/barcodes/hex
2
-
3
-{"type":"clob"}
4
-===
5
-200
6
-Content-Type: application/json
7
-Content-Length: 4
8
-
9
-true
10
-===
11
-GET /columns/barcodes/hex
12
-===
13
-200
14
-Content-Type: application/json
15
-Content-Length: 28
16
-
17
-{"name":"hex","type":"clob"}
18
-===
19
-PUT /columns/barcodes/hex
20
-
21
-{"type":"varchar","length":255}
22
-===
23
-200
24
-Content-Type: application/json
25
-Content-Length: 4
26
-
27
-true
28
-===
29
-GET /columns/barcodes/hex
30
-===
31
-200
32
-Content-Type: application/json
33
-Content-Length: 44
34
-
35
-{"name":"hex","type":"varchar","length":255}

+ 0
- 25
tests/functional/003_columns/010_create_barcodes_table.log.skip View File

1
-POST /columns
2
-
3
-{"name":"barcodes2","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"}]}
4
-===
5
-200
6
-Content-Type: application/json
7
-Content-Length: 4
8
-
9
-true
10
-===
11
-GET /columns/barcodes2
12
-===
13
-200
14
-Content-Type: application/json
15
-Content-Length: 217
16
-
17
-{"name":"barcodes2","type":"table","columns":[{"name":"id","type":"integer","pk":true},{"name":"product_id","type":"integer","fk":"products"},{"name":"hex","type":"varchar","length":255},{"name":"bin","type":"blob"}]}
18
-===
19
-DELETE /columns/barcodes2
20
-===
21
-200
22
-Content-Type: application/json
23
-Content-Length: 4
24
-
25
-true

+ 0
- 25
tests/functional/003_columns/011_create_barcodes_column.log.skip View File

1
-POST /columns/barcodes
2
-
3
-{"name":"alternative_product_id","type":"integer","nullable":true,"fk":"products"}
4
-===
5
-200
6
-Content-Type: application/json
7
-Content-Length: 4
8
-
9
-true
10
-===
11
-GET /columns/barcodes/alternative_product_id
12
-===
13
-200
14
-Content-Type: application/json
15
-Content-Length: 82
16
-
17
-{"name":"alternative_product_id","type":"integer","nullable":true,"fk":"products"}
18
-===
19
-DELETE /columns/barcodes/alternative_product_id
20
-===
21
-200
22
-Content-Type: application/json
23
-Content-Length: 4
24
-
25
-true

Loading…
Cancel
Save