Exemplo n.º 1
0
 /**
  * @NOTICE: sql_format specific!
  * Compare dbsteward::$old_database to dbsteward::$new_database
  * Generate DDL / DML / DCL statements to upgrade old to new
  *
  * Changes are outputted to output_file_segementer members of this class
  *
  * @param  object  $stage1_ofs  stage 1 output file segmentor
  * @param  object  $stage2_ofs  stage 2 output file segmentor
  * @param  object  $stage3_ofs  stage 3 output file segmentor
  * @param  object  $stage4_ofs  stage 4 output file segmentor
  * @return void
  */
 protected static function diff_doc_work($stage1_ofs, $stage2_ofs, $stage3_ofs, $stage4_ofs)
 {
     if (mssql10_diff::$as_transaction) {
         $stage1_ofs->append_header("BEGIN TRANSACTION;\n\n");
         $stage1_ofs->append_footer("\nCOMMIT TRANSACTION;\n");
         if (!dbsteward::$single_stage_upgrade) {
             $stage2_ofs->append_header("BEGIN TRANSACTION;\n\n");
             $stage3_ofs->append_header("BEGIN TRANSACTION;\n\n");
             $stage4_ofs->append_header("BEGIN TRANSACTION;\n\n");
             $stage2_ofs->append_footer("\nCOMMIT TRANSACTION;\n");
             $stage3_ofs->append_footer("\nCOMMIT TRANSACTION;\n");
             $stage4_ofs->append_footer("\nCOMMIT TRANSACTION;\n");
         }
     }
     // start with pre-upgrade sql statements that prepare the database to take on its changes
     dbx::build_staged_sql(dbsteward::$new_database, $stage1_ofs, 'STAGE1BEFORE');
     dbx::build_staged_sql(dbsteward::$new_database, $stage2_ofs, 'STAGE2BEFORE');
     dbsteward::inf("Drop Old Schemas");
     mssql10_diff::drop_old_schemas($stage3_ofs);
     dbsteward::info("Create New Schemas");
     mssql10_diff::create_new_schemas($stage1_ofs);
     dbsteward::info("Update Structure");
     mssql10_diff::update_structure($stage1_ofs, $stage3_ofs, mssql10_diff::$new_table_dependency);
     dbsteward::info("Update Permissions");
     mssql10_diff::update_permissions($stage1_ofs, $stage3_ofs);
     mssql10_diff::update_database_config_parameters($stage1_ofs);
     dbsteward::info("Update Data");
     mssql10_diff::update_data($stage2_ofs, TRUE);
     mssql10_diff::update_data($stage2_ofs, FALSE);
     // append any literal SQL in new not in old at the end of data stage 1
     $old_sql = dbx::get_sql(dbsteward::$old_database);
     $new_sql = dbx::get_sql(dbsteward::$new_database);
     for ($n = 0; $n < count($new_sql); $n++) {
         if (isset($new_sql[$n]['stage'])) {
             // ignore upgrade staged sql elements
             continue;
         }
         // is this new statement in the old database?
         $found = FALSE;
         for ($o = 0; $o < count($old_sql); $o++) {
             if (isset($old_sql[$o]['stage'])) {
                 // ignore upgrade staged sql elements
                 continue;
             }
             if (strcmp($new_sql[$n], $old_sql[$o]) == 0) {
                 $found = TRUE;
             }
         }
         if (!$found) {
             $stage2_ofs->write($new_sql[$n] . "\n");
         }
     }
     // append stage defined sql statements to appropriate stage file
     dbx::build_staged_sql(dbsteward::$new_database, $stage1_ofs, 'STAGE1');
     dbx::build_staged_sql(dbsteward::$new_database, $stage2_ofs, 'STAGE2');
     dbx::build_staged_sql(dbsteward::$new_database, $stage3_ofs, 'STAGE3');
     dbx::build_staged_sql(dbsteward::$new_database, $stage4_ofs, 'STAGE4');
 }
Exemplo n.º 2
0
 /**
  * @NOTICE: sql_format specific!
  * Compare dbsteward::$old_database to dbsteward::$new_database
  * Generate DDL / DML / DCL statements to upgrade old to new
  *
  * Changes are outputted to output_file_segementer members of this class
  *
  * @param  object  $stage1_ofs  stage 1 output file segmentor
  * @param  object  $stage2_ofs  stage 2 output file segmentor
  * @param  object  $stage3_ofs  stage 3 output file segmentor
  * @param  object  $stage4_ofs  stage 4 output file segmentor
  * @return void
  */
 public static function diff_doc_work($stage1_ofs, $stage2_ofs, $stage3_ofs, $stage4_ofs)
 {
     // this shouldn't be called if we're not generating slonik, it looks for
     // a slony element in <database> which most likely won't be there if
     // we're not interested in slony replication
     if (dbsteward::$generate_slonik) {
         format::set_context_replica_set_to_natural_first(dbsteward::$new_database);
     }
     if (self::$as_transaction) {
         // stage 1 and 3 should not be in a transaction
         // as they will be submitted via slonik EXECUTE SCRIPT
         if (!dbsteward::$generate_slonik) {
             $stage1_ofs->append_header("\nBEGIN;\n");
             $stage1_ofs->append_footer("\nCOMMIT;\n");
         } else {
             $stage1_ofs->append_header("\n-- generateslonik specified: pgsql8 STAGE1 upgrade omitting BEGIN. slonik EXECUTE SCRIPT will wrap stage 1 DDL and DCL in a transaction\n");
         }
         if (!dbsteward::$single_stage_upgrade) {
             $stage2_ofs->append_header("\nBEGIN;\n\n");
             $stage2_ofs->append_footer("\nCOMMIT;\n");
             // if generating slonik, stage 1 and 3 should not be in a transaction
             // as they will be submitted via slonik EXECUTE SCRIPT
             if (!dbsteward::$generate_slonik) {
                 $stage3_ofs->append_header("\nBEGIN;\n\n");
                 $stage3_ofs->append_footer("\nCOMMIT;\n");
             } else {
                 $stage3_ofs->append_header("\n-- generateslonik specified: pgsql8 STAGE1 upgrade omitting BEGIN. slonik EXECUTE SCRIPT will wrap stage 3 DDL and DCL in a transaction\n");
             }
             $stage4_ofs->append_header("\nBEGIN;\n\n");
             $stage4_ofs->append_footer("\nCOMMIT;\n");
         }
     }
     // start with pre-upgrade sql statements that prepare the database to take on its changes
     dbx::build_staged_sql(dbsteward::$new_database, $stage1_ofs, 'STAGE1BEFORE');
     dbx::build_staged_sql(dbsteward::$new_database, $stage2_ofs, 'STAGE2BEFORE');
     dbsteward::info("Drop Old Schemas");
     self::drop_old_schemas($stage3_ofs);
     dbsteward::info("Create New Schemas");
     self::create_new_schemas($stage1_ofs);
     dbsteward::info("Update Structure");
     self::update_structure($stage1_ofs, $stage3_ofs, self::$new_table_dependency);
     dbsteward::info("Update Permissions");
     self::update_permissions($stage1_ofs, $stage3_ofs);
     self::update_database_config_parameters($stage1_ofs, dbsteward::$new_database, dbsteward::$old_database);
     dbsteward::info("Update Data");
     if (dbsteward::$generate_slonik) {
         format::set_context_replica_set_to_natural_first(dbsteward::$new_database);
     }
     self::update_data($stage2_ofs, true);
     self::update_data($stage4_ofs, false);
     // append any literal SQL in new not in old at the end of data stage 1
     $old_sql = dbx::get_sql(dbsteward::$old_database);
     $new_sql = dbx::get_sql(dbsteward::$new_database);
     for ($n = 0; $n < count($new_sql); $n++) {
         if (isset($new_sql[$n]['stage'])) {
             // ignore upgrade staged sql elements
             continue;
         }
         // is this new statement in the old database?
         $found = false;
         for ($o = 0; $o < count($old_sql); $o++) {
             if (isset($old_sql[$o]['stage'])) {
                 // ignore upgrade staged sql elements
                 continue;
             }
             if (strcmp($new_sql[$n], $old_sql[$o]) == 0) {
                 $found = true;
             }
         }
         if (!$found) {
             $stage2_ofs->write($new_sql[$n] . "\n");
         }
     }
     // append stage defined sql statements to appropriate stage file
     if (dbsteward::$generate_slonik) {
         format::set_context_replica_set_to_natural_first(dbsteward::$new_database);
     }
     dbx::build_staged_sql(dbsteward::$new_database, $stage1_ofs, 'STAGE1');
     dbx::build_staged_sql(dbsteward::$new_database, $stage2_ofs, 'STAGE2');
     dbx::build_staged_sql(dbsteward::$new_database, $stage3_ofs, 'STAGE3');
     dbx::build_staged_sql(dbsteward::$new_database, $stage4_ofs, 'STAGE4');
 }