@@ -10,35 +10,69 @@ export const User = model.define("user", {
|
||||
name: model.text(),
|
||||
})
|
||||
|
||||
export const Car = model.define("car", {
|
||||
id: model.id().primaryKey(),
|
||||
name: model.text(),
|
||||
})
|
||||
|
||||
export const userJoinerConfig = defineJoinerConfig("User", {
|
||||
models: [User],
|
||||
})
|
||||
|
||||
export const carJoinerConfig = defineJoinerConfig("Car", {
|
||||
models: [Car],
|
||||
})
|
||||
|
||||
export class UserService extends MedusaService({ User }) {
|
||||
constructor() {
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
|
||||
export class CarService extends MedusaService({ Car }) {
|
||||
constructor() {
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
|
||||
export const UserModule = Module("User", {
|
||||
service: UserService,
|
||||
})
|
||||
|
||||
export const Car = model.define("car", {
|
||||
id: model.id().primaryKey(),
|
||||
name: model.text(),
|
||||
})
|
||||
|
||||
export const carJoinerConfig = defineJoinerConfig("Car", {
|
||||
models: [Car],
|
||||
})
|
||||
|
||||
export class CarService extends MedusaService({ Car }) {
|
||||
constructor() {
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
|
||||
export const CarModule = Module("Car", {
|
||||
service: CarService,
|
||||
})
|
||||
|
||||
export const CustomModuleImplementationContainingAReallyBigNameThatExceedsPosgresLimitToNameATable =
|
||||
model.define("very_long_table_name_of_custom_module", {
|
||||
id: model.id().primaryKey(),
|
||||
name: model.text(),
|
||||
})
|
||||
|
||||
export const longNameJoinerConfig = defineJoinerConfig(
|
||||
"CustomModuleImplementationContainingAReallyBigNameThatExceedsPosgresLimitToNameATable",
|
||||
{
|
||||
models: [
|
||||
CustomModuleImplementationContainingAReallyBigNameThatExceedsPosgresLimitToNameATable,
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
export class CustomModuleImplementationContainingAReallyBigNameThatExceedsPosgresLimitToNameATableService extends MedusaService(
|
||||
{
|
||||
CustomModuleImplementationContainingAReallyBigNameThatExceedsPosgresLimitToNameATable,
|
||||
}
|
||||
) {
|
||||
constructor() {
|
||||
super(...arguments)
|
||||
}
|
||||
}
|
||||
|
||||
export const CustomModuleImplementationContainingAReallyBigNameThatExceedsPosgresLimitToNameATableModule =
|
||||
Module(
|
||||
"CustomModuleImplementationContainingAReallyBigNameThatExceedsPosgresLimitToNameATable",
|
||||
{
|
||||
service:
|
||||
CustomModuleImplementationContainingAReallyBigNameThatExceedsPosgresLimitToNameATableService,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
import { MedusaModule } from "@medusajs/modules-sdk"
|
||||
import { ILinkModule, ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { defineLink, isObject, Modules } from "@medusajs/utils"
|
||||
import { Modules, defineLink, isObject } from "@medusajs/utils"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { MigrationsExecutionPlanner } from "../../src"
|
||||
import {
|
||||
Car,
|
||||
carJoinerConfig,
|
||||
CarModule,
|
||||
CustomModuleImplementationContainingAReallyBigNameThatExceedsPosgresLimitToNameATableModule,
|
||||
User,
|
||||
userJoinerConfig,
|
||||
UserModule,
|
||||
carJoinerConfig,
|
||||
longNameJoinerConfig,
|
||||
userJoinerConfig,
|
||||
} from "../__fixtures__/migrations"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
MedusaModule.setJoinerConfig(userJoinerConfig.serviceName, userJoinerConfig)
|
||||
MedusaModule.setJoinerConfig(carJoinerConfig.serviceName, carJoinerConfig)
|
||||
MedusaModule.setJoinerConfig(
|
||||
longNameJoinerConfig.serviceName,
|
||||
longNameJoinerConfig
|
||||
)
|
||||
|
||||
moduleIntegrationTestRunner<ILinkModule>({
|
||||
moduleName: Modules.LINK,
|
||||
@@ -24,6 +30,11 @@ moduleIntegrationTestRunner<ILinkModule>({
|
||||
describe("MigrationsExecutionPlanner", () => {
|
||||
test("should generate an execution plan", async () => {
|
||||
defineLink(UserModule.linkable.user, CarModule.linkable.car)
|
||||
defineLink(
|
||||
UserModule.linkable.user,
|
||||
CustomModuleImplementationContainingAReallyBigNameThatExceedsPosgresLimitToNameATableModule
|
||||
.linkable.veryLongTableNameOfCustomModule
|
||||
)
|
||||
|
||||
MedusaModule.getCustomLinks().forEach((linkDefinition: any) => {
|
||||
MedusaModule.setCustomLink(
|
||||
@@ -44,9 +55,11 @@ moduleIntegrationTestRunner<ILinkModule>({
|
||||
})
|
||||
|
||||
let actionPlan = await planner.createPlan()
|
||||
|
||||
await planner.executePlan(actionPlan)
|
||||
|
||||
expect(actionPlan).toHaveLength(1)
|
||||
expect(actionPlan).toHaveLength(2)
|
||||
|
||||
expect(actionPlan[0]).toEqual({
|
||||
action: "create",
|
||||
linkDescriptor: {
|
||||
@@ -55,8 +68,8 @@ moduleIntegrationTestRunner<ILinkModule>({
|
||||
fromModel: "user",
|
||||
toModel: "car",
|
||||
},
|
||||
tableName: "User_user_Car_car",
|
||||
sql: 'create table "User_user_Car_car" ("user_id" varchar(255) not null, "car_id" varchar(255) not null, "id" varchar(255) not null, "created_at" timestamptz(0) not null default CURRENT_TIMESTAMP, "updated_at" timestamptz(0) not null default CURRENT_TIMESTAMP, "deleted_at" timestamptz(0) null, constraint "User_user_Car_car_pkey" primary key ("user_id", "car_id"));\ncreate index "IDX_car_id_-8c9667b4" on "User_user_Car_car" ("car_id");\ncreate index "IDX_id_-8c9667b4" on "User_user_Car_car" ("id");\ncreate index "IDX_user_id_-8c9667b4" on "User_user_Car_car" ("user_id");\ncreate index "IDX_deleted_at_-8c9667b4" on "User_user_Car_car" ("deleted_at");\n\n',
|
||||
tableName: "user_user_car_car",
|
||||
sql: 'create table "user_user_car_car" ("user_id" varchar(255) not null, "car_id" varchar(255) not null, "id" varchar(255) not null, "created_at" timestamptz(0) not null default CURRENT_TIMESTAMP, "updated_at" timestamptz(0) not null default CURRENT_TIMESTAMP, "deleted_at" timestamptz(0) null, constraint "user_user_car_car_pkey" primary key ("user_id", "car_id"));\ncreate index "IDX_car_id_-8c9667b4" on "user_user_car_car" ("car_id");\ncreate index "IDX_id_-8c9667b4" on "user_user_car_car" ("id");\ncreate index "IDX_user_id_-8c9667b4" on "user_user_car_car" ("user_id");\ncreate index "IDX_deleted_at_-8c9667b4" on "user_user_car_car" ("deleted_at");\n\n',
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -91,7 +104,7 @@ moduleIntegrationTestRunner<ILinkModule>({
|
||||
actionPlan = await planner.createPlan()
|
||||
await planner.executePlan(actionPlan)
|
||||
|
||||
expect(actionPlan).toHaveLength(1)
|
||||
expect(actionPlan).toHaveLength(2)
|
||||
expect(actionPlan[0]).toEqual({
|
||||
action: "update",
|
||||
linkDescriptor: {
|
||||
@@ -100,8 +113,8 @@ moduleIntegrationTestRunner<ILinkModule>({
|
||||
fromModel: "user",
|
||||
toModel: "car",
|
||||
},
|
||||
tableName: "User_user_Car_car",
|
||||
sql: 'alter table "User_user_Car_car" add column "data" jsonb not null;\n\n',
|
||||
tableName: "user_user_car_car",
|
||||
sql: 'alter table "user_user_car_car" add column "data" jsonb not null;\n\n',
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -120,7 +133,7 @@ moduleIntegrationTestRunner<ILinkModule>({
|
||||
fromModel: "user",
|
||||
toModel: "car",
|
||||
},
|
||||
tableName: "User_user_Car_car",
|
||||
tableName: "user_user_car_car",
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -138,7 +151,7 @@ moduleIntegrationTestRunner<ILinkModule>({
|
||||
expect(actionPlan).toHaveLength(1)
|
||||
expect(actionPlan[0]).toEqual({
|
||||
action: "delete",
|
||||
tableName: "User_user_Car_car",
|
||||
tableName: "user_user_car_car",
|
||||
linkDescriptor: {
|
||||
toModel: "car",
|
||||
toModule: "Car",
|
||||
|
||||
Reference in New Issue
Block a user