refactor db migrations to make sure it works for older versions #257

This commit is contained in:
leogermani 2019-05-22 12:32:33 -03:00
parent 9d0ada1f6a
commit b79503d31d
1 changed files with 20 additions and 16 deletions

View File

@ -54,11 +54,22 @@ class Migrations {
$wpdb->query($query);
}
/**
* We had some cases of tainacan upgrades from very old versions that missed some migrations...
* This migration make sure the table strucure is updated since the very first version
*/
static function assure_bg_process_database() {
global $wpdb;
$table_name = $wpdb->prefix . 'tnc_bg_process';
$column_exists = $wpdb->get_results( "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$wpdb->prefix}tnc_bg_process' AND column_name = 'progress_label'" );
if(empty($column_exists)) {
$wpdb->query("
ALTER TABLE {$wpdb->prefix}tnc_bg_process
ALTER TABLE $table_name
ADD progress_label text,
ADD progress_value int
");
@ -68,15 +79,12 @@ class Migrations {
if(empty($column_exists)) {
$wpdb->query("
ALTER TABLE {$wpdb->prefix}tnc_bg_process
ALTER TABLE $table_name
ADD name text NOT NULL
");
}
}
static function add_output_column_to_bg_process() {
global $wpdb;
$table_name = $wpdb->prefix . 'tnc_bg_process';
$column_exists = $wpdb->get_results( "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$wpdb->prefix}tnc_bg_process' AND column_name = 'output'" );
if(empty($column_exists)) {
@ -85,21 +93,17 @@ class Migrations {
ADD output longtext
");
}
}
static function create_importer_status_column(){
global $wpdb;
$column_exists = $wpdb->get_results( "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$wpdb->prefix}tnc_bg_process' AND column_name = 'status'" );
$column_exists = $wpdb->get_results( "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '{$wpdb->prefix}tnc_bg_process' AND column_name = 'status'" );
if(empty($column_exists)) {
$wpdb->query("
ALTER TABLE {$wpdb->prefix}tnc_bg_process
ALTER TABLE $table_name
ADD status ENUM('waiting','running','paused','cancelled','errored','finished','finished-errors')
");
}
}
}
static function init_capabilites() {
$Tainacan_Capabilities = \Tainacan\Capabilities::get_instance();