Skip to content

Commit 6c877e8

Browse files
committed
Update GRDB tables to include stock properties
1 parent 0d908b9 commit 6c877e8

File tree

2 files changed

+73
-19
lines changed

2 files changed

+73
-19
lines changed

Modules/Sources/Storage/GRDB/Migrations/V001InitialSchema.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ struct V001InitialSchema {
4343
productTable.column("downloadable", .boolean).notNull()
4444

4545
productTable.column("parentID", .integer).notNull()
46+
47+
productTable.column("manageStock", .boolean).notNull()
48+
productTable.column("stockQuantity", .double)
49+
productTable.column("stockStatusKey", .text).notNull()
4650
}
4751
}
4852

@@ -87,6 +91,10 @@ struct V001InitialSchema {
8791
productVariationTable.column("downloadable", .boolean).notNull()
8892

8993
productVariationTable.column("fullDescription", .text)
94+
95+
productVariationTable.column("manageStock", .boolean).notNull()
96+
productVariationTable.column("stockQuantity", .double)
97+
productVariationTable.column("stockStatusKey", .text).notNull()
9098
}
9199
}
92100

Modules/Tests/StorageTests/GRDB/GRDBManagerTests.swift

Lines changed: 65 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ struct GRDBManagerTests {
6868
productTypeKey: "simple",
6969
price: "10.00",
7070
downloadable: false,
71-
parentID: 0
71+
parentID: 0,
72+
manageStock: false,
73+
stockStatusKey: ""
7274
)
7375
try record.insert(db)
7476
}
@@ -92,7 +94,9 @@ struct GRDBManagerTests {
9294
productTypeKey: "variable",
9395
price: "10.00",
9496
downloadable: false,
95-
parentID: 0
97+
parentID: 0,
98+
manageStock: false,
99+
stockStatusKey: ""
96100
)
97101
try product.insert(db)
98102
}
@@ -104,7 +108,9 @@ struct GRDBManagerTests {
104108
id: 200,
105109
productID: 100,
106110
price: "12.00",
107-
downloadable: false
111+
downloadable: false,
112+
manageStock: false,
113+
stockStatusKey: ""
108114
)
109115
try variation.insert(db)
110116
}
@@ -130,7 +136,9 @@ struct GRDBManagerTests {
130136
productTypeKey: "variable",
131137
price: "10.00",
132138
downloadable: false,
133-
parentID: 0
139+
parentID: 0,
140+
manageStock: false,
141+
stockStatusKey: ""
134142
)
135143
try product.insert(db)
136144

@@ -141,7 +149,9 @@ struct GRDBManagerTests {
141149
id: Int64(200 + i),
142150
productID: 100,
143151
price: "\(10 + i).00",
144-
downloadable: false
152+
downloadable: false,
153+
manageStock: false,
154+
stockStatusKey: ""
145155
)
146156
try variation.insert(db)
147157
}
@@ -171,7 +181,9 @@ struct GRDBManagerTests {
171181
productTypeKey: "simple",
172182
price: "10.00",
173183
downloadable: false,
174-
parentID: 0
184+
parentID: 0,
185+
manageStock: false,
186+
stockStatusKey: ""
175187
)
176188
try product.insert(db)
177189
}
@@ -210,7 +222,9 @@ struct GRDBManagerTests {
210222
productTypeKey: "variable",
211223
price: "10.00",
212224
downloadable: false,
213-
parentID: 0
225+
parentID: 0,
226+
manageStock: false,
227+
stockStatusKey: ""
214228
)
215229
try product.insert(db)
216230

@@ -220,7 +234,9 @@ struct GRDBManagerTests {
220234
id: 200,
221235
productID: 100,
222236
price: "12.00",
223-
downloadable: false
237+
downloadable: false,
238+
manageStock: false,
239+
stockStatusKey: ""
224240
)
225241
try variation.insert(db)
226242
}
@@ -262,7 +278,9 @@ struct GRDBManagerTests {
262278
productTypeKey: "simple",
263279
price: "10.00",
264280
downloadable: false,
265-
parentID: 0
281+
parentID: 0,
282+
manageStock: false,
283+
stockStatusKey: ""
266284
)
267285
try product.insert(db)
268286

@@ -271,7 +289,9 @@ struct GRDBManagerTests {
271289
id: 200,
272290
productID: 100,
273291
price: "12.00",
274-
downloadable: false
292+
downloadable: false,
293+
manageStock: false,
294+
stockStatusKey: ""
275295
)
276296
try variation.insert(db)
277297

@@ -350,7 +370,9 @@ struct GRDBManagerTests {
350370
productTypeKey: "simple",
351371
price: "\(i * 10).00",
352372
downloadable: false,
353-
parentID: 0
373+
parentID: 0,
374+
manageStock: false,
375+
stockStatusKey: ""
354376
)
355377
try product.insert(db)
356378
}
@@ -364,7 +386,9 @@ struct GRDBManagerTests {
364386
productTypeKey: "variable",
365387
price: "\(i * 5).00",
366388
downloadable: true,
367-
parentID: 0
389+
parentID: 0,
390+
manageStock: false,
391+
stockStatusKey: ""
368392
)
369393
try product.insert(db)
370394
}
@@ -405,7 +429,9 @@ struct GRDBManagerTests {
405429
productTypeKey: "variable",
406430
price: "10.00",
407431
downloadable: false,
408-
parentID: 0
432+
parentID: 0,
433+
manageStock: false,
434+
stockStatusKey: ""
409435
)
410436
try product.insert(db)
411437

@@ -415,7 +441,9 @@ struct GRDBManagerTests {
415441
id: Int64(200 + i),
416442
productID: 100,
417443
price: "\(10 + i).00",
418-
downloadable: false
444+
downloadable: false,
445+
manageStock: false,
446+
stockStatusKey: ""
419447
)
420448
try variation.insert(db)
421449
}
@@ -446,7 +474,9 @@ struct GRDBManagerTests {
446474
productTypeKey: "simple",
447475
price: "10.00",
448476
downloadable: false,
449-
parentID: 0
477+
parentID: 0,
478+
manageStock: false,
479+
stockStatusKey: ""
450480
)
451481
try product.insert(db)
452482
}
@@ -463,7 +493,9 @@ struct GRDBManagerTests {
463493
id: 200,
464494
productID: 999, // Non-existent product
465495
price: "12.00",
466-
downloadable: false
496+
downloadable: false,
497+
manageStock: false,
498+
stockStatusKey: ""
467499
)
468500
try variation.insert(db)
469501
}
@@ -494,22 +526,29 @@ struct TestProduct: Codable {
494526
let price: String
495527
let downloadable: Bool
496528
let parentID: Int64
529+
let manageStock: Bool
530+
let stockQuantity: Double?
531+
let stockStatusKey: String
497532

498533
init(siteID: Int64, id: Int64, name: String, productTypeKey: String,
499534
price: String, downloadable: Bool, parentID: Int64,
535+
manageStock: Bool, stockStatusKey: String,
500536
fullDescription: String? = nil, shortDescription: String? = nil,
501-
sku: String? = nil, globalUniqueID: String? = nil) {
537+
sku: String? = nil, globalUniqueID: String? = nil, stockQuantity: Double? = nil) {
502538
self.siteID = siteID
503539
self.id = id
504540
self.name = name
505541
self.productTypeKey = productTypeKey
506542
self.price = price
507543
self.downloadable = downloadable
508544
self.parentID = parentID
545+
self.manageStock = manageStock
546+
self.stockStatusKey = stockStatusKey
509547
self.fullDescription = fullDescription
510548
self.shortDescription = shortDescription
511549
self.sku = sku
512550
self.globalUniqueID = globalUniqueID
551+
self.stockQuantity = stockQuantity
513552
}
514553
}
515554

@@ -526,18 +565,25 @@ struct TestProductVariation: Codable {
526565
let price: String
527566
let downloadable: Bool
528567
let fullDescription: String?
568+
let manageStock: Bool
569+
let stockQuantity: Double?
570+
let stockStatusKey: String
529571

530572
init(siteID: Int64, id: Int64, productID: Int64,
531-
price: String, downloadable: Bool,
532-
sku: String? = nil, globalUniqueID: String? = nil, fullDescription: String? = nil) {
573+
price: String, downloadable: Bool, manageStock: Bool, stockStatusKey: String,
574+
sku: String? = nil, globalUniqueID: String? = nil, fullDescription: String? = nil,
575+
stockQuantity: Double? = nil) {
533576
self.siteID = siteID
534577
self.id = id
535578
self.productID = productID
536579
self.price = price
537580
self.downloadable = downloadable
581+
self.manageStock = manageStock
582+
self.stockStatusKey = stockStatusKey
538583
self.sku = sku
539584
self.globalUniqueID = globalUniqueID
540585
self.fullDescription = fullDescription
586+
self.stockQuantity = stockQuantity
541587
}
542588
}
543589

0 commit comments

Comments
 (0)