feat(medusa): Categories - Adds indexes + remove soft delete (#3589)
* chore: added indexes for category properties * chore: added changset * chore: test changeset pre * chore: undo pre release * chore: remove soft delete from categories (#3590) * chore: remove soft delete from categories * chore: remove delete indexes and columns * chore: drop safely + changeset * chore: fix slipped deleted_at * chore: removes extra changeset * chore: redraw indexes * chore: redraw indexes * chore: drop records before dropping column for delete --------- Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
5
.changeset/tall-lions-rescue.md
Normal file
5
.changeset/tall-lions-rescue.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
feat(medusa): remove soft delete from categories + adds indexes for categories
|
||||
@@ -61,8 +61,4 @@ export interface ProductCategory {
|
||||
* The date with timezone at which the resource was updated.
|
||||
*/
|
||||
updated_at: string
|
||||
/**
|
||||
* The date with timezone at which the resource was deleted.
|
||||
*/
|
||||
deleted_at: string | null
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||
|
||||
export class categoryRemoveSoftDelete1679950221063 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DELETE FROM "product_category" WHERE "deleted_at" IS NOT NULL;`)
|
||||
await queryRunner.query(`ALTER TABLE "product_category" DROP COLUMN "deleted_at";`)
|
||||
await queryRunner.query(`DROP INDEX IF EXISTS "IDX_product_category_handle";`)
|
||||
await queryRunner.query(
|
||||
`CREATE UNIQUE INDEX "IDX_product_category_handle" ON "product_category" ("handle");`
|
||||
)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DROP INDEX IF EXISTS "IDX_product_category_handle";`)
|
||||
await queryRunner.query(`ALTER TABLE "product_category" ADD COLUMN "deleted_at" timestamp with time zone;`)
|
||||
await queryRunner.query(
|
||||
`CREATE UNIQUE INDEX "IDX_product_category_handle" ON "product_category" ("handle") WHERE deleted_at IS NULL;`
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm"
|
||||
|
||||
export class categoryCreateIndexes1679950645253 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
CREATE INDEX "IDX_product_category_active_public" ON "product_category" (
|
||||
"parent_category_id",
|
||||
"is_active",
|
||||
"is_internal"
|
||||
) WHERE (
|
||||
("is_active" IS TRUE) AND
|
||||
("is_internal" IS FALSE)
|
||||
);
|
||||
`)
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`
|
||||
DROP INDEX "IDX_product_category_active_public";
|
||||
`)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { generateEntityId } from "../utils/generate-entity-id"
|
||||
import { SoftDeletableEntity } from "../interfaces/models/soft-deletable-entity"
|
||||
import { BaseEntity } from "../interfaces/models/base-entity"
|
||||
import { kebabCase } from "lodash"
|
||||
import { Product } from "."
|
||||
import {
|
||||
@@ -18,14 +18,14 @@ import {
|
||||
@Entity()
|
||||
@Tree("materialized-path")
|
||||
@Index(["parent_category_id", "rank"], { unique: true })
|
||||
export class ProductCategory extends SoftDeletableEntity {
|
||||
export class ProductCategory extends BaseEntity {
|
||||
static productCategoryProductJoinTable = "product_category_product"
|
||||
static treeRelations = ["parent_category", "category_children"]
|
||||
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@Index({ unique: true, where: "deleted_at IS NULL" })
|
||||
@Index({ unique: true })
|
||||
@Column({ nullable: false })
|
||||
handle: string
|
||||
|
||||
@@ -88,7 +88,6 @@ export class ProductCategory extends SoftDeletableEntity {
|
||||
* required:
|
||||
* - category_children
|
||||
* - created_at
|
||||
* - deleted_at
|
||||
* - handle
|
||||
* - id
|
||||
* - is_active
|
||||
@@ -154,9 +153,4 @@ export class ProductCategory extends SoftDeletableEntity {
|
||||
* description: The date with timezone at which the resource was updated.
|
||||
* type: string
|
||||
* format: date-time
|
||||
* deleted_at:
|
||||
* description: The date with timezone at which the resource was deleted.
|
||||
* nullable: true
|
||||
* type: string
|
||||
* format: date-time
|
||||
*/
|
||||
|
||||
@@ -109,10 +109,6 @@ export const ProductCategoryRepository = dataSource
|
||||
queryBuilder.leftJoinAndSelect(`${entityName}.${relation}`, relation)
|
||||
})
|
||||
|
||||
if (options_.withDeleted) {
|
||||
queryBuilder.withDeleted()
|
||||
}
|
||||
|
||||
let [categories, count] = await queryBuilder.getManyAndCount()
|
||||
|
||||
if (includeTree) {
|
||||
|
||||
Reference in New Issue
Block a user