diff --git a/packages/customer/integration-tests/utils/database.ts b/packages/customer/integration-tests/utils/database.ts index 720e81274162d..284863d2c7297 100644 --- a/packages/customer/integration-tests/utils/database.ts +++ b/packages/customer/integration-tests/utils/database.ts @@ -10,9 +10,9 @@ export const MikroOrmWrapper = TestDatabaseUtils.getMikroOrmWrapper({ pathToMigrations, }) -export const MikroOrmConfig = TestDatabaseUtils.getMikroOrmConfig( +export const MikroOrmConfig = TestDatabaseUtils.getMikroOrmConfig({ mikroOrmEntities, - pathToMigrations -) + pathToMigrations, +}) export const DB_URL = TestDatabaseUtils.getDatabaseURL() diff --git a/packages/fulfillment/integration-tests/__tests__/fulfillment-module-service.spec.ts b/packages/fulfillment/integration-tests/__tests__/fulfillment-module-service.spec.ts index 45258f3143425..5922f8e9b60af 100644 --- a/packages/fulfillment/integration-tests/__tests__/fulfillment-module-service.spec.ts +++ b/packages/fulfillment/integration-tests/__tests__/fulfillment-module-service.spec.ts @@ -15,6 +15,8 @@ import { import { GeoZoneType } from "@medusajs/utils" import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils" +jest.setTimeout(100000) + moduleIntegrationTestRunner({ moduleName: Modules.FULFILLMENT, testSuite: ({ diff --git a/packages/fulfillment/src/migrations/.snapshot-medusa-fulfillment.json b/packages/fulfillment/src/migrations/.snapshot-medusa-fulfillment.json index fe755d017a122..d1b7292ae5c14 100644 --- a/packages/fulfillment/src/migrations/.snapshot-medusa-fulfillment.json +++ b/packages/fulfillment/src/migrations/.snapshot-medusa-fulfillment.json @@ -818,13 +818,7 @@ "autoincrement": false, "primary": false, "nullable": false, - "default": "'default'", - "enumItems": [ - "default", - "gift_card", - "custom" - ], - "mappedType": "enum" + "mappedType": "text" }, "metadata": { "name": "metadata", @@ -965,15 +959,6 @@ "nullable": true, "mappedType": "text" }, - "shipping_option_type_id": { - "name": "shipping_option_type_id", - "type": "text", - "unsigned": false, - "autoincrement": false, - "primary": false, - "nullable": true, - "mappedType": "text" - }, "data": { "name": "data", "type": "jsonb", @@ -992,6 +977,15 @@ "nullable": true, "mappedType": "json" }, + "shipping_option_type_id": { + "name": "shipping_option_type_id", + "type": "text", + "unsigned": false, + "autoincrement": false, + "primary": false, + "nullable": true, + "mappedType": "text" + }, "created_at": { "name": "created_at", "type": "timestamptz", @@ -1037,16 +1031,6 @@ "primary": false, "unique": true }, - { - "keyName": "IDX_shipping_option_name_unique", - "columnNames": [ - "name" - ], - "composite": false, - "primary": false, - "unique": false, - "expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_shipping_option_name_unique\" ON \"shipping_option\" (name) WHERE deleted_at IS NULL" - }, { "keyName": "IDX_shipping_option_service_zone_id", "columnNames": [ @@ -1766,7 +1750,7 @@ "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_fulfillment_id\" ON \"fulfillment_item\" (line_item_id) WHERE deleted_at IS NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_line_item_id\" ON \"fulfillment_item\" (line_item_id) WHERE deleted_at IS NULL" }, { "keyName": "IDX_fulfillment_item_inventory_item_id", @@ -1776,7 +1760,7 @@ "composite": false, "primary": false, "unique": false, - "expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_fulfillment_id\" ON \"fulfillment_item\" (inventory_item_id) WHERE deleted_at IS NULL" + "expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_inventory_item_id\" ON \"fulfillment_item\" (inventory_item_id) WHERE deleted_at IS NULL" }, { "keyName": "IDX_fulfillment_item_fulfillment_id", diff --git a/packages/fulfillment/src/migrations/Migration20240215122031.ts b/packages/fulfillment/src/migrations/Migration20240219115644.ts similarity index 93% rename from packages/fulfillment/src/migrations/Migration20240215122031.ts rename to packages/fulfillment/src/migrations/Migration20240219115644.ts index c6e20984ff14f..aa1294981b732 100644 --- a/packages/fulfillment/src/migrations/Migration20240215122031.ts +++ b/packages/fulfillment/src/migrations/Migration20240219115644.ts @@ -1,6 +1,6 @@ import { Migration } from '@mikro-orm/migrations'; -export class Migration20240215122031 extends Migration { +export class Migration20240219115644 extends Migration { async up(): Promise { this.addSql('create table if not exists "fulfillment_address" ("id" text not null, "fulfillment_id" text null, "company" text null, "first_name" text null, "last_name" text null, "address_1" text null, "address_2" text null, "city" text null, "country_code" text null, "province" text null, "postal_code" text null, "phone" text null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "fulfillment_address_pkey" primary key ("id"));'); @@ -30,13 +30,12 @@ export class Migration20240215122031 extends Migration { this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_option_type_shipping_option_id" ON "shipping_option_type" (shipping_option_id) WHERE deleted_at IS NULL;'); this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_option_type_deleted_at" ON "shipping_option_type" (deleted_at) WHERE deleted_at IS NOT NULL;'); - this.addSql('create table if not exists "shipping_profile" ("id" text not null, "name" text not null, "type" text check ("type" in (\'default\', \'gift_card\', \'custom\')) not null default \'default\', "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "shipping_profile_pkey" primary key ("id"));'); + this.addSql('create table if not exists "shipping_profile" ("id" text not null, "name" text not null, "type" 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 "shipping_profile_pkey" primary key ("id"));'); this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_shipping_profile_name_unique" ON "shipping_profile" (name) WHERE deleted_at IS NULL;'); this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_profile_deleted_at" ON "shipping_profile" (deleted_at) WHERE deleted_at IS NOT NULL;'); - this.addSql('create table if not exists "shipping_option" ("id" text not null, "name" text not null, "price_type" text check ("price_type" in (\'calculated\', \'flat\')) not null default \'calculated\', "service_zone_id" text not null, "shipping_profile_id" text null, "service_provider_id" text null, "shipping_option_type_id" text null, "data" jsonb null, "metadata" jsonb null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "shipping_option_pkey" primary key ("id"));'); + this.addSql('create table if not exists "shipping_option" ("id" text not null, "name" text not null, "price_type" text check ("price_type" in (\'calculated\', \'flat\')) not null default \'calculated\', "service_zone_id" text not null, "shipping_profile_id" text null, "service_provider_id" text null, "data" jsonb null, "metadata" jsonb null, "shipping_option_type_id" text null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "shipping_option_pkey" primary key ("id"));'); this.addSql('alter table if exists "shipping_option" add constraint "shipping_option_shipping_option_type_id_unique" unique ("shipping_option_type_id");'); - this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_shipping_option_name_unique" ON "shipping_option" (name) WHERE deleted_at IS NULL;'); this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_option_service_zone_id" ON "shipping_option" (service_zone_id) WHERE deleted_at IS NULL;'); this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_option_shipping_profile_id" ON "shipping_option" (shipping_profile_id) WHERE deleted_at IS NULL;'); this.addSql('CREATE INDEX IF NOT EXISTS "IDX_shipping_option_service_provider_id" ON "shipping_option" (service_provider_id) WHERE deleted_at IS NULL;'); @@ -58,8 +57,8 @@ export class Migration20240215122031 extends Migration { this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_label_deleted_at" ON "fulfillment_label" (deleted_at) WHERE deleted_at IS NOT NULL;'); this.addSql('create table if not exists "fulfillment_item" ("id" text not null, "title" text not null, "sku" text not null, "barcode" text not null, "quantity" numeric not null, "line_item_id" text null, "inventory_item_id" text null, "fulfillment_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "fulfillment_item_pkey" primary key ("id"));'); - this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_fulfillment_id" ON "fulfillment_item" (line_item_id) WHERE deleted_at IS NULL;'); - this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_fulfillment_id" ON "fulfillment_item" (inventory_item_id) WHERE deleted_at IS NULL;'); + this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_line_item_id" ON "fulfillment_item" (line_item_id) WHERE deleted_at IS NULL;'); + this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_inventory_item_id" ON "fulfillment_item" (inventory_item_id) WHERE deleted_at IS NULL;'); this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_fulfillment_id" ON "fulfillment_item" (fulfillment_id) WHERE deleted_at IS NULL;'); this.addSql('CREATE INDEX IF NOT EXISTS "IDX_fulfillment_item_deleted_at" ON "fulfillment_item" (deleted_at) WHERE deleted_at IS NOT NULL;'); diff --git a/packages/fulfillment/src/models/shipping-option.ts b/packages/fulfillment/src/models/shipping-option.ts index 78d565cd8e164..7c5dfa43c62ec 100644 --- a/packages/fulfillment/src/models/shipping-option.ts +++ b/packages/fulfillment/src/models/shipping-option.ts @@ -77,15 +77,29 @@ export default class ShippingOption { }) price_type: ShippingOptionPriceType - @Property({ columnType: "text" }) + @ManyToOne(() => ShippingProfile, { + type: "text", + fieldName: "service_zone_id", + mapToPk: true, + }) @ServiceZoneIdIndex.MikroORMIndex() service_zone_id: string - @Property({ columnType: "text", nullable: true }) + @ManyToOne(() => ShippingProfile, { + type: "text", + fieldName: "shipping_profile_id", + mapToPk: true, + nullable: true, + }) @ShippingProfileIdIndex.MikroORMIndex() shipping_profile_id: string | null - @Property({ columnType: "text", nullable: true }) + @ManyToOne(() => ServiceProvider, { + type: "text", + fieldName: "service_provider_id", + mapToPk: true, + nullable: true, + }) @ServiceProviderIdIndex.MikroORMIndex() service_provider_id: string @@ -104,15 +118,13 @@ export default class ShippingOption { @ManyToOne(() => ShippingProfile, { persist: false, - nullable: true, }) shipping_profile: ShippingProfile | null @ManyToOne(() => ServiceProvider, { persist: false, - nullable: true, }) - service_provider: ServiceProvider + service_provider: ServiceProvider | null @OneToOne(() => ShippingOptionType, (so) => so.shipping_option, { owner: true, diff --git a/packages/medusa-test-utils/src/database.ts b/packages/medusa-test-utils/src/database.ts index 87aae1d141972..dc8c454ff92d7 100644 --- a/packages/medusa-test-utils/src/database.ts +++ b/packages/medusa-test-utils/src/database.ts @@ -1,6 +1,4 @@ import { MikroORM, Options, SqlEntityManager } from "@mikro-orm/postgresql" -import * as process from "process" -import { Migrator } from "@mikro-orm/migrations" export function getDatabaseURL(dbName?: string): string { const DB_HOST = process.env.DB_HOST ?? "localhost" @@ -32,7 +30,6 @@ export function getMikroOrmConfig({ entities: Object.values(mikroOrmEntities), schema: schema ?? process.env.MEDUSA_DB_SCHEMA, debug: false, - extensions: [Migrator], migrations: { pathTs: pathToMigrations, silent: true, diff --git a/packages/medusa-test-utils/src/module-test-runner.ts b/packages/medusa-test-utils/src/module-test-runner.ts index 37f80c3d1d332..8907b633b9d1f 100644 --- a/packages/medusa-test-utils/src/module-test-runner.ts +++ b/packages/medusa-test-utils/src/module-test-runner.ts @@ -18,19 +18,17 @@ export function moduleIntegrationTestRunner({ moduleModels, joinerConfig = [], schema = "public", - migrationPath, testSuite, }: { moduleName: string moduleModels?: any[] joinerConfig?: any[] - migrationPath?: string schema?: string dbName?: string testSuite: (options: SuiteOptions) => () => void }) { moduleModels = Object.values(require(`${process.cwd()}/src/models`)) - migrationPath ??= process.cwd() + "/src/migrations/!(*.d).{js,ts,cjs}" + // migrationPath ??= process.cwd() + "/src/migrations/!(*.d).{js,ts,cjs}" const tempName = parseInt(process.env.JEST_WORKER_ID || "1") const dbName = `medusa-${moduleName.toLowerCase()}-integration-${tempName}` @@ -45,7 +43,6 @@ export function moduleIntegrationTestRunner({ const MikroOrmWrapper = getMikroOrmWrapper({ mikroOrmEntities: moduleModels, - pathToMigrations: migrationPath, clientUrl: dbConfig.clientUrl, schema: dbConfig.schema, }) diff --git a/packages/types/src/fulfillment/mutations/shipping-option.ts b/packages/types/src/fulfillment/mutations/shipping-option.ts index d0967fb89b36f..3070870b079d9 100644 --- a/packages/types/src/fulfillment/mutations/shipping-option.ts +++ b/packages/types/src/fulfillment/mutations/shipping-option.ts @@ -1,12 +1,6 @@ -import { - CreateShippingOptionTypeDTO, - UpdateShippingOptionTypeDTO, -} from "./shipping-option-type" +import { CreateShippingOptionTypeDTO } from "./shipping-option-type" import { ShippingOptionPriceType } from "../common" -import { - CreateShippingOptionRuleDTO, - UpdateShippingOptionRuleDTO, -} from "./shipping-option-rule" +import { CreateShippingOptionRuleDTO } from "./shipping-option-rule" export interface CreateShippingOptionDTO { name: string @@ -26,12 +20,10 @@ export interface UpdateShippingOptionDTO { service_zone_id?: string shipping_profile_id?: string service_provider_id?: string - type: - | Omit - | Omit + type: Omit | { id: string } data?: Record | null rules?: ( | Omit - | Omit + | { id: string } )[] }