@devx-commerce/plugin-product-reviews
Version:
Product Reviews Plugin for Medusa
31 lines • 5.41 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Migration20250425092433 = void 0;
const migrations_1 = require("@mikro-orm/migrations");
class Migration20250425092433 extends migrations_1.Migration {
async up() {
this.addSql(`create table if not exists "review_associated_media" ("id" text not null, "url" text not null, "type" text check ("type" in ('IMAGE', 'VIDEO')) not null, "product_review_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "review_associated_media_pkey" primary key ("id"));`);
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_review_associated_media_product_review_id" ON "review_associated_media" (product_review_id) WHERE deleted_at IS NULL;`);
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_review_associated_media_deleted_at" ON "review_associated_media" (deleted_at) WHERE deleted_at IS NULL;`);
this.addSql(`alter table if exists "review_associated_media" add constraint "review_associated_media_product_review_id_foreign" foreign key ("product_review_id") references "product_review" ("id") on update cascade;`);
this.addSql(`drop index if exists "IDX_product_review_order_id";`);
this.addSql(`alter table if exists "product_review" drop column if exists "content", drop column if exists "order_line_item_id", drop column if exists "order_id", drop column if exists "images";`);
this.addSql(`alter table if exists "product_review" add column if not exists "customer_id" text null, add column if not exists "phone" text null, add column if not exists "title" text null, add column if not exists "description" text null, add column if not exists "is_verified_purchase" boolean not null default false, add column if not exists "verified_order_item_id" text null, add column if not exists "verified_order_line_item_id" text null;`);
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_product_review_customer_id" ON "product_review" (customer_id) WHERE deleted_at IS NULL;`);
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_product_review_verified_order_item_id" ON "product_review" (verified_order_item_id) WHERE deleted_at IS NULL;`);
this.addSql(`alter table if exists "product_review" add constraint product_review_rating_check check(rating >= 1 AND rating <= 5);`);
this.addSql(`alter table if exists "product_review_response" add column if not exists "admin_user_id" text not null;`);
}
async down() {
this.addSql(`drop table if exists "review_associated_media" cascade;`);
this.addSql(`drop index if exists "IDX_product_review_customer_id";`);
this.addSql(`drop index if exists "IDX_product_review_verified_order_item_id";`);
this.addSql(`alter table if exists "product_review" drop constraint if exists product_review_rating_check;`);
this.addSql(`alter table if exists "product_review" drop column if exists "customer_id", drop column if exists "phone", drop column if exists "title", drop column if exists "description", drop column if exists "is_verified_purchase", drop column if exists "verified_order_item_id", drop column if exists "verified_order_line_item_id";`);
this.addSql(`alter table if exists "product_review" add column if not exists "content" text null, add column if not exists "order_line_item_id" text null, add column if not exists "order_id" text null, add column if not exists "images" text[] not null;`);
this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_product_review_order_id" ON "product_review" (order_id) WHERE deleted_at IS NULL;`);
this.addSql(`alter table if exists "product_review_response" drop column if exists "admin_user_id";`);
}
}
exports.Migration20250425092433 = Migration20250425092433;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWlncmF0aW9uMjAyNTA0MjUwOTI0MzMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvbW9kdWxlcy9wcm9kdWN0LXJldmlldy9taWdyYXRpb25zL01pZ3JhdGlvbjIwMjUwNDI1MDkyNDMzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLHNEQUFrRDtBQUVsRCxNQUFhLHVCQUF3QixTQUFRLHNCQUFTO0lBRTNDLEtBQUssQ0FBQyxFQUFFO1FBQ2YsSUFBSSxDQUFDLE1BQU0sQ0FBQyw4WEFBOFgsQ0FBQyxDQUFDO1FBQzVZLElBQUksQ0FBQyxNQUFNLENBQUMsdUpBQXVKLENBQUMsQ0FBQztRQUNySyxJQUFJLENBQUMsTUFBTSxDQUFDLHlJQUF5SSxDQUFDLENBQUM7UUFFdkosSUFBSSxDQUFDLE1BQU0sQ0FBQyw0TUFBNE0sQ0FBQyxDQUFDO1FBRTFOLElBQUksQ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