Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: using create or replace syntax for view def (#13512)

h3n4l041228a35642
diff --git a/backend/plugin/schema/mysql/get_design_schema.go b/backend/plugin/schema/mysql/get_design_schema.go
index 9f4530dc5f..79147c0b9d 100644
--- a/backend/plugin/schema/mysql/get_design_schema.go
+++ b/backend/plugin/schema/mysql/get_design_schema.go
@@ -174,7 +174,7 @@ func writeFunctions(w io.StringWriter, to *storepb.DatabaseSchemaMetadata, state
}
func getViewAnnouncement(name string) string {
- return fmt.Sprintf("\nDROP VIEW IF EXISTS `%s`;\n--\n-- View structure for `%s`\n--\n", name, name)
+ return fmt.Sprintf("\n--\n-- View structure for `%s`\n--\n", name)
}
func getTableAnnouncement(name string) string {
diff --git a/backend/plugin/schema/mysql/state.go b/backend/plugin/schema/mysql/state.go
index 93dad57546..3474eb6179 100644
--- a/backend/plugin/schema/mysql/state.go
+++ b/backend/plugin/schema/mysql/state.go
@@ -469,7 +469,7 @@ func convertToViewState(id int, view *storepb.ViewMetadata) *viewState {
}
func (v *viewState) toString(buf io.StringWriter) error {
- stmt := fmt.Sprintf("CREATE VIEW `%s` AS %s", v.name, v.definition)
+ stmt := fmt.Sprintf("CREATE OR REPLACE VIEW `%s` AS %s", v.name, v.definition)
if !strings.HasSuffix(stmt, ";") {
stmt += ";"
}
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/function/create-new-function.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/function/create-new-function.yaml
index d9db93f0fa..c8e546e62a 100644
--- a/backend/plugin/schema/mysql/testdata/get-design-schema/function/create-new-function.yaml
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/function/create-new-function.yaml
@@ -53,11 +53,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Function structure for `CalcIncome`
@@ -138,11 +137,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Function structure for `CalcIncome`
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/function/delete-function-without-set.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/function/delete-function-without-set.yaml
index 2d81a2f44e..71b00b2f83 100644
--- a/backend/plugin/schema/mysql/testdata/get-design-schema/function/delete-function-without-set.yaml
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/function/delete-function-without-set.yaml
@@ -57,11 +57,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Function structure for `CalcIncome2`
@@ -173,11 +172,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Function structure for `CalcIncome4`
@@ -289,11 +287,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Function structure for `CalcIncome`
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/function/delete-function.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/function/delete-function.yaml
index 2e3876a142..799c81b60e 100644
--- a/backend/plugin/schema/mysql/testdata/get-design-schema/function/delete-function.yaml
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/function/delete-function.yaml
@@ -57,11 +57,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Function structure for `CalcIncome2`
@@ -173,11 +172,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Function structure for `CalcIncome`
@@ -289,11 +287,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Function structure for `CalcIncome`
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/function/modify-function.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/function/modify-function.yaml
index 0ec378363e..6d1385ded4 100644
--- a/backend/plugin/schema/mysql/testdata/get-design-schema/function/modify-function.yaml
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/function/modify-function.yaml
@@ -53,11 +53,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Function structure for `CalcIncome`
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/procedure/create-new-procedure.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/procedure/create-new-procedure.yaml
index 0d5c70887d..fa46da58ae 100644
--- a/backend/plugin/schema/mysql/testdata/get-design-schema/procedure/create-new-procedure.yaml
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/procedure/create-new-procedure.yaml
@@ -1,29 +1,4 @@
- description: Create new procedure in schema without procedure
- baseline: |-
- SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
- SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
- --
- -- Temporary view structure for `v1`
- --
- CREATE VIEW `v1` AS SELECT
- 1 AS `id`;
-
-
- --
- -- Table structure for `t`
- --
- CREATE TABLE `t` (
- `id` int DEFAULT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
- DROP VIEW IF EXISTS `v1`;
- --
- -- View structure for `v1`
- --
- CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `v1` AS select `t`.`id` AS `id` from `t`;
-
- SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
- SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
target: |-
{
"name": "test_function",
@@ -72,11 +47,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Procedure structure for `citycount`
@@ -88,59 +62,6 @@
END ;;
DELIMITER ;
- description: Create procedure in schema with function
- baseline: |-
- SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
- SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
- --
- -- Temporary view structure for `v1`
- --
- CREATE VIEW `v1` AS SELECT
- 1 AS `id`;
-
-
- --
- -- Table structure for `t`
- --
- CREATE TABLE `t` (
- `id` int DEFAULT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
- DROP VIEW IF EXISTS `v1`;
- --
- -- View structure for `v1`
- --
- CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `v1` AS select `t`.`id` AS `id` from `t`;
-
- --
- -- Procedure structure for `citycount`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` PROCEDURE `citycount`(IN country CHAR(3), OUT cities INT)
- BEGIN
- SELECT 1000 INTO cities;
- END ;;
- DELIMITER ;
-
- --
- -- Procedure structure for `citycount2`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` PROCEDURE `citycount2`(IN country CHAR(3), OUT cities INT)
- BEGIN
- SELECT 1000 INTO cities;
- END ;;
- DELIMITER ;
-
- SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
- SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
target: |-
{
"name": "test_function",
@@ -193,11 +114,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Procedure structure for `citycount`
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/procedure/delete-procedure-without-set.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/procedure/delete-procedure-without-set.yaml
index 531ac1d362..cfc0b6e710 100644
--- a/backend/plugin/schema/mysql/testdata/get-design-schema/procedure/delete-procedure-without-set.yaml
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/procedure/delete-procedure-without-set.yaml
@@ -1,96 +1,4 @@
- description: Delete first procedures in schema
- baseline: |-
- SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
- SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
- --
- -- Temporary view structure for `v1`
- --
- CREATE VIEW `v1` AS SELECT
- 1 AS `id`;
-
-
- --
- -- Table structure for `t`
- --
- CREATE TABLE `t` (
- `id` int DEFAULT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
- DROP VIEW IF EXISTS `v1`;
- --
- -- View structure for `v1`
- --
- CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `v1` AS select `t`.`id` AS `id` from `t`;
-
- --
- -- Function structure for `CalcIncome`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` FUNCTION `CalcIncome`( starting_value INT ) RETURNS int(11)
- DETERMINISTIC
- BEGIN
-
- DECLARE income INT;
-
- SET income = 0;
-
- label1: WHILE income <= 3000 DO
- SET income = income + starting_value;
- END WHILE label1;
-
- RETURN income;
-
- END ;;
- DELIMITER ;
-
- --
- -- Procedure structure for `citycount`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` PROCEDURE `citycount`(IN country CHAR(3), OUT cities INT)
- BEGIN
- SELECT 1000 INTO cities;
- END ;;
- DELIMITER ;
-
- --
- -- Procedure structure for `citycount2`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` PROCEDURE `citycount2`(IN country CHAR(3), OUT cities INT)
- BEGIN
- SELECT 1000 INTO cities;
- END ;;
- DELIMITER ;
-
- --
- -- Procedure structure for `citycount3`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` PROCEDURE `citycount3`(IN country CHAR(3), OUT cities INT)
- BEGIN
- SELECT 1000 INTO cities;
- END ;;
- DELIMITER ;
-
- SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
- SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
target: |-
{
"name": "test_function",
@@ -149,11 +57,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Function structure for `CalcIncome`
@@ -196,98 +103,6 @@
END ;;
DELIMITER ;
- description: Delete second procedures in schema
- baseline: |-
- SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
- SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
- --
- -- Temporary view structure for `v1`
- --
- CREATE VIEW `v1` AS SELECT
- 1 AS `id`;
-
-
- --
- -- Table structure for `t`
- --
- CREATE TABLE `t` (
- `id` int DEFAULT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
- DROP VIEW IF EXISTS `v1`;
- --
- -- View structure for `v1`
- --
- CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `v1` AS select `t`.`id` AS `id` from `t`;
-
- --
- -- Function structure for `CalcIncome`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` FUNCTION `CalcIncome`( starting_value INT ) RETURNS int(11)
- DETERMINISTIC
- BEGIN
-
- DECLARE income INT;
-
- SET income = 0;
-
- label1: WHILE income <= 3000 DO
- SET income = income + starting_value;
- END WHILE label1;
-
- RETURN income;
-
- END ;;
- DELIMITER ;
-
- --
- -- Procedure structure for `citycount`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` PROCEDURE `citycount`(IN country CHAR(3), OUT cities INT)
- BEGIN
- SELECT 1000 INTO cities;
- END ;;
- DELIMITER ;
-
- --
- -- Procedure structure for `citycount2`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` PROCEDURE `citycount2`(IN country CHAR(3), OUT cities INT)
- BEGIN
- SELECT 1000 INTO cities;
- END ;;
- DELIMITER ;
-
- --
- -- Procedure structure for `citycount3`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` PROCEDURE `citycount3`(IN country CHAR(3), OUT cities INT)
- BEGIN
- SELECT 1000 INTO cities;
- END ;;
- DELIMITER ;
-
- SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
- SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
target: |-
{
"name": "test_function",
@@ -346,11 +161,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Function structure for `CalcIncome`
@@ -393,98 +207,6 @@
END ;;
DELIMITER ;
- description: Delete last procedures in schema
- baseline: |-
- SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
- SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
- --
- -- Temporary view structure for `v1`
- --
- CREATE VIEW `v1` AS SELECT
- 1 AS `id`;
-
-
- --
- -- Table structure for `t`
- --
- CREATE TABLE `t` (
- `id` int DEFAULT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
- DROP VIEW IF EXISTS `v1`;
- --
- -- View structure for `v1`
- --
- CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `v1` AS select `t`.`id` AS `id` from `t`;
-
- --
- -- Function structure for `CalcIncome`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` FUNCTION `CalcIncome`( starting_value INT ) RETURNS int(11)
- DETERMINISTIC
- BEGIN
-
- DECLARE income INT;
-
- SET income = 0;
-
- label1: WHILE income <= 3000 DO
- SET income = income + starting_value;
- END WHILE label1;
-
- RETURN income;
-
- END ;;
- DELIMITER ;
-
- --
- -- Procedure structure for `citycount`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` PROCEDURE `citycount`(IN country CHAR(3), OUT cities INT)
- BEGIN
- SELECT 1000 INTO cities;
- END ;;
- DELIMITER ;
-
- --
- -- Procedure structure for `citycount2`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` PROCEDURE `citycount2`(IN country CHAR(3), OUT cities INT)
- BEGIN
- SELECT 1000 INTO cities;
- END ;;
- DELIMITER ;
-
- --
- -- Procedure structure for `citycount3`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` PROCEDURE `citycount3`(IN country CHAR(3), OUT cities INT)
- BEGIN
- SELECT 1000 INTO cities;
- END ;;
- DELIMITER ;
-
- SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
- SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
target: |-
{
"name": "test_function",
@@ -543,11 +265,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Function structure for `CalcIncome`
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/procedure/delete-procedure.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/procedure/delete-procedure.yaml
index 2655682819..318a44c21f 100644
--- a/backend/plugin/schema/mysql/testdata/get-design-schema/procedure/delete-procedure.yaml
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/procedure/delete-procedure.yaml
@@ -1,82 +1,4 @@
- description: Delete all procedures in schema
- baseline: |-
- SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
- SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
- --
- -- Temporary view structure for `v1`
- --
- CREATE VIEW `v1` AS SELECT
- 1 AS `id`;
-
-
- --
- -- Table structure for `t`
- --
- CREATE TABLE `t` (
- `id` int DEFAULT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
- DROP VIEW IF EXISTS `v1`;
- --
- -- View structure for `v1`
- --
- CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `v1` AS select `t`.`id` AS `id` from `t`;
-
- --
- -- Function structure for `CalcIncome`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` FUNCTION `CalcIncome`( starting_value INT ) RETURNS int(11)
- DETERMINISTIC
- BEGIN
-
- DECLARE income INT;
-
- SET income = 0;
-
- label1: WHILE income <= 3000 DO
- SET income = income + starting_value;
- END WHILE label1;
-
- RETURN income;
-
- END ;;
- DELIMITER ;
-
- --
- -- Procedure structure for `citycount`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` PROCEDURE `citycount`(IN country CHAR(3), OUT cities INT)
- BEGIN
- SELECT 1000 INTO cities;
- END ;;
- DELIMITER ;
-
- --
- -- Procedure structure for `citycount2`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` PROCEDURE `citycount2`(IN country CHAR(3), OUT cities INT)
- BEGIN
- SELECT 1000 INTO cities;
- END ;;
- DELIMITER ;
-
- SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
- SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
target: |-
{
"name": "test_function",
@@ -125,11 +47,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Function structure for `CalcIncome`
@@ -152,70 +73,6 @@
END ;;
DELIMITER ;
- description: Delete all procedures in schema
- baseline: |-
- SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
- SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
- --
- -- Temporary view structure for `v1`
- --
- CREATE VIEW `v1` AS SELECT
- 1 AS `id`;
-
-
- --
- -- Table structure for `t`
- --
- CREATE TABLE `t` (
- `id` int DEFAULT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
- DROP VIEW IF EXISTS `v1`;
- --
- -- View structure for `v1`
- --
- CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `v1` AS select `t`.`id` AS `id` from `t`;
-
- --
- -- Function structure for `CalcIncome`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` FUNCTION `CalcIncome`( starting_value INT ) RETURNS int(11)
- DETERMINISTIC
- BEGIN
-
- DECLARE income INT;
-
- SET income = 0;
-
- label1: WHILE income <= 3000 DO
- SET income = income + starting_value;
- END WHILE label1;
-
- RETURN income;
-
- END ;;
- DELIMITER ;
-
- --
- -- Procedure structure for `citycount2`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` PROCEDURE `citycount2`(IN country CHAR(3), OUT cities INT)
- BEGIN
- SELECT 1000 INTO cities;
- END ;;
- DELIMITER ;
-
- SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
- SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
target: |-
{
"name": "test_function",
@@ -264,11 +121,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Function structure for `CalcIncome`
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/procedure/modify-procedure.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/procedure/modify-procedure.yaml
index 0228e596d9..8e5939ab6f 100644
--- a/backend/plugin/schema/mysql/testdata/get-design-schema/procedure/modify-procedure.yaml
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/procedure/modify-procedure.yaml
@@ -1,82 +1,4 @@
- description: Modify procedure
- baseline: |-
- SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
- SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
- --
- -- Temporary view structure for `v1`
- --
- CREATE VIEW `v1` AS SELECT
- 1 AS `id`;
-
-
- --
- -- Table structure for `t`
- --
- CREATE TABLE `t` (
- `id` int DEFAULT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
- DROP VIEW IF EXISTS `v1`;
- --
- -- View structure for `v1`
- --
- CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `v1` AS select `t`.`id` AS `id` from `t`;
-
- --
- -- Function structure for `CalcIncome`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` FUNCTION `CalcIncome`( starting_value INT ) RETURNS int(11)
- DETERMINISTIC
- BEGIN
-
- DECLARE income INT;
-
- SET income = 0;
-
- label1: WHILE income <= 3000 DO
- SET income = income + starting_value;
- END WHILE label1;
-
- RETURN income;
-
- END ;;
- DELIMITER ;
-
- --
- -- Procedure structure for `citycount`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` PROCEDURE `citycount`(IN country CHAR(3), OUT cities INT)
- BEGIN
- SELECT 1000 INTO cities;
- END ;;
- DELIMITER ;
-
- --
- -- Procedure structure for `citycount2`
- --
- SET character_set_client = latin1;
- SET character_set_results = latin1;
- SET collation_connection = latin1_swedish_ci;
- SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
- DELIMITER ;;
- CREATE DEFINER=`root`@`%` PROCEDURE `citycount2`(IN country CHAR(3), OUT cities INT)
- BEGIN
- SELECT 1000 INTO cities;
- END ;;
- DELIMITER ;
-
- SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
- SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
target: |-
{
"name": "test_function",
@@ -135,11 +57,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
--
-- Function structure for `CalcIncome`
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/view/add-new-view.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/view/add-new-view.yaml
index 799412c4d5..fbf3b781cb 100644
--- a/backend/plugin/schema/mysql/testdata/get-design-schema/view/add-new-view.yaml
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/view/add-new-view.yaml
@@ -46,17 +46,15 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
- DROP VIEW IF EXISTS `v2`;
--
-- View structure for `v2`
--
- CREATE VIEW `v2` AS select (`t`.`id` + 1) AS `id + 1` from `t`;
+ CREATE OR REPLACE VIEW `v2` AS select (`t`.`id` + 1) AS `id + 1` from `t`;
- description: Add new view in schema without views
target: |-
{
@@ -104,8 +102,7 @@
`price` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v`;
--
-- View structure for `v`
--
- CREATE VIEW `v` AS select * from `test_view`.`t`;
+ CREATE OR REPLACE VIEW `v` AS select * from `test_view`.`t`;
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/view/drop-view.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/view/drop-view.yaml
index 2a80c88526..95a4ebe8fb 100644
--- a/backend/plugin/schema/mysql/testdata/get-design-schema/view/drop-view.yaml
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/view/drop-view.yaml
@@ -41,11 +41,10 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
- description: Drop all views
target: |-
{
diff --git a/backend/plugin/schema/mysql/testdata/get-design-schema/view/modify-view.yaml b/backend/plugin/schema/mysql/testdata/get-design-schema/view/modify-view.yaml
index 316753924f..efe4017ff8 100644
--- a/backend/plugin/schema/mysql/testdata/get-design-schema/view/modify-view.yaml
+++ b/backend/plugin/schema/mysql/testdata/get-design-schema/view/modify-view.yaml
@@ -46,14 +46,12 @@
`id` int DEFAULT NULL
) ENGINE=InnoDB COLLATE=utf8mb4_0900_ai_ci;
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` + 20 AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` + 20 AS `id` from `t`;
- DROP VIEW IF EXISTS `v2`;
--
-- View structure for `v2`
--
- CREATE VIEW `v2` AS select (`t`.`id` + 30) AS `id + 30` from `t`;
+ CREATE OR REPLACE VIEW `v2` AS select (`t`.`id` + 30) AS `id + 30` from `t`;
diff --git a/backend/plugin/schema/tidb/get_design_schema.go b/backend/plugin/schema/tidb/get_design_schema.go
index fbb65c1d28..b3dc9b00c5 100644
--- a/backend/plugin/schema/tidb/get_design_schema.go
+++ b/backend/plugin/schema/tidb/get_design_schema.go
@@ -93,7 +93,7 @@ func writeViews(w io.StringWriter, to *storepb.DatabaseSchemaMetadata, state *da
}
func getViewAnnouncement(name string) string {
- return fmt.Sprintf("\nDROP VIEW IF EXISTS `%s`;\n--\n-- View structure for `%s`\n--\n", name, name)
+ return fmt.Sprintf("\n--\n-- View structure for `%s`\n--\n", name)
}
func getTableAnnouncement(name string) string {
diff --git a/backend/plugin/schema/tidb/state.go b/backend/plugin/schema/tidb/state.go
index e6522c9662..9b018e2523 100644
--- a/backend/plugin/schema/tidb/state.go
+++ b/backend/plugin/schema/tidb/state.go
@@ -1305,7 +1305,7 @@ func convertToViewState(id int, view *storepb.ViewMetadata) *viewState {
}
func (v *viewState) toString(buf io.StringWriter) error {
- stmt := fmt.Sprintf("CREATE VIEW `%s` AS %s", v.name, v.definition)
+ stmt := fmt.Sprintf("CREATE OR REPLACE VIEW `%s` AS %s", v.name, v.definition)
if !strings.HasSuffix(stmt, ";") {
stmt += ";"
}
diff --git a/backend/plugin/schema/tidb/testdata/get_design_schema.yaml b/backend/plugin/schema/tidb/testdata/get_design_schema.yaml
index 3509926b02..41ffa0e9e0 100644
--- a/backend/plugin/schema/tidb/testdata/get_design_schema.yaml
+++ b/backend/plugin/schema/tidb/testdata/get_design_schema.yaml
@@ -84,17 +84,15 @@
KEY `idx_t_b2` (`b`(20))
);
- DROP VIEW IF EXISTS `v1`;
--
-- View structure for `v1`
--
- CREATE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
+ CREATE OR REPLACE VIEW `v1` AS select `t`.`id` AS `id` from `t`;
- DROP VIEW IF EXISTS `v2`;
--
-- View structure for `v2`
--
- CREATE VIEW `v2` AS select (`t`.`id` + 1) AS `id + 1` from `t`;
+ CREATE OR REPLACE VIEW `v2` AS select (`t`.`id` + 1) AS `id + 1` from `t`;
- target: |-
{
"schemas": [