Compare commits

..

1 Commits

Author SHA1 Message Date
review-agent-prime[bot]
812130cc51 Edit packages/database/migrations/20240229062232_adds_styling_column_to_product_model/migration.sql 2024-03-04 16:40:24 +00:00
2 changed files with 32 additions and 31 deletions

View File

@@ -15,37 +15,37 @@ async function main() {
return;
}
const updates = products.map(product => {
if (product.styling !== null) {
// styling object already exists for this product
return;
}
const styling: TStyling = {
unifiedStyling: true,
allowStyleOverwrite: true,
brandColor: {
light: product.brandColor,
},
...(product.highlightBorderColor && {
highlightBorderColor: {
light: product.highlightBorderColor,
dark: product.highlightBorderColor,
if (products.length) {
for (const product of products) {
if (product.styling !== null) {
// styling object already exists for this product
continue;
}
const styling: TStyling = {
unifiedStyling: true,
allowStyleOverwrite: true,
brandColor: {
light: product.brandColor,
},
}),
};
return tx.product.update({
where: {
id: product.id,
},
data: {
styling,
},
});
});
await tx.$transaction(updates);
...(product.highlightBorderColor && {
highlightBorderColor: {
light: product.highlightBorderColor,
dark: product.highlightBorderColor,
},
}),
};
await tx.product.update({
where: {
id: product.id,
},
data: {
styling,
},
});
}
}
});
}

View File

@@ -1,2 +1,3 @@
-- AlterTable
ALTER TABLE "Product" ADD COLUMN "styling" JSONB DEFAULT '{"unifiedStyling":true,"allowStyleOverwrite":true,"brandColor":{"light":"#64748b"}}';
ALTER TABLE "Product" ADD COLUMN "styling" JSONB DEFAULT '{"unifiedStyling":true,"allowStyleOverwrite":true,"brandColor":{"light":"#64748b"}}';
CREATE INDEX idx_product_styling ON "Product" USING gin ("styling");