slimdump
slimdump copied to clipboard
Take care of dependencies between VIEW definitions
Since v1.10, slimdump
will also dump VIEW definitions.
One possible issue with that is that one VIEW might be built on top of another one. To make it possible to load the dump into an empty database schema, we need to take these dependencies between VIEWs into consideration.
One approach might be to build something like a dependency graph and dump the VIEWs in the right order. I'd suspect that there cannot be cycles for logical reasons.
The other solution would be to have a look at how mysqldump
solves this. In fact, it creates something like temporary placeholders for views and replacing those in a final phase.
/* many lines removed for clarity ... */
CREATE TABLE `test` (
`id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!50001 CREATE VIEW `view1` AS SELECT 1 AS `id`*/;
/*!50001 CREATE VIEW `view2` AS SELECT 1 AS `id`*/;
--
-- Final view structure for view `view1`
--
/*!50001 DROP VIEW IF EXISTS `view1`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`...`@`...` SQL SECURITY DEFINER */
/*!50001 VIEW `view1` AS select `view2`.`id` AS `id` from `view2` */;
--
-- Final view structure for view `view2`
--
/*!50001 DROP VIEW IF EXISTS `view2`*/;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`...`@`...` SQL SECURITY DEFINER */
/*!50001 VIEW `view2` AS select `test`.`id` AS `id` from `test` */;