@ozzaim/medusa-plugin-product-reviews
Version:
A product review plugin for Medusa v1 that allows customers to leave reviews and ratings for products, including optional admin UI.
63 lines (62 loc) • 2.58 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateProductReview1685312235425 = void 0;
const typeorm_1 = require("typeorm");
class CreateProductReview1685312235425 {
async up(queryRunner) {
const tableExists = await queryRunner.hasTable("product_review");
if (tableExists) {
console.log("Table 'product_review' already exists. Skipping creation.");
return;
}
await queryRunner.createTable(new typeorm_1.Table({
name: "product_review",
columns: [
{ name: "id", type: "varchar", isPrimary: true },
{ name: "product_id", type: "varchar" },
{ name: "variant_id", type: "varchar", isNullable: true },
{ name: "rating", type: "int" },
{ name: "title", type: "varchar" },
{ name: "content", type: "text" },
{ name: "approved", type: "boolean", default: false },
{ name: "customer_id", type: "varchar", isNullable: true },
{ name: "customer_email", type: "varchar", isNullable: true },
{ name: "customer_name", type: "varchar", isNullable: true },
{
name: "created_at",
type: "timestamp with time zone",
default: "now()",
},
{
name: "updated_at",
type: "timestamp with time zone",
default: "now()",
},
{
name: "deleted_at",
type: "timestamp with time zone",
isNullable: true,
},
],
foreignKeys: [
{
columnNames: ["product_id"],
referencedTableName: "product",
referencedColumnNames: ["id"],
onDelete: "SET NULL",
},
{
columnNames: ["variant_id"],
referencedTableName: "product_variant",
referencedColumnNames: ["id"],
onDelete: "SET NULL",
},
],
}), true);
console.log("✅ Table 'product_review' created");
}
async down(queryRunner) {
await queryRunner.dropTable("product_review");
}
}
exports.CreateProductReview1685312235425 = CreateProductReview1685312235425;