--
-- Host: 0    Database: mysql_innodb_cluster_metadata
-- ------------------------------------------------------


--
-- GTID state at the beginning of the backup 
--

--
-- Table structure for table `async_cluster_members`
--

CREATE TABLE `async_cluster_members` (
  `cluster_id` char(36) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
  `view_id` int(10) unsigned NOT NULL,
  `instance_id` int(10) unsigned NOT NULL,
  `master_instance_id` int(10) unsigned DEFAULT NULL,
  `primary_master` tinyint(1) NOT NULL,
  `attributes` json NOT NULL,
  PRIMARY KEY (`cluster_id`,`view_id`,`instance_id`),
  KEY `view_id` (`view_id`),
  KEY `instance_id` (`instance_id`),
  CONSTRAINT `async_cluster_members_ibfk_1` FOREIGN KEY (`cluster_id`, `view_id`) REFERENCES `async_cluster_views` (`cluster_id`, `view_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Dumping data for table `async_cluster_members`
--


--
-- Table structure for table `async_cluster_views`
--

CREATE TABLE `async_cluster_views` (
  `cluster_id` char(36) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
  `view_id` int(10) unsigned NOT NULL,
  `topology_type` enum('SINGLE-PRIMARY-TREE') DEFAULT NULL,
  `view_change_reason` varchar(32) NOT NULL,
  `view_change_time` timestamp(6) NOT NULL,
  `view_change_info` json NOT NULL,
  `attributes` json NOT NULL,
  PRIMARY KEY (`cluster_id`,`view_id`),
  KEY `view_id` (`view_id`),
  CONSTRAINT `async_cluster_views_ibfk_1` FOREIGN KEY (`cluster_id`) REFERENCES `clusters` (`cluster_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Dumping data for table `async_cluster_views`
--


--
-- Table structure for table `clusters`
--

CREATE TABLE `clusters` (
  `cluster_id` char(36) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
  `cluster_name` varchar(40) NOT NULL,
  `description` text,
  `options` json DEFAULT NULL,
  `attributes` json DEFAULT NULL,
  `cluster_type` enum('gr','ar') NOT NULL,
  `primary_mode` enum('pm','mm') NOT NULL DEFAULT 'pm',
  `router_options` json DEFAULT NULL,
  PRIMARY KEY (`cluster_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Dumping data for table `clusters`
--

INSERT INTO `clusters` VALUES ('6ac64d08-e0b2-11e9-b85c-473e6231d183','cluster','Default Cluster',NULL,'{\"adopted\": 0, \"default\": true, \"opt_gtidSetIsComplete\": false, \"group_replication_group_name\": \"68442640-e0b2-11e9-b85c-473e6231d183\"}','gr','pm',NULL);

--
-- Table structure for table `instances`
--

CREATE TABLE `instances` (
  `instance_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `cluster_id` char(36) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
  `address` varchar(256) CHARACTER SET ascii COLLATE ascii_general_ci DEFAULT NULL,
  `mysql_server_uuid` char(36) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
  `instance_name` varchar(265) NOT NULL,
  `addresses` json NOT NULL,
  `attributes` json DEFAULT NULL,
  `description` text,
  PRIMARY KEY (`instance_id`,`cluster_id`),
  KEY `cluster_id` (`cluster_id`),
  CONSTRAINT `instances_ibfk_1` FOREIGN KEY (`cluster_id`) REFERENCES `clusters` (`cluster_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4;

--
-- Dumping data for table `instances`
--

INSERT INTO `instances` VALUES (1,'6ac64d08-e0b2-11e9-b85c-473e6231d183','127.0.0.1:3000','11111111-1111-1111-1111-111111111111','127.0.0.1:3000','{\"mysqlX\": \"127.0.0.1:30000\", \"grLocal\": \"127.0.0.1:30001\", \"mysqlClassic\": \"127.0.0.1:3000\"}','{\"recoveryAccountHost\": \"%\", \"recoveryAccountUser\": \"mysql_innodb_cluster_2452472775\"}',NULL);

--
-- Table structure for table `router_rest_accounts`
--

CREATE TABLE `router_rest_accounts` (
  `cluster_id` char(36) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,
  `user` varchar(256) NOT NULL,
  `authentication_method` varchar(64) NOT NULL DEFAULT 'modular_crypt_format',
  `authentication_string` text CHARACTER SET ascii COLLATE ascii_general_ci,
  `description` varchar(255) DEFAULT NULL,
  `privileges` json DEFAULT NULL,
  `attributes` json DEFAULT NULL,
  PRIMARY KEY (`cluster_id`,`user`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Dumping data for table `router_rest_accounts`
--


--
-- Table structure for table `routers`
--

CREATE TABLE `routers` (
  `router_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `router_name` varchar(265) NOT NULL,
  `product_name` varchar(128) NOT NULL,
  `address` varchar(256) CHARACTER SET ascii COLLATE ascii_general_ci DEFAULT NULL,
  `version` varchar(12) DEFAULT NULL,
  `last_check_in` timestamp NULL DEFAULT NULL,
  `attributes` json DEFAULT NULL,
  `cluster_id` char(36) CHARACTER SET ascii COLLATE ascii_general_ci DEFAULT NULL,
  `options` json DEFAULT NULL,
  PRIMARY KEY (`router_id`),
  UNIQUE KEY `address` (`address`,`router_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Dumping data for table `routers`
--


--
-- Temporary view structure for view `schema_version`
--

/*!50001 DROP VIEW IF EXISTS `schema_version`*/;
/*!50001 CREATE VIEW `schema_version` AS SELECT 
 1 AS `major`,
 1 AS `minor`,
 1 AS `patch`*/;

--
-- Temporary view structure for view `v2_ar_clusters`
--

/*!50001 DROP VIEW IF EXISTS `v2_ar_clusters`*/;
/*!50001 CREATE VIEW `v2_ar_clusters` AS SELECT 
 1 AS `view_id`,
 1 AS `cluster_type`,
 1 AS `primary_mode`,
 1 AS `async_topology_type`,
 1 AS `cluster_id`,
 1 AS `cluster_name`,
 1 AS `attributes`,
 1 AS `options`,
 1 AS `router_options`,
 1 AS `description`*/;

--
-- Temporary view structure for view `v2_ar_members`
--

/*!50001 DROP VIEW IF EXISTS `v2_ar_members`*/;
/*!50001 CREATE VIEW `v2_ar_members` AS SELECT 
 1 AS `view_id`,
 1 AS `cluster_id`,
 1 AS `instance_id`,
 1 AS `label`,
 1 AS `member_id`,
 1 AS `member_role`,
 1 AS `master_instance_id`,
 1 AS `master_member_id`*/;

--
-- Temporary view structure for view `v2_clusters`
--

/*!50001 DROP VIEW IF EXISTS `v2_clusters`*/;
/*!50001 CREATE VIEW `v2_clusters` AS SELECT 
 1 AS `cluster_type`,
 1 AS `primary_mode`,
 1 AS `cluster_id`,
 1 AS `cluster_name`,
 1 AS `router_options`*/;

--
-- Temporary view structure for view `v2_gr_clusters`
--

/*!50001 DROP VIEW IF EXISTS `v2_gr_clusters`*/;
/*!50001 CREATE VIEW `v2_gr_clusters` AS SELECT 
 1 AS `cluster_type`,
 1 AS `primary_mode`,
 1 AS `cluster_id`,
 1 AS `cluster_name`,
 1 AS `group_name`,
 1 AS `attributes`,
 1 AS `options`,
 1 AS `router_options`,
 1 AS `description`,
 1 AS `replicated_cluster_id`*/;

--
-- Temporary view structure for view `v2_instances`
--

/*!50001 DROP VIEW IF EXISTS `v2_instances`*/;
/*!50001 CREATE VIEW `v2_instances` AS SELECT 
 1 AS `instance_id`,
 1 AS `cluster_id`,
 1 AS `label`,
 1 AS `mysql_server_uuid`,
 1 AS `address`,
 1 AS `endpoint`,
 1 AS `xendpoint`,
 1 AS `attributes`*/;

--
-- Temporary view structure for view `v2_router_rest_accounts`
--

/*!50001 DROP VIEW IF EXISTS `v2_router_rest_accounts`*/;
/*!50001 CREATE VIEW `v2_router_rest_accounts` AS SELECT 
 1 AS `cluster_id`,
 1 AS `user`,
 1 AS `authentication_method`,
 1 AS `authentication_string`,
 1 AS `description`,
 1 AS `privileges`,
 1 AS `attributes`*/;

--
-- Temporary view structure for view `v2_routers`
--

/*!50001 DROP VIEW IF EXISTS `v2_routers`*/;
/*!50001 CREATE VIEW `v2_routers` AS SELECT 
 1 AS `router_id`,
 1 AS `cluster_id`,
 1 AS `router_name`,
 1 AS `product_name`,
 1 AS `address`,
 1 AS `version`,
 1 AS `last_check_in`,
 1 AS `attributes`,
 1 AS `options`*/;

--
-- Temporary view structure for view `v2_this_instance`
--

/*!50001 DROP VIEW IF EXISTS `v2_this_instance`*/;
/*!50001 CREATE VIEW `v2_this_instance` AS SELECT 
 1 AS `cluster_id`,
 1 AS `instance_id`,
 1 AS `cluster_name`,
 1 AS `cluster_type`*/;

--
-- Final view structure for view `schema_version`
--

/*!50001 DROP VIEW IF EXISTS `schema_version`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY INVOKER */
/*!50001 VIEW `schema_version` (`major`,`minor`,`patch`) AS select 2 AS `2`,0 AS `0`,0 AS `0` */;

--
-- Final view structure for view `v2_ar_clusters`
--

/*!50001 DROP VIEW IF EXISTS `v2_ar_clusters`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY INVOKER */
/*!50001 VIEW `v2_ar_clusters` AS select `acv`.`view_id` AS `view_id`,`c`.`cluster_type` AS `cluster_type`,`c`.`primary_mode` AS `primary_mode`,`acv`.`topology_type` AS `async_topology_type`,`c`.`cluster_id` AS `cluster_id`,`c`.`cluster_name` AS `cluster_name`,`c`.`attributes` AS `attributes`,`c`.`options` AS `options`,`c`.`router_options` AS `router_options`,`c`.`description` AS `description` from (`clusters` `c` join `async_cluster_views` `acv` on((`c`.`cluster_id` = `acv`.`cluster_id`))) where ((`acv`.`view_id` = (select max(`async_cluster_views`.`view_id`) from `async_cluster_views`)) and (`c`.`cluster_type` = 'ar')) */;

--
-- Final view structure for view `v2_ar_members`
--

/*!50001 DROP VIEW IF EXISTS `v2_ar_members`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY INVOKER */
/*!50001 VIEW `v2_ar_members` AS select `acm`.`view_id` AS `view_id`,`i`.`cluster_id` AS `cluster_id`,`i`.`instance_id` AS `instance_id`,`i`.`instance_name` AS `label`,`i`.`mysql_server_uuid` AS `member_id`,if(`acm`.`primary_master`,'PRIMARY','SECONDARY') AS `member_role`,`acm`.`master_instance_id` AS `master_instance_id`,`mi`.`mysql_server_uuid` AS `master_member_id` from ((`instances` `i` left join `async_cluster_members` `acm` on(((`acm`.`cluster_id` = `i`.`cluster_id`) and (`acm`.`instance_id` = `i`.`instance_id`)))) left join `instances` `mi` on((`mi`.`instance_id` = `acm`.`master_instance_id`))) where (`acm`.`view_id` = (select max(`async_cluster_views`.`view_id`) from `async_cluster_views`)) */;

--
-- Final view structure for view `v2_clusters`
--

/*!50001 DROP VIEW IF EXISTS `v2_clusters`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY INVOKER */
/*!50001 VIEW `v2_clusters` AS select `c`.`cluster_type` AS `cluster_type`,`c`.`primary_mode` AS `primary_mode`,`c`.`cluster_id` AS `cluster_id`,`c`.`cluster_name` AS `cluster_name`,`c`.`router_options` AS `router_options` from `clusters` `c` */;

--
-- Final view structure for view `v2_gr_clusters`
--

/*!50001 DROP VIEW IF EXISTS `v2_gr_clusters`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY INVOKER */
/*!50001 VIEW `v2_gr_clusters` AS select `c`.`cluster_type` AS `cluster_type`,`c`.`primary_mode` AS `primary_mode`,`c`.`cluster_id` AS `cluster_id`,`c`.`cluster_name` AS `cluster_name`,json_unquote(json_extract(`c`.`attributes`,'$.group_replication_group_name')) AS `group_name`,`c`.`attributes` AS `attributes`,`c`.`options` AS `options`,`c`.`router_options` AS `router_options`,`c`.`description` AS `description`,NULL AS `replicated_cluster_id` from `clusters` `c` where (`c`.`cluster_type` = 'gr') */;

--
-- Final view structure for view `v2_instances`
--

/*!50001 DROP VIEW IF EXISTS `v2_instances`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY INVOKER */
/*!50001 VIEW `v2_instances` AS select `i`.`instance_id` AS `instance_id`,`i`.`cluster_id` AS `cluster_id`,`i`.`instance_name` AS `label`,`i`.`mysql_server_uuid` AS `mysql_server_uuid`,`i`.`address` AS `address`,json_unquote(json_extract(`i`.`addresses`,'$.mysqlClassic')) AS `endpoint`,json_unquote(json_extract(`i`.`addresses`,'$.mysqlX')) AS `xendpoint`,`i`.`attributes` AS `attributes` from `instances` `i` */;

--
-- Final view structure for view `v2_router_rest_accounts`
--

/*!50001 DROP VIEW IF EXISTS `v2_router_rest_accounts`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY INVOKER */
/*!50001 VIEW `v2_router_rest_accounts` AS select `a`.`cluster_id` AS `cluster_id`,`a`.`user` AS `user`,`a`.`authentication_method` AS `authentication_method`,`a`.`authentication_string` AS `authentication_string`,`a`.`description` AS `description`,`a`.`privileges` AS `privileges`,`a`.`attributes` AS `attributes` from `router_rest_accounts` `a` */;

--
-- Final view structure for view `v2_routers`
--

/*!50001 DROP VIEW IF EXISTS `v2_routers`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY INVOKER */
/*!50001 VIEW `v2_routers` AS select `r`.`router_id` AS `router_id`,`r`.`cluster_id` AS `cluster_id`,`r`.`router_name` AS `router_name`,`r`.`product_name` AS `product_name`,`r`.`address` AS `address`,`r`.`version` AS `version`,`r`.`last_check_in` AS `last_check_in`,`r`.`attributes` AS `attributes`,`r`.`options` AS `options` from `routers` `r` */;

--
-- Final view structure for view `v2_this_instance`
--

/*!50001 DROP VIEW IF EXISTS `v2_this_instance`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`root`@`localhost` SQL SECURITY INVOKER */
/*!50001 VIEW `v2_this_instance` AS select `i`.`cluster_id` AS `cluster_id`,`i`.`instance_id` AS `instance_id`,`c`.`cluster_name` AS `cluster_name`,`c`.`cluster_type` AS `cluster_type` from (`v2_instances` `i` join `clusters` `c` on((`i`.`cluster_id` = `c`.`cluster_id`))) where (convert(`i`.`mysql_server_uuid` using utf8mb4) = (select `performance_schema`.`global_variables`.`VARIABLE_VALUE` from `performance_schema`.`global_variables` where (`performance_schema`.`global_variables`.`VARIABLE_NAME` = 'server_uuid'))) */;


