/** * Creates views in dependency order * @param output_file_segmenter $ofs Output file segmenter to write to * @param SimpleXMLElement $db_doc_old Old database document * @param SimpleXMLElement $db_doc_new New database document */ public static function create_views_ordered($ofs, $db_doc_old, $db_doc_new) { static::with_views_in_order($db_doc_new, function ($new_schema, $new_view) use($db_doc_new, $db_doc_old, $ofs) { $old_schema = dbx::get_schema($db_doc_old, $new_schema['name']); $old_view = dbx::get_view($old_schema, $new_view['name']); if (format_diff_views::should_create_view($old_schema, $old_view, $new_schema, $new_view)) { // set replica set context for view if (pgsql8::set_context_replica_set_id($new_view) === -10) { // view doesn't specify one, set from for schema object pgsql8::set_context_replica_set_id($new_schema); } $ofs->write(format_view::get_creation_sql($db_doc_new, $new_schema, $new_view) . "\n"); } }); }
private function doTestViewsCreatedInOrder($format) { dbsteward::set_sql_format($format); $doc = $this->doc_with; $actual = $this->capture(function ($ofs) use($doc) { format_diff_views::create_views_ordered($ofs, null, $doc); }); if ($format == 'pgsql8') { $expected = <<<SQL CREATE OR REPLACE VIEW "public"."view2" AS SELECT * FROM elsewhere; ALTER VIEW "public"."view2" OWNER TO deployment; CREATE OR REPLACE VIEW "public"."view1" AS SELECT * FROM view2; ALTER VIEW "public"."view1" OWNER TO deployment; SQL; } else { $expected = <<<SQL CREATE OR REPLACE DEFINER = deployment SQL SECURITY DEFINER VIEW `view2` AS SELECT * FROM elsewhere; CREATE OR REPLACE DEFINER = deployment SQL SECURITY DEFINER VIEW `view1` AS SELECT * FROM view2; SQL; } $this->assertEquals($expected, $actual); }