fix(product, dashboard): manual cleanup of uploaded images (#10254)
* manual cleanup * add changeset * remove thumbnail on deletion
This commit is contained in:
1 parent
df8369028e
commit
c28d0db164
4 files changed
+24
-2
No files matched your search
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/dashboard": patch
|
||||||
|
"@medusajs/product": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(product,dashboard): Avoid duplicating images
|
||||||
+2
-2
@@ -132,8 +132,8 @@ export const EditProductMediaForm = ({ product }: ProductMediaViewProps) => {
|
|||||||
|
|
||||||
await mutateAsync(
|
await mutateAsync(
|
||||||
{
|
{
|
||||||
images: withUpdatedUrls.map((file) => ({ url: file.url })),
|
images: withUpdatedUrls.map((file) => ({ url: file.url, id: file.id })),
|
||||||
thumbnail: thumbnail,
|
thumbnail: thumbnail || null,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
|
|||||||
@@ -19,6 +19,12 @@ export class Migration20241122120331 extends Migration {
|
|||||||
where pi.image_id = i.id;
|
where pi.image_id = i.id;
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
// Delete orphaned images
|
||||||
|
this.addSql(`
|
||||||
|
delete from "image"
|
||||||
|
where product_id is null;
|
||||||
|
`);
|
||||||
|
|
||||||
this.addSql('alter table if exists "image" alter column "product_id" set not null;');
|
this.addSql('alter table if exists "image" alter column "product_id" set not null;');
|
||||||
this.addSql('alter table if exists "image" add constraint "image_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;');
|
this.addSql('alter table if exists "image" add constraint "image_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;');
|
||||||
this.addSql('drop table if exists "product_images" cascade;');
|
this.addSql('drop table if exists "product_images" cascade;');
|
||||||
|
|||||||
@@ -1690,6 +1690,16 @@ export default class ProductModuleService
|
|||||||
sharedContext
|
sharedContext
|
||||||
)
|
)
|
||||||
upsertedProduct.images = productImages
|
upsertedProduct.images = productImages
|
||||||
|
|
||||||
|
await this.productImageService_.delete(
|
||||||
|
{
|
||||||
|
product_id: upsertedProduct.id,
|
||||||
|
id: {
|
||||||
|
$nin: productImages.map(({ id }) => id),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
sharedContext
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
await this.productImageService_.delete(
|
await this.productImageService_.delete(
|
||||||
{ product_id: upsertedProduct.id },
|
{ product_id: upsertedProduct.id },
|
||||||
|
|||||||
Reference in new issue
Block a user