UNPKG

@alphabite/medusa-wishlist

Version:
38 lines 2.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Migration20260415155648 = void 0; const migrations_1 = require("@mikro-orm/migrations"); class Migration20260415155648 extends migrations_1.Migration { async up() { this.addSql(`alter table if exists "wishlist_item" add column if not exists "product_id" text;`); // Backfill product_id from the variant's product. Guarded against fresh // databases where the product module's migrations haven't created // product_variant yet — Medusa runs each module's migrations independently // with no cross-module ordering guarantee. On a fresh install wishlist_item // is empty so the UPDATE would touch zero rows even if the table existed, // but Postgres parses the FROM clause before execution and errors on // missing relations. The IF EXISTS guard skips cleanly in that case. this.addSql(` DO $$ BEGIN IF EXISTS ( SELECT FROM information_schema.tables WHERE table_name = 'product_variant' ) THEN UPDATE "wishlist_item" wi SET "product_id" = pv.product_id FROM "product_variant" pv WHERE wi.product_variant_id = pv.id AND wi.product_id IS NULL; END IF; END $$; `); this.addSql(`update "wishlist_item" set "product_id" = 'orphaned_product' where "product_id" is null;`); this.addSql(`alter table if exists "wishlist_item" alter column "product_id" set not null;`); } async down() { this.addSql(`alter table if exists "wishlist_item" drop column if exists "product_id";`); } } exports.Migration20260415155648 = Migration20260415155648; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWlncmF0aW9uMjAyNjA0MTUxNTU2NDguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvbW9kdWxlcy93aXNobGlzdC9taWdyYXRpb25zL01pZ3JhdGlvbjIwMjYwNDE1MTU1NjQ4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLHNEQUFrRDtBQUVsRCxNQUFhLHVCQUF3QixTQUFRLHNCQUFTO0lBQzNDLEtBQUssQ0FBQyxFQUFFO1FBQ2YsSUFBSSxDQUFDLE1BQU0sQ0FDVCxtRkFBbUYsQ0FDcEYsQ0FBQztRQUVGLHdFQUF3RTtRQUN4RSxrRUFBa0U7UUFDbEUsMkVBQTJFO1FBQzNFLDRFQUE0RTtRQUM1RSwwRUFBMEU7UUFDMUUscUVBQXFFO1FBQ3JFLHFFQUFxRTtRQUNyRSxJQUFJLENBQUMsTUFBTSxDQUFDOzs7Ozs7Ozs7Ozs7OztLQWNYLENBQUMsQ0FBQztRQUVILElBQUksQ0FBQyxNQUFNLENBQ1QsMEZBQTBGLENBQzNGLENBQUM7UUFFRixJQUFJLENBQUMsTUFBTSxDQUNULCtFQUErRSxDQUNoRixDQUFDO0lBQ0osQ0FBQztJQUVRLEtBQUssQ0FBQyxJQUFJO1FBQ2pCLElBQUksQ0FBQyxNQUFNLENBQ1QsMkVBQTJFLENBQzVFLENBQUM7SUFDSixDQUFDO0NBQ0Y7QUEzQ0QsMERBMkNDIn0=