diff --git a/sql/mobilemodels_mysql_schema.sql b/sql/mobilemodels_mysql_schema.sql index 9234faf..2445672 100644 --- a/sql/mobilemodels_mysql_schema.sql +++ b/sql/mobilemodels_mysql_schema.sql @@ -6,7 +6,20 @@ CREATE DATABASE IF NOT EXISTS `python_services_test` DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_0900_ai_ci; -DROP VIEW IF EXISTS `python_services_test`.`models`; +SET @drop_stmt = ( + SELECT CASE `TABLE_TYPE` + WHEN 'BASE TABLE' THEN 'DROP TABLE `python_services_test`.`models`' + WHEN 'VIEW' THEN 'DROP VIEW `python_services_test`.`models`' + ELSE 'DO 0' + END + FROM `information_schema`.`TABLES` + WHERE `TABLE_SCHEMA` = 'python_services_test' AND `TABLE_NAME` = 'models' + LIMIT 1 +); +SET @drop_stmt = COALESCE(@drop_stmt, 'DO 0'); +PREPARE stmt FROM @drop_stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; USE `mobilemodels`; @@ -55,8 +68,35 @@ PREPARE stmt FROM @drop_stmt; EXECUTE stmt; DEALLOCATE PREPARE stmt; -DROP VIEW IF EXISTS `vw_mm_device_lookup`; -DROP VIEW IF EXISTS `vw_models`; +SET @drop_stmt = ( + SELECT CASE `TABLE_TYPE` + WHEN 'BASE TABLE' THEN 'DROP TABLE `vw_mm_device_lookup`' + WHEN 'VIEW' THEN 'DROP VIEW `vw_mm_device_lookup`' + ELSE 'DO 0' + END + FROM `information_schema`.`TABLES` + WHERE `TABLE_SCHEMA` = 'mobilemodels' AND `TABLE_NAME` = 'vw_mm_device_lookup' + LIMIT 1 +); +SET @drop_stmt = COALESCE(@drop_stmt, 'DO 0'); +PREPARE stmt FROM @drop_stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; + +SET @drop_stmt = ( + SELECT CASE `TABLE_TYPE` + WHEN 'BASE TABLE' THEN 'DROP TABLE `vw_models`' + WHEN 'VIEW' THEN 'DROP VIEW `vw_models`' + ELSE 'DO 0' + END + FROM `information_schema`.`TABLES` + WHERE `TABLE_SCHEMA` = 'mobilemodels' AND `TABLE_NAME` = 'vw_models' + LIMIT 1 +); +SET @drop_stmt = COALESCE(@drop_stmt, 'DO 0'); +PREPARE stmt FROM @drop_stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; CREATE TABLE IF NOT EXISTS `mm_device_catalog` ( `record_id` varchar(64) NOT NULL,