Exemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configuration = CodePax_Config::getInstance(CONFIG_PATH . 'config.ini');
     $db_versions_model = CodePax_DbVersions::factory($configuration);
     $latest_structure_version = $db_versions_model->getLatestVersion(CodePax_DbVersions::TYPE_CHANGE_SCRIPT);
     $latest_data_version = $db_versions_model->getLatestVersion(CodePax_DbVersions::TYPE_DATA_CHANGE_SCRIPT);
     $db_versioning_handler = CodePax_DbVersioning_Environments_Factory::factory($configuration);
     $change_scripts = $db_versioning_handler->getChangeScripts();
     $data_change_scripts = $db_versioning_handler->getDataChangeScripts();
     $output->writeln('Environment: ' . strtoupper($configuration->application_environment));
     $output->writeln('');
     $output->writeln('Database name: ' . $configuration->db_name);
     $output->writeln('Database structure version: ' . $latest_structure_version[CodePax_DbVersions::VERSION_ATTRIBUTE]);
     $output->writeln('Database structure last update: ' . $latest_structure_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE]);
     $output->writeln('Database data version: ' . $latest_data_version[CodePax_DbVersions::VERSION_ATTRIBUTE]);
     $output->writeln('Database data last update: ' . (!empty($latest_data_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE]) ? $latest_data_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE] : 'n/a'));
     $output->writeln('');
     if (strtolower($configuration->application_environment) == 'dev') {
         $output->writeln('Baseline version: ' . $db_versioning_handler->getLatestBaselineVersion());
     }
     $output->writeln('Change structure scripts to run: ');
     $output->writeln(!empty($change_scripts) ? implode("\n", array_keys($change_scripts)) : 'n/a');
     $output->writeln('Change data scripts to run: ');
     $output->writeln(!empty($data_change_scripts) ? implode("\n", array_keys($data_change_scripts)) : 'n/a');
 }
Exemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configuration = CodePax_Config::getInstance(CONFIG_PATH . 'config.ini');
     $preserve_test_data = false;
     if ($input->getOption('preserve-test-data')) {
         $preserve_test_data = true;
     }
     try {
         $db_versioning_handler = CodePax_DbVersioning_Environments_Factory::factory($configuration);
         $generate_test_data = false;
         // generate test data
         if (strtolower($configuration->application_environment) == 'dev' && isset($preserve_test_data) && $preserve_test_data == true) {
             $generate_test_data = true;
         }
         $db_scripts_result = $db_versioning_handler->runScripts($generate_test_data);
         unset($db_scripts_result['run_change_scripts'], $db_scripts_result['run_data_change_scripts']);
     } catch (CodePax_DbVersioning_Exception $e) {
         $output->writeln($e->getMessage());
         exit;
     } catch (Exception $e) {
         $output->writeln($e->getMessage());
         exit;
     }
     $output->writeln('Everything went smoothly!');
 }
Exemplo n.º 3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configuration = CodePax_Config::getInstance(CONFIG_PATH . 'config.ini');
     if (strtolower($configuration->application_environment) == 'stg') {
         try {
             $db_versioning_handler = CodePax_DbVersioning_Environments_Factory::factory($configuration);
             $db_versioning_handler->generateBaseline();
         } catch (CodePax_DbVersioning_Exception $e) {
             $output->writeln('An error ocurred: ' . $e->getMessage());
             exit;
         } catch (Exception $e) {
             $output->writeln('Generic error: ' . $e->getMessage());
             exit;
         }
         $output->writeln('A new baseline has been generated!');
     } else {
         $output->writeln('You are not running on stg. The ' . strtolower($configuration->application_environment) . ' environment was detected');
     }
 }
Exemplo n.º 4
0
 /**
  * Return database versioning information
  *
  * @return stdClass
  * @throws CodePax_DbVersioning_Exception
  */
 public function info()
 {
     $databaseVersioningInfo = new stdClass();
     // get current DB version
     $db_versions_model = CodePax_DbVersions::factory($this->configuration);
     if (in_array($this->configuration->application_environment, array('dev', 'prod'))) {
         $latest_baseline_file = $this->filesManager->getLatestBaselineVersion();
         if (!$db_versions_model->checkIsVersionRegistred($latest_baseline_file, CodePax_DbVersions::TYPE_BASELINE)) {
             $db_versions_model->addVersion($latest_baseline_file, CodePax_DbVersions::TYPE_BASELINE);
         }
     }
     $latest_structure_version = $db_versions_model->getLatestVersion(CodePax_DbVersions::TYPE_CHANGE_SCRIPT);
     $latest_data_version = $db_versions_model->getLatestVersion(CodePax_DbVersions::TYPE_DATA_CHANGE_SCRIPT);
     $databaseVersioningInfo->database_name = $this->configuration->db_name;
     $databaseVersioningInfo->database_structure_version = $latest_structure_version[CodePax_DbVersions::VERSION_ATTRIBUTE];
     $databaseVersioningInfo->database_structure_last_update = $latest_structure_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE];
     $databaseVersioningInfo->database_data_version = $latest_data_version[CodePax_DbVersions::VERSION_ATTRIBUTE];
     $databaseVersioningInfo->database_data_last_update = !empty($latest_data_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE]) ? $latest_data_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE] : 'n/a';
     // get change scripts to run
     $db_versioning_handler = CodePax_DbVersioning_Environments_Factory::factory($this->configuration);
     $change_scripts = $db_versioning_handler->getChangeScripts();
     $data_change_scripts = $db_versioning_handler->getDataChangeScripts();
     $new_baseline_available = false;
     if (in_array($this->configuration->application_environment, array('dev', 'prod'))) {
         $new_baseline_available = version_compare($latest_structure_version[CodePax_DbVersions::VERSION_ATTRIBUTE], $db_versioning_handler->getLatestBaselineVersion()) == -1;
     }
     // database is up-to-date
     $databaseVersioningInfo->baseline_script = null;
     $databaseVersioningInfo->db_versioning_dev_note = false;
     $databaseVersioningInfo->db_scripts = array();
     $databaseVersioningInfo->data_db_scripts = array();
     if (empty($change_scripts) && empty($data_change_scripts) && !$new_baseline_available) {
         $databaseVersioningInfo->db_is_updated = true;
     } else {
         //database is not up to date
         $databaseVersioningInfo->db_is_updated = false;
         // data change scripts
         if (!empty($change_scripts)) {
             $databaseVersioningInfo->db_scripts = array_keys($change_scripts);
         }
         // data change scripts
         if (!empty($data_change_scripts)) {
             $databaseVersioningInfo->data_db_scripts = array_keys($data_change_scripts);
         }
         // when on DEV, show extra info
         if ($this->configuration->application_environment == 'dev') {
             $databaseVersioningInfo->baseline_script = $db_versioning_handler->getLatestBaselineVersion();
             $databaseVersioningInfo->db_versioning_dev_note = true;
         }
     }
     return $databaseVersioningInfo;
 }
Exemplo n.º 5
0
 $db_versions_model = CodePax_DbVersions::factory();
 if (in_array(APPLICATION_ENVIRONMENT, array('dev', 'prod'))) {
     $latest_baseline_file = CodePax_DbVersioning_Files_Manager::getLatestBaselineVersion();
     if (!$db_versions_model->checkIsVersionRegistred($latest_baseline_file, CodePax_DbVersions::TYPE_BASELINE)) {
         $db_versions_model->addVersion($latest_baseline_file, CodePax_DbVersions::TYPE_BASELINE);
     }
 }
 $latest_structure_version = $db_versions_model->getLatestVersion(CodePax_DbVersions::TYPE_CHANGE_SCRIPT);
 $latest_data_version = $db_versions_model->getLatestVersion(CodePax_DbVersions::TYPE_DATA_CHANGE_SCRIPT);
 $view->database_name = DB_NAME;
 $view->database_structure_version = $latest_structure_version[CodePax_DbVersions::VERSION_ATTRIBUTE];
 $view->database_structure_last_update = $latest_structure_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE];
 $view->database_data_version = $latest_data_version[CodePax_DbVersions::VERSION_ATTRIBUTE];
 $view->database_data_last_update = !empty($latest_data_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE]) ? $latest_data_version[CodePax_DbVersions::DATE_ADDED_ATTRIBUTE] : 'n/a';
 // get change scripts to run
 $db_versioning_handler = CodePax_DbVersioning_Environments_Factory::factory(APPLICATION_ENVIRONMENT);
 $change_scripts = $db_versioning_handler->getChangeScripts();
 $data_change_scripts = $db_versioning_handler->getDataChangeScripts();
 $new_baseline_available = false;
 if (in_array(APPLICATION_ENVIRONMENT, array('dev', 'prod'))) {
     $new_baseline_available = version_compare($latest_structure_version[CodePax_DbVersions::VERSION_ATTRIBUTE], $db_versioning_handler->getLatestBaselineVersion()) == -1;
 }
 // database is up-to-date
 if (empty($change_scripts) && empty($data_change_scripts) && !$new_baseline_available) {
     $view->db_is_updated = true;
 } else {
     // data change scripts
     if (!empty($change_scripts)) {
         $view->db_scripts = array_keys($change_scripts);
     }
     // data change scripts