-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(medusa): Added models + repo for products in multiple categories (…
…#3083) * chore: Added models + repo for products in multiple categories * chore: remove join table model + repo * chore: add foreign key constraints * Update packages/medusa/src/migrations/1674455083104-product_category_product.ts Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> * chore: cascade on delete Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
- Loading branch information
1 parent
d25a531
commit 2e7e16b
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@medusajs/medusa": patch | ||
--- | ||
|
||
feat(medusa): Added models + repo for products in multiple categories |
45 changes: 45 additions & 0 deletions
45
packages/medusa/src/migrations/1674455083104-product_category_product.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class productCategoryProduct1674455083104 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
` | ||
CREATE TABLE "product_category_product" ( | ||
"product_category_id" character varying NOT NULL, | ||
"product_id" character varying NOT NULL, | ||
CONSTRAINT "FK_product_category_id" FOREIGN KEY ("product_category_id") REFERENCES product_category("id") ON DELETE CASCADE ON UPDATE NO ACTION, | ||
CONSTRAINT "FK_product_id" FOREIGN KEY ("product_id") REFERENCES product("id") ON DELETE CASCADE ON UPDATE NO ACTION | ||
) | ||
` | ||
) | ||
|
||
await queryRunner.query( | ||
` | ||
CREATE UNIQUE INDEX "IDX_upcp_product_id_product_category_id" | ||
ON "product_category_product" ("product_category_id", "product_id") | ||
` | ||
) | ||
|
||
await queryRunner.query( | ||
` | ||
CREATE INDEX "IDX_pcp_product_category_id" | ||
ON "product_category_product" ("product_category_id") | ||
` | ||
) | ||
|
||
await queryRunner.query( | ||
` | ||
CREATE INDEX "IDX_pcp_product_id" | ||
ON "product_category_product" ("product_id") | ||
` | ||
) | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DROP INDEX "IDX_upcp_product_id_product_category_id"`) | ||
await queryRunner.query(`DROP INDEX "IDX_pcp_product_category_id"`) | ||
await queryRunner.query(`DROP INDEX "IDX_pcp_product_id"`) | ||
|
||
await queryRunner.query(`DROP TABLE "product_category_product"`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters