public function setUp()
 {
     parent::setUp();
     dbsteward::set_sql_format('pgsql8');
     // reset these flags before each test
     pgsql8_diff::$as_transaction = TRUE;
     dbsteward::$require_slony_set_id = FALSE;
     dbsteward::$require_slony_id = FALSE;
     dbsteward::$generate_slonik = FALSE;
     dbsteward::$slonyid_set_value = 1;
     dbsteward::$slonyid_start_value = 1;
     // clear these before each test so we don't run into conflicts
     pgsql8::$table_slony_ids = array();
     pgsql8::$sequence_slony_ids = array();
     pgsql8_diff::$new_table_dependency = null;
     pgsql8_diff::$old_table_dependency = null;
     // rest test fixtures
     $this->in_doc = null;
     $this->slonyid_doc = null;
 }
Example #2
0
 private function diff($old, $new, $expected)
 {
     $ofs = new mock_output_file_segmenter();
     $old = '<dbsteward><database/>' . $old . '</dbsteward>';
     $new = '<dbsteward><database/>' . $new . '</dbsteward>';
     $old_doc = simplexml_load_string($old);
     $new_doc = simplexml_load_string($new);
     dbsteward::$old_database = $old_doc;
     dbsteward::$new_database = $new_doc;
     pgsql8_diff::$old_table_dependency = xml_parser::table_dependency_order($old_doc);
     pgsql8_diff::$new_table_dependency = xml_parser::table_dependency_order($new_doc);
     pgsql8_diff_types::apply_changes($ofs, $old_doc->schema, $new_doc->schema);
     $sql = trim(preg_replace('/\\n\\n+/', "\n", preg_replace('/^--.*$/m', '', $ofs->_get_output())));
     $this->assertEquals($expected, $sql);
 }
Example #3
0
 public static function build_upgrade($old_output_prefix, $old_composite_file, $old_db_doc, $old_files, $new_output_prefix, $new_composite_file, $new_db_doc, $new_files)
 {
     // place the upgrade files with the new_files set
     $upgrade_prefix = $new_output_prefix . '_upgrade';
     // pgsql8_diff needs these to intelligently create SQL difference statements in dependency order
     dbsteward::info("Calculating old table foreign key dependency order..");
     pgsql8_diff::$old_table_dependency = xml_parser::table_dependency_order($old_db_doc);
     dbsteward::info("Calculating new table foreign key dependency order..");
     pgsql8_diff::$new_table_dependency = xml_parser::table_dependency_order($new_db_doc);
     pgsql8_diff::diff_doc($old_composite_file, $new_composite_file, $old_db_doc, $new_db_doc, $upgrade_prefix);
     if (dbsteward::$generate_slonik) {
         $replica_sets = pgsql8::get_slony_replica_sets($new_db_doc);
         foreach ($replica_sets as $replica_set) {
             dbsteward::info("Generating replica set " . $replica_set['id'] . " upgrade slonik");
             // separate upgrade slonik file sets for each replica set
             $slonik_upgrade_prefix = $upgrade_prefix . "_slony_replica_set_" . $replica_set['id'];
             // generate upgrade slonik to apply generated sql changes
             $old_new_slonik_header = "# Old definition:  " . implode(', ', $old_files) . "\n" . "# New definition:  " . implode(', ', $new_files) . "\n" . "# Replica set ID " . $replica_set['id'] . "\n";
             $old_replica_set = pgsql8::get_slony_replica_set($old_db_doc, (string) $replica_set['id']);
             pgsql8::build_upgrade_slonik_replica_set($old_db_doc, $new_db_doc, $old_replica_set, $replica_set, $slonik_upgrade_prefix, $old_new_slonik_header);
         }
     }
     return $new_db_doc;
 }
 protected function transaction_statement_check($is_transactional)
 {
     dbsteward::$old_database = new SimpleXMLElement($this->oldxml);
     dbsteward::$new_database = new SimpleXMLElement($this->newxml);
     pgsql8_diff::$new_table_dependency = xml_parser::table_dependency_order(dbsteward::$new_database);
     pgsql8_diff::$old_table_dependency = xml_parser::table_dependency_order(dbsteward::$old_database);
     $ofs = new mock_output_file_segmenter();
     pgsql8_diff::diff_doc_work($ofs, $ofs, $ofs, $ofs);
     if ($is_transactional) {
         $this->assertRegExp('/^BEGIN;/im', $ofs->_get_output(), 'output contains BEGIN statement');
         $this->assertRegExp('/^COMMIT;/im', $ofs->_get_output(), 'output contains COMMIT statement');
     } else {
         $this->assertRegExp('/^(?!BEGIN;).*$/im', $ofs->_get_output(), 'output contains BEGIN statement');
         $this->assertRegExp('/^(?!COMMIT;).*$/im', $ofs->_get_output(), 'output contains COMMIT statement');
     }
 }
 public function setUp()
 {
     parent::setUp();
     dbsteward::set_sql_format('pgsql8');
     // reset runtime mode flags to their default
     dbsteward::$single_stage_upgrade = FALSE;
     dbsteward::$generate_slonik = FALSE;
     pgsql8_diff::$as_transaction = TRUE;
     // reset runtime tracking variables
     pgsql8::$table_slony_ids = array();
     pgsql8::$sequence_slony_ids = array();
     pgsql8::$known_pg_identifiers = array();
     pgsql8_diff::$new_table_dependency = null;
     pgsql8_diff::$old_table_dependency = null;
 }