Ejemplo 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');
 }