-- P5-5343: move ref1, ref2, ref3 to product-products table

ALTER TABLE "product-products"
    ADD COLUMN ref1 TEXT,
    ADD COLUMN ref2 TEXT,
    ADD COLUMN ref3 TEXT;

UPDATE "product-products" SET ref1 = (
    SELECT value FROM "product-products_fields"
    WHERE "product-products_fields".productid = "product-products".productid AND fieldid = 22
);

UPDATE "product-products" SET ref2 = (
    SELECT value FROM "product-products_fields"
    WHERE "product-products_fields".productid = "product-products".productid AND fieldid = 23
);

UPDATE "product-products" SET ref3 = (
    SELECT value FROM "product-products_fields"
    WHERE "product-products_fields".productid = "product-products".productid AND fieldid = 24
);

DELETE FROM "product-products_fields" WHERE fieldid = 22;
DELETE FROM "product-products_fields" WHERE fieldid = 23;
DELETE FROM "product-products_fields" WHERE fieldid = 24;

DELETE FROM "product-fields" WHERE fieldid = 22;
DELETE FROM "product-fields" WHERE fieldid = 23;
DELETE FROM "product-fields" WHERE fieldid = 24;
