From 9f2e39711fdf33abb64287d73a88c2b6fd59833a Mon Sep 17 00:00:00 2001 From: jekkos Date: Sun, 1 Apr 2018 16:24:10 +0200 Subject: [PATCH] Migration refactor: move out common code (#1440) --- application/helpers/migration_helper.php | 32 +++++++++++++++++++ .../20170501150000_upgrade_to_3_1_1.php | 27 +--------------- .../20180225100000_upgrade_to_3_2_0.php | 27 +--------------- 3 files changed, 34 insertions(+), 52 deletions(-) create mode 100644 application/helpers/migration_helper.php diff --git a/application/helpers/migration_helper.php b/application/helpers/migration_helper.php new file mode 100644 index 000000000..8a9cd555b --- /dev/null +++ b/application/helpers/migration_helper.php @@ -0,0 +1,32 @@ +db->simple_query($statement)) + { + foreach($this->db->error() as $error) + { + error_log('error: ' . $error); + } + } + } + + error_log("Migrated to $version"); +} \ No newline at end of file diff --git a/application/migrations/20170501150000_upgrade_to_3_1_1.php b/application/migrations/20170501150000_upgrade_to_3_1_1.php index ca3ea460c..d0f3a231c 100644 --- a/application/migrations/20170501150000_upgrade_to_3_1_1.php +++ b/application/migrations/20170501150000_upgrade_to_3_1_1.php @@ -9,32 +9,7 @@ class Migration_Upgrade_To_3_1_1 extends CI_Migration public function up() { - error_log('Migrating to 3.1.1'); - - $sql = file_get_contents(APPPATH . 'migrations/sqlscripts/3.0.2_to_3.1.1.sql'); - - /* - CI migration only allows you to run one statement at a time. - This small script splits the statements allowing you to run them all in one go. - */ - - $sqls = explode(';', $sql); - array_pop($sqls); - - foreach($sqls as $statement) - { - $statement = $statement . ';'; - - if(!$this->db->simple_query($statement)) - { - foreach($this->db->error() as $error) - { - error_log('error: ' . $error); - } - } - } - - error_log('Migrated to 3.1.1'); + execute_script(APPPATH . 'migrations/sqlscripts/3.0.2_to_3.1.1.sql'); } public function down() diff --git a/application/migrations/20180225100000_upgrade_to_3_2_0.php b/application/migrations/20180225100000_upgrade_to_3_2_0.php index e077f5182..a30185e91 100644 --- a/application/migrations/20180225100000_upgrade_to_3_2_0.php +++ b/application/migrations/20180225100000_upgrade_to_3_2_0.php @@ -9,32 +9,7 @@ class Migration_Upgrade_To_3_2_0 extends CI_Migration public function up() { - error_log('Migrating to 3.2.0'); - - $sql = file_get_contents(APPPATH . 'migrations/sqlscripts/3.1.1_to_3.2.0.sql'); - - /* - CI migration only allows you to run one statement at a time. - This small script splits the statements allowing you to run them all in one go. - */ - - $sqls = explode(';', $sql); - array_pop($sqls); - - foreach($sqls as $statement) - { - $statement = $statement . ';'; - - if(!$this->db->simple_query($statement)) - { - foreach($this->db->error() as $error) - { - error_log('error: ' . $error); - } - } - } - - error_log('Migrated to 3.2.0'); + execute_script(APPPATH . 'migrations/sqlscripts/3.1.1_to_3.2.0.sql'); } public function down()