mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-04-12 02:48:48 -04:00
Migration refactor: move out common code (#1440)
This commit is contained in:
32
application/helpers/migration_helper.php
Normal file
32
application/helpers/migration_helper.php
Normal 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");
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user