Migration refactor: move out common code (#1440)

This commit is contained in:
jekkos
2018-04-01 16:24:10 +02:00
committed by jekkos
parent 43b4cee636
commit 9f2e39711f
3 changed files with 34 additions and 52 deletions

View File

@@ -0,0 +1,32 @@
<?php
function execute_script($path)
{
$version = preg_replace("/(.*_)?(.*).sql/", "$2", $path);
error_log("Migrating to $version");
$sql = file_get_contents($path);
/*
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 $version");
}

View File

@@ -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()

View File

@@ -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()