refactor: remove usage of inventory_quantity from the codebase (#7323)
This commit is contained in:
1 parent
9ca302d33f
commit
a502222582
18 files changed
+158
-117
No files matched your search
@@ -188,10 +188,6 @@ export interface ProductVariantDTO {
|
|||||||
* The UPC of the product variant.
|
* The UPC of the product variant.
|
||||||
*/
|
*/
|
||||||
upc?: string | null
|
upc?: string | null
|
||||||
/**
|
|
||||||
* The inventory quantiy of the product variant.
|
|
||||||
*/
|
|
||||||
inventory_quantity: number
|
|
||||||
/**
|
/**
|
||||||
* Whether the product variant can be ordered when it's out of stock.
|
* Whether the product variant can be ordered when it's out of stock.
|
||||||
*/
|
*/
|
||||||
@@ -1209,10 +1205,6 @@ export interface CreateProductVariantDTO {
|
|||||||
* Whether the product variant can be ordered when it's out of stock.
|
* Whether the product variant can be ordered when it's out of stock.
|
||||||
*/
|
*/
|
||||||
allow_backorder?: boolean
|
allow_backorder?: boolean
|
||||||
/**
|
|
||||||
* The inventory quantiy of the product variant.
|
|
||||||
*/
|
|
||||||
inventory_quantity?: number
|
|
||||||
/**
|
/**
|
||||||
* Whether the product variant's inventory should be managed by the core system.
|
* Whether the product variant's inventory should be managed by the core system.
|
||||||
*/
|
*/
|
||||||
@@ -1310,10 +1302,6 @@ export interface UpdateProductVariantDTO {
|
|||||||
* Whether the product variant can be ordered when it's out of stock.
|
* Whether the product variant can be ordered when it's out of stock.
|
||||||
*/
|
*/
|
||||||
allow_backorder?: boolean
|
allow_backorder?: boolean
|
||||||
/**
|
|
||||||
* The inventory quantiy of the product variant.
|
|
||||||
*/
|
|
||||||
inventory_quantity?: number
|
|
||||||
/**
|
/**
|
||||||
* Whether the product variant's inventory should be managed by the core system.
|
* Whether the product variant's inventory should be managed by the core system.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ export interface CreateProductVariantsInputDTO {
|
|||||||
upc?: string
|
upc?: string
|
||||||
barcode?: string
|
barcode?: string
|
||||||
hs_code?: string
|
hs_code?: string
|
||||||
inventory_quantity?: number
|
|
||||||
allow_backorder?: boolean
|
allow_backorder?: boolean
|
||||||
manage_inventory?: boolean
|
manage_inventory?: boolean
|
||||||
weight?: number
|
weight?: number
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ export interface CreateProductVariantInputDTO {
|
|||||||
upc?: string
|
upc?: string
|
||||||
barcode?: string
|
barcode?: string
|
||||||
hs_code?: string
|
hs_code?: string
|
||||||
inventory_quantity?: number
|
|
||||||
allow_backorder?: boolean
|
allow_backorder?: boolean
|
||||||
manage_inventory?: boolean
|
manage_inventory?: boolean
|
||||||
weight?: number
|
weight?: number
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ export interface UpdateProductVariantsInputDTO {
|
|||||||
upc?: string
|
upc?: string
|
||||||
barcode?: string
|
barcode?: string
|
||||||
hs_code?: string
|
hs_code?: string
|
||||||
inventory_quantity?: number
|
|
||||||
allow_backorder?: boolean
|
allow_backorder?: boolean
|
||||||
manage_inventory?: boolean
|
manage_inventory?: boolean
|
||||||
weight?: number
|
weight?: number
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ export interface UpdateProductVariantInputDTO {
|
|||||||
upc?: string
|
upc?: string
|
||||||
barcode?: string
|
barcode?: string
|
||||||
hs_code?: string
|
hs_code?: string
|
||||||
inventory_quantity?: number
|
|
||||||
allow_backorder?: boolean
|
allow_backorder?: boolean
|
||||||
manage_inventory?: boolean
|
manage_inventory?: boolean
|
||||||
weight?: number
|
weight?: number
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ const remoteQueryObject = {
|
|||||||
"ean",
|
"ean",
|
||||||
"upc",
|
"upc",
|
||||||
"variant_rank",
|
"variant_rank",
|
||||||
"inventory_quantity",
|
|
||||||
"allow_backorder",
|
"allow_backorder",
|
||||||
"manage_inventory",
|
"manage_inventory",
|
||||||
"hs_code",
|
"hs_code",
|
||||||
@@ -188,7 +187,6 @@ describe("remoteQueryObjectToString", function () {
|
|||||||
"variants.ean",
|
"variants.ean",
|
||||||
"variants.upc",
|
"variants.upc",
|
||||||
"variants.variant_rank",
|
"variants.variant_rank",
|
||||||
"variants.inventory_quantity",
|
|
||||||
"variants.allow_backorder",
|
"variants.allow_backorder",
|
||||||
"variants.manage_inventory",
|
"variants.manage_inventory",
|
||||||
"variants.hs_code",
|
"variants.hs_code",
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ export const defaultAdminProductsVariantFields = [
|
|||||||
"product_id",
|
"product_id",
|
||||||
"title",
|
"title",
|
||||||
"sku",
|
"sku",
|
||||||
"inventory_quantity",
|
|
||||||
"allow_backorder",
|
"allow_backorder",
|
||||||
"manage_inventory",
|
"manage_inventory",
|
||||||
"hs_code",
|
"hs_code",
|
||||||
|
|||||||
@@ -131,7 +131,6 @@ export const AdminCreateProductVariant = z.object({
|
|||||||
barcode: z.string().optional(),
|
barcode: z.string().optional(),
|
||||||
hs_code: z.string().optional(),
|
hs_code: z.string().optional(),
|
||||||
mid_code: z.string().optional(),
|
mid_code: z.string().optional(),
|
||||||
inventory_quantity: z.number().optional().default(0),
|
|
||||||
allow_backorder: z.boolean().optional().default(false),
|
allow_backorder: z.boolean().optional().default(false),
|
||||||
manage_inventory: z.boolean().optional().default(true),
|
manage_inventory: z.boolean().optional().default(true),
|
||||||
variant_rank: z.number().optional(),
|
variant_rank: z.number().optional(),
|
||||||
@@ -153,7 +152,6 @@ export const AdminUpdateProductVariant = AdminCreateProductVariant.extend({
|
|||||||
id: z.string().optional(),
|
id: z.string().optional(),
|
||||||
title: z.string().optional(),
|
title: z.string().optional(),
|
||||||
prices: z.array(AdminUpdateVariantPrice).optional(),
|
prices: z.array(AdminUpdateVariantPrice).optional(),
|
||||||
inventory_quantity: z.number().optional(),
|
|
||||||
allow_backorder: z.boolean().optional(),
|
allow_backorder: z.boolean().optional(),
|
||||||
manage_inventory: z.boolean().optional(),
|
manage_inventory: z.boolean().optional(),
|
||||||
}).strict()
|
}).strict()
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ export const ProductVariantModelMock = {
|
|||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
_id: IdMap.getId("inventory-test"),
|
_id: IdMap.getId("inventory-test"),
|
||||||
title: "inventory",
|
title: "inventory",
|
||||||
inventory_quantity: 10,
|
|
||||||
allow_backorder: false,
|
allow_backorder: false,
|
||||||
manage_inventory: true,
|
manage_inventory: true,
|
||||||
})
|
})
|
||||||
@@ -41,7 +40,6 @@ export const ProductVariantModelMock = {
|
|||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
_id: IdMap.getId("no-inventory-test"),
|
_id: IdMap.getId("no-inventory-test"),
|
||||||
title: "inventory",
|
title: "inventory",
|
||||||
inventory_quantity: 0,
|
|
||||||
allow_backorder: false,
|
allow_backorder: false,
|
||||||
manage_inventory: false,
|
manage_inventory: false,
|
||||||
})
|
})
|
||||||
@@ -50,7 +48,6 @@ export const ProductVariantModelMock = {
|
|||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
_id: IdMap.getId("backorder-test"),
|
_id: IdMap.getId("backorder-test"),
|
||||||
title: "inventory",
|
title: "inventory",
|
||||||
inventory_quantity: 5,
|
|
||||||
allow_backorder: true,
|
allow_backorder: true,
|
||||||
manage_inventory: true,
|
manage_inventory: true,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -120,14 +120,12 @@ const variantsData = [
|
|||||||
title: "variant title",
|
title: "variant title",
|
||||||
sku: "sku 1",
|
sku: "sku 1",
|
||||||
product: { id: productsData[0].id },
|
product: { id: productsData[0].id },
|
||||||
inventory_quantity: 10,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "test-2",
|
id: "test-2",
|
||||||
title: "variant title",
|
title: "variant title",
|
||||||
sku: "sku 2",
|
sku: "sku 2",
|
||||||
product: { id: productsData[1].id },
|
product: { id: productsData[1].id },
|
||||||
inventory_quantity: 10,
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -42,13 +42,11 @@ export const variantsData = [
|
|||||||
title: "variant title",
|
title: "variant title",
|
||||||
sku: "sku 1",
|
sku: "sku 1",
|
||||||
product: { id: productsData[0].id },
|
product: { id: productsData[0].id },
|
||||||
inventory_quantity: 10,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "test-2",
|
id: "test-2",
|
||||||
title: "variant title",
|
title: "variant title",
|
||||||
sku: "sku 2",
|
sku: "sku 2",
|
||||||
product: { id: productsData[1].id },
|
product: { id: productsData[1].id },
|
||||||
inventory_quantity: 10,
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@@ -8,7 +8,6 @@ export const buildProductVariantOnlyData = ({
|
|||||||
ean,
|
ean,
|
||||||
upc,
|
upc,
|
||||||
allow_backorder,
|
allow_backorder,
|
||||||
inventory_quantity,
|
|
||||||
manage_inventory,
|
manage_inventory,
|
||||||
hs_code,
|
hs_code,
|
||||||
origin_country,
|
origin_country,
|
||||||
@@ -28,7 +27,6 @@ export const buildProductVariantOnlyData = ({
|
|||||||
ean,
|
ean,
|
||||||
upc,
|
upc,
|
||||||
allow_backorder,
|
allow_backorder,
|
||||||
inventory_quantity,
|
|
||||||
manage_inventory,
|
manage_inventory,
|
||||||
hs_code,
|
hs_code,
|
||||||
origin_country,
|
origin_country,
|
||||||
|
|||||||
-2
@@ -44,7 +44,6 @@ moduleIntegrationTestRunner({
|
|||||||
variantOne = await service.createVariants({
|
variantOne = await service.createVariants({
|
||||||
id: "test-1",
|
id: "test-1",
|
||||||
title: "variant 1",
|
title: "variant 1",
|
||||||
inventory_quantity: 10,
|
|
||||||
product_id: productOne.id,
|
product_id: productOne.id,
|
||||||
options: { size: "large" },
|
options: { size: "large" },
|
||||||
})
|
})
|
||||||
@@ -52,7 +51,6 @@ moduleIntegrationTestRunner({
|
|||||||
variantTwo = await service.createVariants({
|
variantTwo = await service.createVariants({
|
||||||
id: "test-2",
|
id: "test-2",
|
||||||
title: "variant",
|
title: "variant",
|
||||||
inventory_quantity: 10,
|
|
||||||
product_id: productTwo.id,
|
product_id: productTwo.id,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
-5
@@ -119,7 +119,6 @@ moduleIntegrationTestRunner({
|
|||||||
{
|
{
|
||||||
id: "variant-1",
|
id: "variant-1",
|
||||||
title: "variant 1",
|
title: "variant 1",
|
||||||
inventory_quantity: 10,
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
@@ -145,12 +144,10 @@ moduleIntegrationTestRunner({
|
|||||||
{
|
{
|
||||||
id: "variant-2",
|
id: "variant-2",
|
||||||
title: "variant 2",
|
title: "variant 2",
|
||||||
inventory_quantity: 10,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "variant-3",
|
id: "variant-3",
|
||||||
title: "variant 3",
|
title: "variant 3",
|
||||||
inventory_quantity: 10,
|
|
||||||
options: {
|
options: {
|
||||||
size: "small",
|
size: "small",
|
||||||
color: "red",
|
color: "red",
|
||||||
@@ -258,7 +255,6 @@ moduleIntegrationTestRunner({
|
|||||||
sku: createdVariant.sku,
|
sku: createdVariant.sku,
|
||||||
allow_backorder: false,
|
allow_backorder: false,
|
||||||
manage_inventory: true,
|
manage_inventory: true,
|
||||||
inventory_quantity: 100,
|
|
||||||
variant_rank: 0,
|
variant_rank: 0,
|
||||||
options: expect.arrayContaining([
|
options: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
@@ -615,7 +611,6 @@ moduleIntegrationTestRunner({
|
|||||||
sku: data.variants[0].sku,
|
sku: data.variants[0].sku,
|
||||||
allow_backorder: false,
|
allow_backorder: false,
|
||||||
manage_inventory: true,
|
manage_inventory: true,
|
||||||
inventory_quantity: 100,
|
|
||||||
variant_rank: 0,
|
variant_rank: 0,
|
||||||
options: expect.arrayContaining([
|
options: expect.arrayContaining([
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
|
|||||||
@@ -48,14 +48,12 @@ moduleIntegrationTestRunner({
|
|||||||
variantOne = testManager.create(ProductVariant, {
|
variantOne = testManager.create(ProductVariant, {
|
||||||
id: productVariantTestOne,
|
id: productVariantTestOne,
|
||||||
title: "variant 1",
|
title: "variant 1",
|
||||||
inventory_quantity: 10,
|
|
||||||
product: productOne,
|
product: productOne,
|
||||||
})
|
})
|
||||||
|
|
||||||
variantTwo = testManager.create(ProductVariant, {
|
variantTwo = testManager.create(ProductVariant, {
|
||||||
id: "test-2",
|
id: "test-2",
|
||||||
title: "variant",
|
title: "variant",
|
||||||
inventory_quantity: 10,
|
|
||||||
product: productOne,
|
product: productOne,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -71,7 +69,6 @@ moduleIntegrationTestRunner({
|
|||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
id: variantOne.id,
|
id: variantOne.id,
|
||||||
title: "variant 1",
|
title: "variant 1",
|
||||||
inventory_quantity: "10",
|
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
@@ -230,7 +227,6 @@ moduleIntegrationTestRunner({
|
|||||||
id: expect.any(String),
|
id: expect.any(String),
|
||||||
title: data.title,
|
title: data.title,
|
||||||
sku: data.sku,
|
sku: data.sku,
|
||||||
inventory_quantity: 100,
|
|
||||||
allow_backorder: false,
|
allow_backorder: false,
|
||||||
manage_inventory: true,
|
manage_inventory: true,
|
||||||
variant_rank: 0,
|
variant_rank: 0,
|
||||||
@@ -261,7 +257,6 @@ moduleIntegrationTestRunner({
|
|||||||
variantOne = testManager.create(ProductVariant, {
|
variantOne = testManager.create(ProductVariant, {
|
||||||
id: productVariantTestOne,
|
id: productVariantTestOne,
|
||||||
title: "variant 1",
|
title: "variant 1",
|
||||||
inventory_quantity: 10,
|
|
||||||
product: productOne,
|
product: productOne,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1275,16 +1275,6 @@
|
|||||||
"nullable": true,
|
"nullable": true,
|
||||||
"mappedType": "text"
|
"mappedType": "text"
|
||||||
},
|
},
|
||||||
"inventory_quantity": {
|
|
||||||
"name": "inventory_quantity",
|
|
||||||
"type": "numeric",
|
|
||||||
"unsigned": false,
|
|
||||||
"autoincrement": false,
|
|
||||||
"primary": false,
|
|
||||||
"nullable": false,
|
|
||||||
"default": "100",
|
|
||||||
"mappedType": "decimal"
|
|
||||||
},
|
|
||||||
"allow_backorder": {
|
"allow_backorder": {
|
||||||
"name": "allow_backorder",
|
"name": "allow_backorder",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Migration } from '@mikro-orm/migrations';
|
import { Migration } from "@mikro-orm/migrations"
|
||||||
|
|
||||||
export class InitialSetup20240315083440 extends Migration {
|
export class InitialSetup20240315083440 extends Migration {
|
||||||
async up(): Promise<void> {
|
async up(): Promise<void> {
|
||||||
@@ -12,7 +12,7 @@ export class InitialSetup20240315083440 extends Migration {
|
|||||||
`alter table "product_option_value" alter column "variant_id" drop not null;`
|
`alter table "product_option_value" alter column "variant_id" drop not null;`
|
||||||
)
|
)
|
||||||
this.addSql(
|
this.addSql(
|
||||||
`alter table "product_variant" alter column "inventory_quantity" drop not null;`
|
`alter table "product_variant" drop column "inventory_quantity";`
|
||||||
)
|
)
|
||||||
this.addSql(
|
this.addSql(
|
||||||
`alter table "product_category" add column "deleted_at" timestamptz null;`
|
`alter table "product_category" add column "deleted_at" timestamptz null;`
|
||||||
@@ -20,80 +20,184 @@ export class InitialSetup20240315083440 extends Migration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* --- ENTITY TABLES AND INDICES --- */
|
/* --- ENTITY TABLES AND INDICES --- */
|
||||||
this.addSql('create table if not exists "product" ("id" text not null, "title" text not null, "handle" text not null, "subtitle" text null, "description" text null, "is_giftcard" boolean not null default false, "status" text check ("status" in (\'draft\', \'proposed\', \'published\', \'rejected\')) not null, "thumbnail" text null, "weight" text null, "length" text null, "height" text null, "width" text null, "origin_country" text null, "hs_code" text null, "mid_code" text null, "material" text null, "collection_id" text null, "type_id" text null, "discountable" boolean not null default true, "external_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "metadata" jsonb null, constraint "product_pkey" primary key ("id"));');
|
this.addSql(
|
||||||
this.addSql('create unique index if not exists "IDX_product_handle_unique" on "product" (handle) where deleted_at is null;')
|
'create table if not exists "product" ("id" text not null, "title" text not null, "handle" text not null, "subtitle" text null, "description" text null, "is_giftcard" boolean not null default false, "status" text check ("status" in (\'draft\', \'proposed\', \'published\', \'rejected\')) not null, "thumbnail" text null, "weight" text null, "length" text null, "height" text null, "width" text null, "origin_country" text null, "hs_code" text null, "mid_code" text null, "material" text null, "collection_id" text null, "type_id" text null, "discountable" boolean not null default true, "external_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, "metadata" jsonb null, constraint "product_pkey" primary key ("id"));'
|
||||||
this.addSql('create index if not exists "IDX_product_type_id" on "product" ("type_id") where deleted_at is null;');
|
)
|
||||||
this.addSql('create index if not exists "IDX_product_collection_id" on "product" ("collection_id") where deleted_at is null;');
|
this.addSql(
|
||||||
this.addSql('create index if not exists "IDX_product_deleted_at" on "product" ("deleted_at");');
|
'create unique index if not exists "IDX_product_handle_unique" on "product" (handle) where deleted_at is null;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create index if not exists "IDX_product_type_id" on "product" ("type_id") where deleted_at is null;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create index if not exists "IDX_product_collection_id" on "product" ("collection_id") where deleted_at is null;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create index if not exists "IDX_product_deleted_at" on "product" ("deleted_at");'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('create table if not exists "product_variant" ("id" text not null, "title" text not null, "sku" text null, "barcode" text null, "ean" text null, "upc" text null, "inventory_quantity" numeric not null default 100, "allow_backorder" boolean not null default false, "manage_inventory" boolean not null default true, "hs_code" text null, "origin_country" text null, "mid_code" text null, "material" text null, "weight" numeric null, "length" numeric null, "height" numeric null, "width" numeric null, "metadata" jsonb null, "variant_rank" numeric null default 0, "product_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_variant_pkey" primary key ("id"));');
|
this.addSql(
|
||||||
this.addSql('create unique index if not exists "IDX_product_variant_ean_unique" on "product_variant" (ean) where deleted_at is null;')
|
'create table if not exists "product_variant" ("id" text not null, "title" text not null, "sku" text null, "barcode" text null, "ean" text null, "upc" text null, "allow_backorder" boolean not null default false, "manage_inventory" boolean not null default true, "hs_code" text null, "origin_country" text null, "mid_code" text null, "material" text null, "weight" numeric null, "length" numeric null, "height" numeric null, "width" numeric null, "metadata" jsonb null, "variant_rank" numeric null default 0, "product_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_variant_pkey" primary key ("id"));'
|
||||||
this.addSql('create unique index if not exists "IDX_product_variant_upc_unique" on "product_variant" (upc) where deleted_at is null;')
|
)
|
||||||
this.addSql('create unique index if not exists "IDX_product_variant_sku_unique" on "product_variant" (sku) where deleted_at is null;')
|
this.addSql(
|
||||||
this.addSql('create unique index if not exists "IDX_product_variant_barcode_unique" on "product_variant" (barcode) where deleted_at is null;')
|
'create unique index if not exists "IDX_product_variant_ean_unique" on "product_variant" (ean) where deleted_at is null;'
|
||||||
this.addSql('create index if not exists "IDX_product_variant_product_id" on "product_variant" ("product_id") where deleted_at is null;');
|
)
|
||||||
this.addSql('create index if not exists "IDX_product_variant_deleted_at" on "product_variant" ("deleted_at");');
|
this.addSql(
|
||||||
|
'create unique index if not exists "IDX_product_variant_upc_unique" on "product_variant" (upc) where deleted_at is null;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create unique index if not exists "IDX_product_variant_sku_unique" on "product_variant" (sku) where deleted_at is null;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create unique index if not exists "IDX_product_variant_barcode_unique" on "product_variant" (barcode) where deleted_at is null;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create index if not exists "IDX_product_variant_product_id" on "product_variant" ("product_id") where deleted_at is null;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create index if not exists "IDX_product_variant_deleted_at" on "product_variant" ("deleted_at");'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('create table if not exists "product_option" ("id" text not null, "title" text not null, "product_id" text null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_option_pkey" primary key ("id"));');
|
this.addSql(
|
||||||
this.addSql('create unique index if not exists "IDX_option_product_id_title_unique" on "product_option" (product_id, title) where deleted_at is null;')
|
'create table if not exists "product_option" ("id" text not null, "title" text not null, "product_id" text null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_option_pkey" primary key ("id"));'
|
||||||
this.addSql('create index if not exists "IDX_product_option_deleted_at" on "product_option" ("deleted_at");');
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create unique index if not exists "IDX_option_product_id_title_unique" on "product_option" (product_id, title) where deleted_at is null;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create index if not exists "IDX_product_option_deleted_at" on "product_option" ("deleted_at");'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('create table if not exists "product_option_value" ("id" text not null, "value" text not null, "option_id" text null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_option_value_pkey" primary key ("id"));');
|
this.addSql(
|
||||||
this.addSql('create unique index if not exists "IDX_option_value_option_id_unique" on "product_option_value" (option_id, value) where deleted_at is null;')
|
'create table if not exists "product_option_value" ("id" text not null, "value" text not null, "option_id" text null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_option_value_pkey" primary key ("id"));'
|
||||||
this.addSql('create index if not exists "IDX_product_option_value_deleted_at" on "product_option_value" ("deleted_at");');
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create unique index if not exists "IDX_option_value_option_id_unique" on "product_option_value" (option_id, value) where deleted_at is null;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create index if not exists "IDX_product_option_value_deleted_at" on "product_option_value" ("deleted_at");'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('create table if not exists "image" ("id" text not null, "url" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "image_pkey" primary key ("id"));');
|
this.addSql(
|
||||||
this.addSql('create index if not exists "IDX_product_image_url" on "image" ("url") where deleted_at is null;');
|
'create table if not exists "image" ("id" text not null, "url" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "image_pkey" primary key ("id"));'
|
||||||
this.addSql('create index if not exists "IDX_product_image_deleted_at" on "image" ("deleted_at");');
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create index if not exists "IDX_product_image_url" on "image" ("url") where deleted_at is null;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create index if not exists "IDX_product_image_deleted_at" on "image" ("deleted_at");'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('create table if not exists "product_tag" ("id" text not null, "value" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_tag_pkey" primary key ("id"));');
|
this.addSql(
|
||||||
|
'create table if not exists "product_tag" ("id" text not null, "value" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_tag_pkey" primary key ("id"));'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('create unique index if not exists "IDX_tag_value_unique" on "product_tag" (value) where deleted_at is null;')
|
this.addSql(
|
||||||
this.addSql('create index if not exists "IDX_product_tag_deleted_at" on "product_tag" ("deleted_at");');
|
'create unique index if not exists "IDX_tag_value_unique" on "product_tag" (value) where deleted_at is null;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create index if not exists "IDX_product_tag_deleted_at" on "product_tag" ("deleted_at");'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('create table if not exists "product_type" ("id" text not null, "value" text not null, "metadata" json null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_type_pkey" primary key ("id"));');
|
this.addSql(
|
||||||
this.addSql('create unique index if not exists "IDX_type_value_unique" on "product_type" (value) where deleted_at is null;')
|
'create table if not exists "product_type" ("id" text not null, "value" text not null, "metadata" json null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_type_pkey" primary key ("id"));'
|
||||||
this.addSql('create index if not exists "IDX_product_type_deleted_at" on "product_type" ("deleted_at");');
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create unique index if not exists "IDX_type_value_unique" on "product_type" (value) where deleted_at is null;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create index if not exists "IDX_product_type_deleted_at" on "product_type" ("deleted_at");'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('create table if not exists "product_collection" ("id" text not null, "title" text not null, "handle" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_collection_pkey" primary key ("id"));');
|
this.addSql(
|
||||||
this.addSql('create unique index if not exists "IDX_collection_handle_unique" on "product_collection" (handle) where deleted_at is null;')
|
'create table if not exists "product_collection" ("id" text not null, "title" text not null, "handle" text not null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_collection_pkey" primary key ("id"));'
|
||||||
this.addSql('create index if not exists "IDX_product_collection_deleted_at" on "product_collection" ("deleted_at");');
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create unique index if not exists "IDX_collection_handle_unique" on "product_collection" (handle) where deleted_at is null;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create index if not exists "IDX_product_collection_deleted_at" on "product_collection" ("deleted_at");'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('create table if not exists "product_category" ("id" text not null, "name" text not null, "description" text not null default \'\', "handle" text not null, "mpath" text not null, "is_active" boolean not null default false, "is_internal" boolean not null default false, "rank" numeric not null default 0, "parent_category_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_category_pkey" primary key ("id"));');
|
this.addSql(
|
||||||
this.addSql('create unique index if not exists "IDX_category_handle_unique" on "product_category" (handle) where deleted_at is null;')
|
'create table if not exists "product_category" ("id" text not null, "name" text not null, "description" text not null default \'\', "handle" text not null, "mpath" text not null, "is_active" boolean not null default false, "is_internal" boolean not null default false, "rank" numeric not null default 0, "parent_category_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "product_category_pkey" primary key ("id"));'
|
||||||
this.addSql('create index if not exists "IDX_product_category_path" on "product_category" ("mpath") where deleted_at is null;');
|
)
|
||||||
this.addSql('create index if not exists "IDX_product_category_deleted_at" on "product_collection" ("deleted_at");');
|
this.addSql(
|
||||||
|
'create unique index if not exists "IDX_category_handle_unique" on "product_category" (handle) where deleted_at is null;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create index if not exists "IDX_product_category_path" on "product_category" ("mpath") where deleted_at is null;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create index if not exists "IDX_product_category_deleted_at" on "product_collection" ("deleted_at");'
|
||||||
|
)
|
||||||
// TODO: Batch updating composite unique index in MikroORM is faulty. Should be added back when issue has been resolved.
|
// TODO: Batch updating composite unique index in MikroORM is faulty. Should be added back when issue has been resolved.
|
||||||
this.addSql(`drop index if exists "UniqProductCategoryParentIdRank";`)
|
this.addSql(`drop index if exists "UniqProductCategoryParentIdRank";`)
|
||||||
|
|
||||||
/* --- PIVOT TABLES --- */
|
/* --- PIVOT TABLES --- */
|
||||||
this.addSql('create table if not exists "product_tags" ("product_id" text not null, "product_tag_id" text not null, constraint "product_tags_pkey" primary key ("product_id", "product_tag_id"));');
|
this.addSql(
|
||||||
this.addSql('create table if not exists "product_images" ("product_id" text not null, "image_id" text not null, constraint "product_images_pkey" primary key ("product_id", "image_id"));');
|
'create table if not exists "product_tags" ("product_id" text not null, "product_tag_id" text not null, constraint "product_tags_pkey" primary key ("product_id", "product_tag_id"));'
|
||||||
this.addSql('create table if not exists "product_category_product" ("product_id" text not null, "product_category_id" text not null, constraint "product_category_product_pkey" primary key ("product_id", "product_category_id"));');
|
)
|
||||||
this.addSql('create table if not exists "product_variant_option" ("variant_id" text not null, "option_value_id" text not null, constraint "product_variant_option_pkey" primary key ("variant_id", "option_value_id"));');
|
this.addSql(
|
||||||
|
'create table if not exists "product_images" ("product_id" text not null, "image_id" text not null, constraint "product_images_pkey" primary key ("product_id", "image_id"));'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create table if not exists "product_category_product" ("product_id" text not null, "product_category_id" text not null, constraint "product_category_product_pkey" primary key ("product_id", "product_category_id"));'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'create table if not exists "product_variant_option" ("variant_id" text not null, "option_value_id" text not null, constraint "product_variant_option_pkey" primary key ("variant_id", "option_value_id"));'
|
||||||
|
)
|
||||||
|
|
||||||
/* --- FOREIGN KEYS AND CONSTRAINTS --- */
|
/* --- FOREIGN KEYS AND CONSTRAINTS --- */
|
||||||
this.addSql('alter table if exists "product" add constraint "product_collection_id_foreign" foreign key ("collection_id") references "product_collection" ("id") on update cascade on delete set null;');
|
this.addSql(
|
||||||
this.addSql('alter table if exists "product" add constraint "product_type_id_foreign" foreign key ("type_id") references "product_type" ("id") on update cascade on delete set null;');
|
'alter table if exists "product" add constraint "product_collection_id_foreign" foreign key ("collection_id") references "product_collection" ("id") on update cascade on delete set null;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'alter table if exists "product" add constraint "product_type_id_foreign" foreign key ("type_id") references "product_type" ("id") on update cascade on delete set null;'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('alter table if exists "product_variant" add constraint "product_variant_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;');
|
this.addSql(
|
||||||
|
'alter table if exists "product_variant" add constraint "product_variant_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('alter table if exists "product_option" add constraint "product_option_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;');
|
this.addSql(
|
||||||
|
'alter table if exists "product_option" add constraint "product_option_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('alter table if exists "product_option_value" add constraint "product_option_value_option_id_foreign" foreign key ("option_id") references "product_option" ("id") on update cascade on delete cascade;');
|
this.addSql(
|
||||||
|
'alter table if exists "product_option_value" add constraint "product_option_value_option_id_foreign" foreign key ("option_id") references "product_option" ("id") on update cascade on delete cascade;'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('alter table if exists "product_variant_option" add constraint "product_variant_option_variant_id_foreign" foreign key ("variant_id") references "product_variant" ("id") on update cascade on delete cascade;');
|
this.addSql(
|
||||||
this.addSql('alter table if exists "product_variant_option" add constraint "product_variant_option_option_value_id_foreign" foreign key ("option_value_id") references "product_option_value" ("id") on update cascade on delete cascade;');
|
'alter table if exists "product_variant_option" add constraint "product_variant_option_variant_id_foreign" foreign key ("variant_id") references "product_variant" ("id") on update cascade on delete cascade;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'alter table if exists "product_variant_option" add constraint "product_variant_option_option_value_id_foreign" foreign key ("option_value_id") references "product_option_value" ("id") on update cascade on delete cascade;'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('alter table if exists "product_images" add constraint "product_images_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;');
|
this.addSql(
|
||||||
this.addSql('alter table if exists "product_images" add constraint "product_images_image_id_foreign" foreign key ("image_id") references "image" ("id") on update cascade on delete cascade;');
|
'alter table if exists "product_images" add constraint "product_images_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'alter table if exists "product_images" add constraint "product_images_image_id_foreign" foreign key ("image_id") references "image" ("id") on update cascade on delete cascade;'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('alter table if exists "product_tags" add constraint "product_tags_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;');
|
this.addSql(
|
||||||
this.addSql('alter table if exists "product_tags" add constraint "product_tags_product_tag_id_foreign" foreign key ("product_tag_id") references "product_tag" ("id") on update cascade on delete cascade;');
|
'alter table if exists "product_tags" add constraint "product_tags_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'alter table if exists "product_tags" add constraint "product_tags_product_tag_id_foreign" foreign key ("product_tag_id") references "product_tag" ("id") on update cascade on delete cascade;'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('alter table if exists "product_category_product" add constraint "product_category_product_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;');
|
this.addSql(
|
||||||
this.addSql('alter table if exists "product_category_product" add constraint "product_category_product_product_category_id_foreign" foreign key ("product_category_id") references "product_category" ("id") on update cascade on delete cascade;');
|
'alter table if exists "product_category_product" add constraint "product_category_product_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;'
|
||||||
|
)
|
||||||
|
this.addSql(
|
||||||
|
'alter table if exists "product_category_product" add constraint "product_category_product_product_category_id_foreign" foreign key ("product_category_id") references "product_category" ("id") on update cascade on delete cascade;'
|
||||||
|
)
|
||||||
|
|
||||||
this.addSql('alter table if exists "product_category" add constraint "product_category_parent_category_id_foreign" foreign key ("parent_category_id") references "product_category" ("id") on update cascade on delete cascade;');
|
this.addSql(
|
||||||
|
'alter table if exists "product_category" add constraint "product_category_parent_category_id_foreign" foreign key ("parent_category_id") references "product_category" ("id") on update cascade on delete cascade;'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,17 +97,6 @@ class ProductVariant {
|
|||||||
@Property({ columnType: "text", nullable: true })
|
@Property({ columnType: "text", nullable: true })
|
||||||
upc?: string | null
|
upc?: string | null
|
||||||
|
|
||||||
// TODO: replace with BigNumber
|
|
||||||
// Note: Upon serialization, this turns to a string. This is on purpose, because you would loose
|
|
||||||
// precision if you cast numeric to JS number, as JS number is a float.
|
|
||||||
// Ref: https://github.com/mikro-orm/mikro-orm/issues/2295
|
|
||||||
@Property({
|
|
||||||
columnType: "numeric",
|
|
||||||
default: 100,
|
|
||||||
serializer: optionalNumericSerializer,
|
|
||||||
})
|
|
||||||
inventory_quantity?: number = 100
|
|
||||||
|
|
||||||
@Property({ columnType: "boolean", default: false })
|
@Property({ columnType: "boolean", default: false })
|
||||||
allow_backorder?: boolean = false
|
allow_backorder?: boolean = false
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user