diff --git a/packages/core/types/src/product/common.ts b/packages/core/types/src/product/common.ts index 96da2f0fc4..f527700176 100644 --- a/packages/core/types/src/product/common.ts +++ b/packages/core/types/src/product/common.ts @@ -188,10 +188,6 @@ export interface ProductVariantDTO { * The UPC of the product variant. */ 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. */ @@ -1209,10 +1205,6 @@ export interface CreateProductVariantDTO { * Whether the product variant can be ordered when it's out of stock. */ 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. */ @@ -1310,10 +1302,6 @@ export interface UpdateProductVariantDTO { * Whether the product variant can be ordered when it's out of stock. */ 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. */ diff --git a/packages/core/types/src/workflow/product/create-product-variants.ts b/packages/core/types/src/workflow/product/create-product-variants.ts index 1d7fb0eeba..5d2d241b7e 100644 --- a/packages/core/types/src/workflow/product/create-product-variants.ts +++ b/packages/core/types/src/workflow/product/create-product-variants.ts @@ -11,7 +11,6 @@ export interface CreateProductVariantsInputDTO { upc?: string barcode?: string hs_code?: string - inventory_quantity?: number allow_backorder?: boolean manage_inventory?: boolean weight?: number diff --git a/packages/core/types/src/workflow/product/create-products.ts b/packages/core/types/src/workflow/product/create-products.ts index 9b1f9f21ef..9a841545e6 100644 --- a/packages/core/types/src/workflow/product/create-products.ts +++ b/packages/core/types/src/workflow/product/create-products.ts @@ -44,7 +44,6 @@ export interface CreateProductVariantInputDTO { upc?: string barcode?: string hs_code?: string - inventory_quantity?: number allow_backorder?: boolean manage_inventory?: boolean weight?: number diff --git a/packages/core/types/src/workflow/product/update-product-variants.ts b/packages/core/types/src/workflow/product/update-product-variants.ts index 693eeeb86e..e963d07ff5 100644 --- a/packages/core/types/src/workflow/product/update-product-variants.ts +++ b/packages/core/types/src/workflow/product/update-product-variants.ts @@ -20,7 +20,6 @@ export interface UpdateProductVariantsInputDTO { upc?: string barcode?: string hs_code?: string - inventory_quantity?: number allow_backorder?: boolean manage_inventory?: boolean weight?: number diff --git a/packages/core/types/src/workflow/product/update-products.ts b/packages/core/types/src/workflow/product/update-products.ts index fa73485151..9c6e4c3e6e 100644 --- a/packages/core/types/src/workflow/product/update-products.ts +++ b/packages/core/types/src/workflow/product/update-products.ts @@ -40,7 +40,6 @@ export interface UpdateProductVariantInputDTO { upc?: string barcode?: string hs_code?: string - inventory_quantity?: number allow_backorder?: boolean manage_inventory?: boolean weight?: number diff --git a/packages/core/utils/src/common/__tests__/remote-query-object-to-string.spec.ts b/packages/core/utils/src/common/__tests__/remote-query-object-to-string.spec.ts index fbff611a6a..1c07b3d633 100644 --- a/packages/core/utils/src/common/__tests__/remote-query-object-to-string.spec.ts +++ b/packages/core/utils/src/common/__tests__/remote-query-object-to-string.spec.ts @@ -79,7 +79,6 @@ const remoteQueryObject = { "ean", "upc", "variant_rank", - "inventory_quantity", "allow_backorder", "manage_inventory", "hs_code", @@ -188,7 +187,6 @@ describe("remoteQueryObjectToString", function () { "variants.ean", "variants.upc", "variants.variant_rank", - "variants.inventory_quantity", "variants.allow_backorder", "variants.manage_inventory", "variants.hs_code", diff --git a/packages/medusa/src/api-v2/admin/products/query-config.ts b/packages/medusa/src/api-v2/admin/products/query-config.ts index e5eda87a62..241d8ddcdb 100644 --- a/packages/medusa/src/api-v2/admin/products/query-config.ts +++ b/packages/medusa/src/api-v2/admin/products/query-config.ts @@ -3,7 +3,6 @@ export const defaultAdminProductsVariantFields = [ "product_id", "title", "sku", - "inventory_quantity", "allow_backorder", "manage_inventory", "hs_code", diff --git a/packages/medusa/src/api-v2/admin/products/validators.ts b/packages/medusa/src/api-v2/admin/products/validators.ts index 4310de1c02..5a2b2b006c 100644 --- a/packages/medusa/src/api-v2/admin/products/validators.ts +++ b/packages/medusa/src/api-v2/admin/products/validators.ts @@ -131,7 +131,6 @@ export const AdminCreateProductVariant = z.object({ barcode: z.string().optional(), hs_code: z.string().optional(), mid_code: z.string().optional(), - inventory_quantity: z.number().optional().default(0), allow_backorder: z.boolean().optional().default(false), manage_inventory: z.boolean().optional().default(true), variant_rank: z.number().optional(), @@ -153,7 +152,6 @@ export const AdminUpdateProductVariant = AdminCreateProductVariant.extend({ id: z.string().optional(), title: z.string().optional(), prices: z.array(AdminUpdateVariantPrice).optional(), - inventory_quantity: z.number().optional(), allow_backorder: z.boolean().optional(), manage_inventory: z.boolean().optional(), }).strict() diff --git a/packages/medusa/src/repositories/__mocks__/product-variant.js b/packages/medusa/src/repositories/__mocks__/product-variant.js index f6ce87bcc3..e22e4e5a8b 100644 --- a/packages/medusa/src/repositories/__mocks__/product-variant.js +++ b/packages/medusa/src/repositories/__mocks__/product-variant.js @@ -32,7 +32,6 @@ export const ProductVariantModelMock = { return Promise.resolve({ _id: IdMap.getId("inventory-test"), title: "inventory", - inventory_quantity: 10, allow_backorder: false, manage_inventory: true, }) @@ -41,7 +40,6 @@ export const ProductVariantModelMock = { return Promise.resolve({ _id: IdMap.getId("no-inventory-test"), title: "inventory", - inventory_quantity: 0, allow_backorder: false, manage_inventory: false, }) @@ -50,7 +48,6 @@ export const ProductVariantModelMock = { return Promise.resolve({ _id: IdMap.getId("backorder-test"), title: "inventory", - inventory_quantity: 5, allow_backorder: true, manage_inventory: true, }) diff --git a/packages/modules/product/README.md b/packages/modules/product/README.md index b1a9273811..ac7b6623d8 100644 --- a/packages/modules/product/README.md +++ b/packages/modules/product/README.md @@ -4,7 +4,7 @@ The Product Module gives you access Products, Variants, Categories, and more thr [Product Module documentation](https://docs.medusajs.com/modules/product/serverless-module) | [Medusa Website](https://medusajs.com/) | [Medusa Repository](https://github.com/medusajs/medusa) -> The Product Module is currently in beta. The beta version comes with limited functionality, primarily centered around retrieving products. In the official version, the product module will be fully-fledged and on par with the product functionality in our core package. +> The Product Module is currently in beta. The beta version comes with limited functionality, primarily centered around retrieving products. In the official version, the product module will be fully-fledged and on par with the product functionality in our core package. --- @@ -120,14 +120,12 @@ const variantsData = [ title: "variant title", sku: "sku 1", product: { id: productsData[0].id }, - inventory_quantity: 10, }, { id: "test-2", title: "variant title", sku: "sku 2", product: { id: productsData[1].id }, - inventory_quantity: 10, }, ] diff --git a/packages/modules/product/integration-tests/__fixtures__/product/data/products.ts b/packages/modules/product/integration-tests/__fixtures__/product/data/products.ts index ebd58385cb..0fb849ff9c 100644 --- a/packages/modules/product/integration-tests/__fixtures__/product/data/products.ts +++ b/packages/modules/product/integration-tests/__fixtures__/product/data/products.ts @@ -42,13 +42,11 @@ export const variantsData = [ title: "variant title", sku: "sku 1", product: { id: productsData[0].id }, - inventory_quantity: 10, }, { id: "test-2", title: "variant title", sku: "sku 2", product: { id: productsData[1].id }, - inventory_quantity: 10, }, ] diff --git a/packages/modules/product/integration-tests/__fixtures__/variant/data/create-variant.ts b/packages/modules/product/integration-tests/__fixtures__/variant/data/create-variant.ts index fd1c70e4c9..a0e496391e 100644 --- a/packages/modules/product/integration-tests/__fixtures__/variant/data/create-variant.ts +++ b/packages/modules/product/integration-tests/__fixtures__/variant/data/create-variant.ts @@ -8,7 +8,6 @@ export const buildProductVariantOnlyData = ({ ean, upc, allow_backorder, - inventory_quantity, manage_inventory, hs_code, origin_country, @@ -28,7 +27,6 @@ export const buildProductVariantOnlyData = ({ ean, upc, allow_backorder, - inventory_quantity, manage_inventory, hs_code, origin_country, diff --git a/packages/modules/product/integration-tests/__tests__/services/product-module-service/product-variants.spec.ts b/packages/modules/product/integration-tests/__tests__/services/product-module-service/product-variants.spec.ts index 5d08e8e9cf..8e873b3fbd 100644 --- a/packages/modules/product/integration-tests/__tests__/services/product-module-service/product-variants.spec.ts +++ b/packages/modules/product/integration-tests/__tests__/services/product-module-service/product-variants.spec.ts @@ -44,7 +44,6 @@ moduleIntegrationTestRunner({ variantOne = await service.createVariants({ id: "test-1", title: "variant 1", - inventory_quantity: 10, product_id: productOne.id, options: { size: "large" }, }) @@ -52,7 +51,6 @@ moduleIntegrationTestRunner({ variantTwo = await service.createVariants({ id: "test-2", title: "variant", - inventory_quantity: 10, product_id: productTwo.id, }) }) diff --git a/packages/modules/product/integration-tests/__tests__/services/product-module-service/products.spec.ts b/packages/modules/product/integration-tests/__tests__/services/product-module-service/products.spec.ts index 0d35fe2f0f..1b8ce12d12 100644 --- a/packages/modules/product/integration-tests/__tests__/services/product-module-service/products.spec.ts +++ b/packages/modules/product/integration-tests/__tests__/services/product-module-service/products.spec.ts @@ -119,7 +119,6 @@ moduleIntegrationTestRunner({ { id: "variant-1", title: "variant 1", - inventory_quantity: 10, }, ], }) @@ -145,12 +144,10 @@ moduleIntegrationTestRunner({ { id: "variant-2", title: "variant 2", - inventory_quantity: 10, }, { id: "variant-3", title: "variant 3", - inventory_quantity: 10, options: { size: "small", color: "red", @@ -258,7 +255,6 @@ moduleIntegrationTestRunner({ sku: createdVariant.sku, allow_backorder: false, manage_inventory: true, - inventory_quantity: 100, variant_rank: 0, options: expect.arrayContaining([ expect.objectContaining({ @@ -615,7 +611,6 @@ moduleIntegrationTestRunner({ sku: data.variants[0].sku, allow_backorder: false, manage_inventory: true, - inventory_quantity: 100, variant_rank: 0, options: expect.arrayContaining([ expect.objectContaining({ diff --git a/packages/modules/product/integration-tests/__tests__/services/product-variant/index.ts b/packages/modules/product/integration-tests/__tests__/services/product-variant/index.ts index 63af29c56c..3e0650ae62 100644 --- a/packages/modules/product/integration-tests/__tests__/services/product-variant/index.ts +++ b/packages/modules/product/integration-tests/__tests__/services/product-variant/index.ts @@ -48,14 +48,12 @@ moduleIntegrationTestRunner({ variantOne = testManager.create(ProductVariant, { id: productVariantTestOne, title: "variant 1", - inventory_quantity: 10, product: productOne, }) variantTwo = testManager.create(ProductVariant, { id: "test-2", title: "variant", - inventory_quantity: 10, product: productOne, }) @@ -71,7 +69,6 @@ moduleIntegrationTestRunner({ expect.objectContaining({ id: variantOne.id, title: "variant 1", - inventory_quantity: "10", }), ]) }) @@ -230,7 +227,6 @@ moduleIntegrationTestRunner({ id: expect.any(String), title: data.title, sku: data.sku, - inventory_quantity: 100, allow_backorder: false, manage_inventory: true, variant_rank: 0, @@ -261,7 +257,6 @@ moduleIntegrationTestRunner({ variantOne = testManager.create(ProductVariant, { id: productVariantTestOne, title: "variant 1", - inventory_quantity: 10, product: productOne, }) diff --git a/packages/modules/product/src/migrations/.snapshot-medusa-products.json b/packages/modules/product/src/migrations/.snapshot-medusa-products.json index 72f811710f..776583d0d2 100644 --- a/packages/modules/product/src/migrations/.snapshot-medusa-products.json +++ b/packages/modules/product/src/migrations/.snapshot-medusa-products.json @@ -1275,16 +1275,6 @@ "nullable": true, "mappedType": "text" }, - "inventory_quantity": { - "name": "inventory_quantity", - "type": "numeric", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": false, - "default": "100", - "mappedType": "decimal" - }, "allow_backorder": { "name": "allow_backorder", "type": "boolean", diff --git a/packages/modules/product/src/migrations/InitialSetup20240401153642.ts b/packages/modules/product/src/migrations/InitialSetup20240401153642.ts index 78624cc02c..8e24748615 100644 --- a/packages/modules/product/src/migrations/InitialSetup20240401153642.ts +++ b/packages/modules/product/src/migrations/InitialSetup20240401153642.ts @@ -1,4 +1,4 @@ -import { Migration } from '@mikro-orm/migrations'; +import { Migration } from "@mikro-orm/migrations" export class InitialSetup20240315083440 extends Migration { async up(): Promise { @@ -12,7 +12,7 @@ export class InitialSetup20240315083440 extends Migration { `alter table "product_option_value" alter column "variant_id" drop not null;` ) this.addSql( - `alter table "product_variant" alter column "inventory_quantity" drop not null;` + `alter table "product_variant" drop column "inventory_quantity";` ) this.addSql( `alter table "product_category" add column "deleted_at" timestamptz null;` @@ -20,80 +20,184 @@ export class InitialSetup20240315083440 extends Migration { } /* --- 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('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" ("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 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('create unique index if not exists "IDX_product_variant_ean_unique" on "product_variant" (ean) where deleted_at is null;') - 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_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_ean_unique" on "product_variant" (ean) where deleted_at is null;' + ) + 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('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" ("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 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('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 "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 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('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 "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_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('create index if not exists "IDX_product_tag_deleted_at" on "product_tag" ("deleted_at");'); + this.addSql( + '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('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_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 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('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_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 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('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");'); + 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( + '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. this.addSql(`drop index if exists "UniqProductCategoryParentIdRank";`) /* --- 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('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"));'); + 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( + '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 --- */ - 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('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" 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('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_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('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_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('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_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('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_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;' + ) } } diff --git a/packages/modules/product/src/models/product-variant.ts b/packages/modules/product/src/models/product-variant.ts index 8128b1adf9..f372a7b4aa 100644 --- a/packages/modules/product/src/models/product-variant.ts +++ b/packages/modules/product/src/models/product-variant.ts @@ -97,17 +97,6 @@ class ProductVariant { @Property({ columnType: "text", nullable: true }) 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 }) allow_backorder?: boolean = false