fix(index): logical operators (#13137)
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import ProductModule from "@medusajs/medusa/product"
|
||||
import { defineLink } from "@medusajs/utils"
|
||||
import BrandModule from "../modules/brand"
|
||||
|
||||
const link =
|
||||
process.env.ENABLE_INDEX_MODULE === "true"
|
||||
? defineLink(
|
||||
{
|
||||
linkable: ProductModule.linkable.product.id,
|
||||
filterable: ["description", "material"],
|
||||
isList: true,
|
||||
},
|
||||
{
|
||||
linkable: BrandModule.linkable.brand.id,
|
||||
filterable: ["id", "name"],
|
||||
isList: false,
|
||||
}
|
||||
)
|
||||
: {}
|
||||
|
||||
export default link
|
||||
@@ -0,0 +1,8 @@
|
||||
import { Module } from "@medusajs/utils"
|
||||
import { BrandModuleService } from "./service"
|
||||
|
||||
export const BRAND_MODULE = "brand"
|
||||
|
||||
export default Module(BRAND_MODULE, {
|
||||
service: BrandModuleService,
|
||||
})
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20250805184935 extends Migration {
|
||||
override async up(): Promise<void> {
|
||||
this.addSql(
|
||||
`create table if not exists "brand" ("id" text not null, "name" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "brand_pkey" primary key ("id"));`
|
||||
)
|
||||
this.addSql(
|
||||
`CREATE INDEX IF NOT EXISTS "IDX_brand_deleted_at" ON "brand" (deleted_at) WHERE deleted_at IS NULL;`
|
||||
)
|
||||
}
|
||||
|
||||
override async down(): Promise<void> {
|
||||
this.addSql(`drop table if exists "brand" cascade;`)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { model } from "@medusajs/utils"
|
||||
|
||||
export const Brand = model.define("brand", {
|
||||
id: model.id({ prefix: "brand" }).primaryKey(),
|
||||
name: model.text(),
|
||||
})
|
||||
@@ -0,0 +1,6 @@
|
||||
import { MedusaService } from "@medusajs/utils"
|
||||
import { Brand } from "./models/brand"
|
||||
|
||||
export class BrandModuleService extends MedusaService({
|
||||
Brand,
|
||||
}) {}
|
||||
Reference in New Issue
Block a user