From e1f25bbc8fcf7d53ea3d148f6539497a4bda9366 Mon Sep 17 00:00:00 2001 From: Jacek Pyziak Date: Fri, 27 Feb 2026 18:09:43 +0100 Subject: [PATCH] feat: add product_integration_translations table and migrate marianek.pl data --- ...reate_product_integration_translations.sql | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 database/migrations/20260227_000014_create_product_integration_translations.sql diff --git a/database/migrations/20260227_000014_create_product_integration_translations.sql b/database/migrations/20260227_000014_create_product_integration_translations.sql new file mode 100644 index 0000000..621e112 --- /dev/null +++ b/database/migrations/20260227_000014_create_product_integration_translations.sql @@ -0,0 +1,43 @@ +CREATE TABLE IF NOT EXISTS product_integration_translations ( + id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, + product_id INT UNSIGNED NOT NULL, + integration_id INT UNSIGNED NOT NULL, + name VARCHAR(255) NULL, + short_description TEXT NULL, + description LONGTEXT NULL, + created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + UNIQUE KEY pit_product_integration_unique (product_id, integration_id), + KEY pit_product_idx (product_id), + KEY pit_integration_idx (integration_id), + CONSTRAINT pit_product_fk + FOREIGN KEY (product_id) REFERENCES products(id) + ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT pit_integration_fk + FOREIGN KEY (integration_id) REFERENCES integrations(id) + ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + +-- Migrate existing products to marianek.pl integration. +-- Finds the integration by name 'marianek.pl' and copies current +-- product_translations content for all linked products. +INSERT INTO product_integration_translations + (product_id, integration_id, name, short_description, description, created_at, updated_at) +SELECT + pt.product_id, + i.id AS integration_id, + pt.name, + pt.short_description, + pt.description, + NOW(), + NOW() +FROM product_translations pt +INNER JOIN product_channel_map pcm ON pcm.product_id = pt.product_id +INNER JOIN integrations i ON i.id = pcm.integration_id +WHERE i.name = 'marianek.pl' + AND pt.lang = 'pl' +ON DUPLICATE KEY UPDATE + name = VALUES(name), + short_description = VALUES(short_description), + description = VALUES(description), + updated_at = VALUES(updated_at);