-- Adminer 4.8.1 MySQL 8.0.45-0ubuntu0.22.04.1 dump

SET foreign_key_checks = 0;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';


CREATE TABLE `ai_model_measurements` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `user_id` int unsigned NOT NULL,
  `measurement_type` enum('app','recheck_api','final','manual') NOT NULL DEFAULT 'app',
  `parent_id` bigint unsigned DEFAULT NULL,
  `measurement_fields` json DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `ai_model_measurements_user_id_foreign` (`user_id`),
  KEY `ai_model_measurements_parent_id_foreign` (`parent_id`),
  CONSTRAINT `ai_model_measurements_parent_id_foreign` FOREIGN KEY (`parent_id`) REFERENCES `ai_model_measurements` (`id`) ON DELETE SET NULL
);

INSERT INTO `ai_model_measurements` (`id`, `user_id`, `measurement_type`, `parent_id`, `measurement_fields`, `deleted_at`, `created_at`, `updated_at`) VALUES
(1,	11131,	'app',	NULL,	'{\"back\": 18, \"knee\": 17, \"neck\": 15, \"bicep\": 14, \"chest\": 40, \"front\": 17, \"thigh\": 23, \"waist\": 35, \"wrist\": 7.5, \"crotch\": 30, \"height\": 170, \"weight\": 70, \"sleeves\": 24, \"shoulder\": 18, \"side_img\": \"enhanced_Caesar-Ronaldo(13).png\", \"foot_size\": 9, \"front_img\": \"enhanced_GettyImages-1443064180(14).png\", \"lower_hip\": 41, \"upper_hip\": 40, \"pant_waist\": 35, \"under_bust\": 36, \"pant_length\": 40, \"weight_unit\": \"kg\", \"shirt_length\": 29, \"natural_waist\": 34, \"shoe_size_unit\": \"us\", \"left_sleeve_length\": 24, \"left_shoulder_slope\": 4.5, \"right_sleeve_length\": 24, \"right_shoulder_slope\": 4.5}',	NULL,	'2026-04-15 04:01:42',	'2026-04-15 04:01:42'),
(2,	11132,	'app',	NULL,	'{\"back\": 18, \"knee\": 17, \"neck\": 15, \"bicep\": 14, \"chest\": 40, \"front\": 17, \"thigh\": 23, \"waist\": 35, \"wrist\": 7.5, \"crotch\": 30, \"height\": 170, \"weight\": 70, \"sleeves\": 24, \"shoulder\": 18, \"foot_size\": 9, \"lower_hip\": 41, \"upper_hip\": 40, \"pant_waist\": 35, \"under_bust\": 36, \"pant_length\": 40, \"weight_unit\": \"kg\", \"shirt_length\": 29, \"natural_waist\": 34, \"shoe_size_unit\": \"dus\", \"left_sleeve_length\": 24, \"left_shoulder_slope\": 4.5, \"right_sleeve_length\": 24, \"right_shoulder_slope\": 4.5}',	NULL,	'2026-04-15 04:01:42',	'2026-04-15 04:01:42'),
(3,	11133,	'app',	NULL,	'{\"back\": 18, \"knee\": 17, \"neck\": 15, \"bicep\": 14, \"chest\": 40, \"front\": 17, \"thigh\": 23, \"waist\": 35, \"wrist\": 7.5, \"crotch\": 30, \"height\": 170, \"weight\": 70, \"sleeves\": 24, \"shoulder\": 18, \"foot_size\": 9, \"lower_hip\": 41, \"upper_hip\": 40, \"pant_waist\": 35, \"under_bust\": 36, \"pant_length\": 40, \"weight_unit\": \"kg\", \"shirt_length\": 29, \"natural_waist\": 34, \"shoe_size_unit\": \"us\", \"left_sleeve_length\": 24, \"left_shoulder_slope\": 4.5, \"right_sleeve_length\": 24, \"right_shoulder_slope\": 4.5}',	NULL,	'2026-04-15 04:01:42',	'2026-04-15 04:01:42'),
(73,	4518,	'app',	NULL,	'{\"back\": 14.23, \"knee\": 13.55, \"neck\": 14.37, \"bicep\": 11.14, \"chest\": 35.51, \"front\": 13.13, \"thigh\": 21.33, \"waist\": 34.25, \"wrist\": 6.12, \"crotch\": 26.38, \"height\": 174.4, \"weight\": 65.4, \"sleeves\": 23.38, \"shoulder\": 16.05, \"side_img\": \"enhanced_Caesar-Ronaldo(23).png\", \"foot_size\": 8.0, \"front_img\": \"enhanced_GettyImages-1443064180(24).png\", \"lower_hip\": 38.06, \"upper_hip\": 33.93, \"pant_waist\": 34.72, \"under_bust\": 33.44, \"pant_length\": 38.67, \"weight_unit\": \"kg\", \"shirt_length\": 27.56, \"natural_waist\": 31.38, \"shoe_size_unit\": \"UK\", \"left_sleeve_length\": 19.94, \"left_shoulder_slope\": 1.98, \"right_sleeve_length\": 19.69, \"right_shoulder_slope\": 1.98}',	NULL,	'2026-04-17 05:26:34',	'2026-04-17 05:26:34');

CREATE TABLE `customer_entity_linked` (
  `id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `entity_id` bigint unsigned NOT NULL,
  `linked_entity_id` bigint unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `customer_entity_linked_unique_pair` (`entity_id`,`linked_entity_id`)
);


-- 2026-04-30 12:52:42



START TRANSACTION;

ALTER TABLE `measurement_parts`
ADD COLUMN `model_key` VARCHAR(64) NULL AFTER `name`;

-- Update existing data FIRST
UPDATE `measurement_parts`
SET `model_key` = CASE
 WHEN `id` = 1 THEN 'shirt_length'
 WHEN `id` = 2 THEN 'chest'
 WHEN `id` = 3 THEN 'upper_hip'
 WHEN `id` = 4 THEN 'front'
 WHEN `id` = 5 THEN 'back'
 WHEN `id` = 6 THEN 'shoulder'
 WHEN `id` = 7 THEN 'sleeves'
 WHEN `id` = 8 THEN 'neck'
 WHEN `id` = 10 THEN 'natural_waist'
 WHEN `id` = 13 THEN 'waist'
 WHEN `id` = 14 THEN 'lower_hip'
 WHEN `id` = 17 THEN 'bicep'
 WHEN `id` = 19 THEN 'thigh'
 WHEN `id` = 20 THEN 'knee'
 WHEN `id` = 23 THEN 'pant_length'
 ELSE `model_key`
END;

-- Add UNIQUE after data is clean
ALTER TABLE `measurement_parts`
ADD UNIQUE KEY `measurement_parts_model_key_unique` (`model_key`);

-- Insert safely
INSERT IGNORE INTO `measurement_parts` (`name`, `model_key`, `is_active`)
VALUES
('Left Sleeve Length', 'left_sleeve_length', 1),
('Right Sleeve Length', 'right_sleeve_length', 1),
('Underbust', 'under_bust', 1),
('Crotch', 'crotch', 1),
('Pant Waist', 'pant_waist', 1),
('Left Shoulder Slope', 'left_shoulder_slope', 1),
('Right Shoulder Slope', 'right_shoulder_slope', 1),
('Wrist', 'wrist', 1);

COMMIT;

