zZzzZ.
home
/
u763624827
/
domains
/
jkbrothertravels.com
/
public_html
/
database
New Folder
Editing: import_old_route_data.sql
Save
Cancel
SET FOREIGN_KEY_CHECKS=0; SET @ertiga_id := (SELECT `id` FROM `cabs` WHERE `slug` = 'maruti-ertiga' ORDER BY `status` = 'active' DESC, `id` DESC LIMIT 1); SET @crysta_id := (SELECT `id` FROM `cabs` WHERE `slug` IN ('toyota-innova-crysta', 'innova-crysta') ORDER BY `status` = 'active' DESC, `id` DESC LIMIT 1); SET @innova_id := (SELECT `id` FROM `cabs` WHERE `slug` = 'toyota-innova' ORDER BY `status` = 'active' DESC, `id` DESC LIMIT 1); SET @dzire_id := (SELECT `id` FROM `cabs` WHERE `slug` = 'maruti-dzire' ORDER BY `status` = 'active' DESC, `id` DESC LIMIT 1); SET @etios_id := (SELECT `id` FROM `cabs` WHERE `slug` = 'toyota-etios' ORDER BY `status` = 'active' DESC, `id` DESC LIMIT 1); SET @marazzo_id := (SELECT `id` FROM `cabs` WHERE `slug` = 'mahindra-marazzo' ORDER BY `status` = 'active' DESC, `id` DESC LIMIT 1); SET @fortuner_id := (SELECT `id` FROM `cabs` WHERE `slug` = 'fortuner' ORDER BY `status` = 'active' DESC, `id` DESC LIMIT 1); SET @thar_id := (SELECT `id` FROM `cabs` WHERE `slug` = 'thar' ORDER BY `status` = 'active' DESC, `id` DESC LIMIT 1); INSERT INTO `cabs` ( `title`, `price`, `min_mile`, `car_note`, `slug`, `description`, `cab_terms`, `note`, `photo`, `bag`, `ac`, `seaters`, `status`, `created_at`, `updated_at`, `seoTitle`, `seoDescription`, `sort_order`, `round_per_day_price`, `driver_allowance`, `cab_type` ) SELECT `title`, `price`, `min_mile`, `car_note`, `slug`, `description`, `cab_terms`, `note`, `photo`, `bag`, `ac`, `seaters`, `status`, `created_at`, `updated_at`, `seoTitle`, `seoDescription`, `id`, 3000, 0, NULL FROM `jkbrothertravels_old_import`.`cabtype` WHERE `id` = 5 AND @etios_id IS NULL; INSERT INTO `cabs` ( `title`, `price`, `min_mile`, `car_note`, `slug`, `description`, `cab_terms`, `note`, `photo`, `bag`, `ac`, `seaters`, `status`, `created_at`, `updated_at`, `seoTitle`, `seoDescription`, `sort_order`, `round_per_day_price`, `driver_allowance`, `cab_type` ) SELECT `title`, `price`, `min_mile`, `car_note`, `slug`, `description`, `cab_terms`, `note`, `photo`, `bag`, `ac`, `seaters`, `status`, `created_at`, `updated_at`, `seoTitle`, `seoDescription`, `id`, 3000, 0, NULL FROM `jkbrothertravels_old_import`.`cabtype` WHERE `id` = 6 AND @marazzo_id IS NULL; INSERT INTO `cabs` ( `title`, `price`, `min_mile`, `car_note`, `slug`, `description`, `cab_terms`, `note`, `photo`, `bag`, `ac`, `seaters`, `status`, `created_at`, `updated_at`, `seoTitle`, `seoDescription`, `sort_order`, `round_per_day_price`, `driver_allowance`, `cab_type` ) SELECT `title`, `price`, `min_mile`, `car_note`, `slug`, `description`, `cab_terms`, `note`, `photo`, `bag`, `ac`, `seaters`, `status`, `created_at`, `updated_at`, `seoTitle`, `seoDescription`, `id`, 3000, 0, NULL FROM `jkbrothertravels_old_import`.`cabtype` WHERE `id` = 10 AND @thar_id IS NULL; SET @etios_id := (SELECT `id` FROM `cabs` WHERE `slug` = 'toyota-etios' ORDER BY `status` = 'active' DESC, `id` DESC LIMIT 1); SET @marazzo_id := (SELECT `id` FROM `cabs` WHERE `slug` = 'mahindra-marazzo' ORDER BY `status` = 'active' DESC, `id` DESC LIMIT 1); SET @thar_id := (SELECT `id` FROM `cabs` WHERE `slug` = 'thar' ORDER BY `status` = 'active' DESC, `id` DESC LIMIT 1); DELETE FROM `route_services`; DELETE FROM `routes`; DELETE FROM `cities`; INSERT INTO `cities` ( `id`, `name`, `slug`, `image`, `status`, `popular`, `heading`, `description`, `type`, `created_at`, `updated_at`, `seoTitle`, `seoDescription`, `latitude`, `longitude`, `is_airport` ) SELECT `id`, `name`, `slug`, `image`, `status`, COALESCE(`popular`, 'no'), `heading`, `description`, `type`, `created_at`, `updated_at`, `seoTitle`, `seoDescription`, NULL, NULL, CASE WHEN `slug` IN ( 'delhi-airport', 'igi-airport-delhi', 'indra-gandhi-international-airport-delhi', 'airport-delhi', 'delhi-airport-terminal-1', 'delhi-airport-terminal-2', 'delhi-airport-terminal-3', 'chandigarh-air', 'chandigarh-airport', 'mohali-airport', 'hindon-airport', 'hindon-airport-ghaziabad', 'ghaziabad-airport', 'amritsar-airport', 'airport-amritsar' ) THEN 1 ELSE 0 END FROM `jkbrothertravels_old_import`.`category`; INSERT INTO `routes` ( `id`, `title`, `slug`, `tour_from`, `tour_to`, `tour_kilometers`, `description`, `terms`, `created_at`, `updated_at`, `photo`, `status`, `popular`, `seoTitle`, `seoDescription` ) SELECT `id`, `title`, `slug`, `tour_from`, `tour_to`, NULL, `description`, `terms`, `created_at`, `updated_at`, `photo`, `status`, `popular`, `seoTitle`, `seoDescription` FROM `jkbrothertravels_old_import`.`tour`; CREATE TEMPORARY TABLE `old_cab_id_map` ( `old_id` VARCHAR(200) PRIMARY KEY, `new_id` INT NOT NULL ); INSERT INTO `old_cab_id_map` (`old_id`, `new_id`) VALUES ('1', @ertiga_id), ('2', @crysta_id), ('3', @innova_id), ('4', @dzire_id), ('5', @etios_id), ('6', @marazzo_id), ('9', @fortuner_id), ('10', @thar_id); INSERT INTO `route_services` ( `id`, `tour_id`, `car_id`, `onewayPrice`, `roundPrice`, `created_at`, `updated_at` ) SELECT `service`.`id`, `service`.`tour_id`, `map`.`new_id`, CASE WHEN REGEXP_REPLACE(COALESCE(`service`.`onewayPrice`, ''), '[^0-9]', '') = '' THEN NULL ELSE CAST(REGEXP_REPLACE(`service`.`onewayPrice`, '[^0-9]', '') AS UNSIGNED) END, `service`.`roundPrice`, `service`.`created_at`, `service`.`updated_at` FROM `jkbrothertravels_old_import`.`tourService` AS `service` INNER JOIN `old_cab_id_map` AS `map` ON `map`.`old_id` = `service`.`car_id` INNER JOIN `routes` ON `routes`.`id` = `service`.`tour_id`; DROP TEMPORARY TABLE `old_cab_id_map`; SET @next_city_id := (SELECT COALESCE(MAX(`id`), 0) + 1 FROM `cities`); SET @next_route_id := (SELECT COALESCE(MAX(`id`), 0) + 1 FROM `routes`); SET @next_route_service_id := (SELECT COALESCE(MAX(`id`), 0) + 1 FROM `route_services`); SET @next_cab_id := (SELECT COALESCE(MAX(`id`), 0) + 1 FROM `cabs`); SET @alter_city := CONCAT('ALTER TABLE `cities` AUTO_INCREMENT = ', @next_city_id); SET @alter_route := CONCAT('ALTER TABLE `routes` AUTO_INCREMENT = ', @next_route_id); SET @alter_route_service := CONCAT('ALTER TABLE `route_services` AUTO_INCREMENT = ', @next_route_service_id); SET @alter_cab := CONCAT('ALTER TABLE `cabs` AUTO_INCREMENT = ', @next_cab_id); PREPARE stmt FROM @alter_city; EXECUTE stmt; DEALLOCATE PREPARE stmt; PREPARE stmt FROM @alter_route; EXECUTE stmt; DEALLOCATE PREPARE stmt; PREPARE stmt FROM @alter_route_service; EXECUTE stmt; DEALLOCATE PREPARE stmt; PREPARE stmt FROM @alter_cab; EXECUTE stmt; DEALLOCATE PREPARE stmt; SET FOREIGN_KEY_CHECKS=1;