fix(): product image missing index (#13466)

**What**
Add product image imssing index
This commit is contained in:
Adrien de Peretti
2025-09-10 19:01:04 +02:00
committed by GitHub
parent 8e849074e4
commit 368c1d1e17
4 changed files with 86 additions and 0 deletions

View File

@@ -1189,6 +1189,33 @@
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_image_url\" ON \"image\" (url) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_product_image_rank",
"columnNames": [],
"composite": false,
"constraint": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_image_rank\" ON \"image\" (rank) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_product_image_url_rank_product_id",
"columnNames": [],
"composite": false,
"constraint": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_image_url_rank_product_id\" ON \"image\" (url, rank, product_id) WHERE deleted_at IS NULL"
},
{
"keyName": "IDX_product_image_rank_product_id",
"columnNames": [],
"composite": false,
"constraint": false,
"primary": false,
"unique": false,
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_product_image_rank_product_id\" ON \"image\" (rank, product_id) WHERE deleted_at IS NULL"
},
{
"keyName": "image_pkey",
"columnNames": [

View File

@@ -0,0 +1,36 @@
import { Migration } from "@mikro-orm/migrations"
export class Migration20250910154539 extends Migration {
override async up(): Promise<void> {
this.addSql(
`CREATE INDEX IF NOT EXISTS "IDX_image_product_id" ON "image" (product_id) WHERE deleted_at IS NULL;`
)
this.addSql(
`CREATE INDEX IF NOT EXISTS "IDX_image_deleted_at" ON "image" (deleted_at) WHERE deleted_at IS NULL;`
)
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_rank" ON "image" (rank) WHERE deleted_at IS NULL;`
)
this.addSql(
`CREATE INDEX IF NOT EXISTS "IDX_product_image_url_rank_product_id" ON "image" (url, rank, product_id) WHERE deleted_at IS NULL;`
)
this.addSql(
`CREATE INDEX IF NOT EXISTS "IDX_product_image_rank_product_id" ON "image" (rank, product_id) WHERE deleted_at IS NULL;`
)
}
override async down(): Promise<void> {
this.addSql(`drop index if exists "IDX_image_product_id";`)
this.addSql(`drop index if exists "IDX_image_deleted_at";`)
this.addSql(`drop index if exists "IDX_product_image_url";`)
this.addSql(`drop index if exists "IDX_product_image_rank";`)
this.addSql(`drop index if exists "IDX_product_image_url_rank_product_id";`)
this.addSql(
`alter table if exists "image" drop constraint if exists "image_pkey";`
)
this.addSql(`drop index if exists "IDX_product_image_rank_product_id";`)
}
}

View File

@@ -21,6 +21,24 @@ const ProductImage = model
unique: false,
where: "deleted_at IS NULL",
},
{
name: "IDX_product_image_rank",
on: ["rank"],
unique: false,
where: "deleted_at IS NULL",
},
{
name: "IDX_product_image_url_rank_product_id",
on: ["url", "rank", "product_id"],
unique: false,
where: "deleted_at IS NULL",
},
{
name: "IDX_product_image_rank_product_id",
on: ["rank", "product_id"],
unique: false,
where: "deleted_at IS NULL",
},
])
export default ProductImage