summaryrefslogtreecommitdiffstats
path: root/application/core
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2014-07-23 21:56:01 +0200
committerFlorian Pritz <bluewind@xinu.at>2014-07-23 21:58:19 +0200
commitcc72236f71c60396b69631656f8e0ad00a6301c8 (patch)
treea981833a17cba56e85682048a84e544e877af773 /application/core
parentce58ad70b8f3800adeaaadd46d8ed499bc21eda6 (diff)
Move migration code to CLI callable function
This is necessary to prevent migrations from running multiple times in parallel. A git hook can be used to run this after checkout so impact should be fairly low. Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/core')
-rw-r--r--application/core/MY_Controller.php19
1 files changed, 16 insertions, 3 deletions
diff --git a/application/core/MY_Controller.php b/application/core/MY_Controller.php
index 043b52ef7..a98245b1b 100644
--- a/application/core/MY_Controller.php
+++ b/application/core/MY_Controller.php
@@ -21,9 +21,22 @@ class MY_Controller extends CI_Controller {
$this->var = new StdClass();
$csrf_protection = true;
- $this->load->library('migration');
- if ( ! $this->migration->current()) {
- show_error($this->migration->error_string());
+ // check if DB is up to date
+ if (!$this->input->is_cli_request()) {
+ if (!$this->db->table_exists('migrations')){
+ show_error("Database not initialized. Can't find migrations table. Please run the migration script.");
+ } else {
+ $this->config->load("migration", true);
+ $target_version = $this->config->item("migration_version", "migration");
+
+ // TODO: wait 20 seconds for an update so requests don't get lost for short updates?
+ $row = $this->db->get('migrations')->row();
+
+ $current_version = $row ? $row->version : 0;
+ if ($current_version != $target_version) {
+ show_error("Database version is $current_version, we want $target_version. Please run the migration script.");
+ }
+ }
}
$old_path = getenv("PATH");