summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCloudmanic Labs, LLC <github@cloudmanic.com>2011-09-18 21:23:00 +0200
committerCloudmanic Labs, LLC <github@cloudmanic.com>2011-09-18 21:23:00 +0200
commitd1ba8f790eb91deb2898ff19d7827ce86e40ee7c (patch)
treeacd68c6bc5b3a00c1d5e1fbc79df58b94a1b6c71
parent539dcb0b2968a2d83c16b42a20252011152f2e65 (diff)
Migrations: Added a config that allows the system to migration to the latest migration when you load the library. This way you do not have to call migrations anywhere else in your code and can always be at the latest migration
-rw-r--r--application/config/migration.php16
-rw-r--r--system/libraries/Migration.php10
2 files changed, 26 insertions, 0 deletions
diff --git a/application/config/migration.php b/application/config/migration.php
index aca052d0c..1f532f170 100644
--- a/application/config/migration.php
+++ b/application/config/migration.php
@@ -25,6 +25,22 @@ $config['migration_enabled'] = FALSE;
*/
$config['migration_table'] = 'migrations';
+
+/*
+|--------------------------------------------------------------------------
+| Auto Migrate To Latest
+|--------------------------------------------------------------------------
+|
+| If this is set to TRUE when you load the migrations class and have
+| $config['migration_enabled'] set to TRUE the system will auto migrate
+| to your latest migration (whatever $config['migration_version'] is
+| set to). This way you do not have to call migrations anywhere else
+| in your code to have the latest migration.
+|
+*/
+$config['migration_auto_latest'] = FALSE;
+
+
/*
|--------------------------------------------------------------------------
| Migrations version
diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php
index 682d90752..28b1dd69f 100644
--- a/system/libraries/Migration.php
+++ b/system/libraries/Migration.php
@@ -33,6 +33,7 @@ class CI_Migration {
protected $_migration_path = NULL;
protected $_migration_version = 0;
protected $_migration_table = 'migrations';
+ protected $_migration_auto_latest = FALSE;
protected $_error_string = '';
@@ -86,6 +87,15 @@ class CI_Migration {
$this->db->insert($this->_migration_table, array('version' => 0));
}
+
+ // Do we auto migrate to the latest migration?
+ if ( $this->_migration_auto_latest == TRUE )
+ {
+ if ( ! $this->latest() )
+ {
+ show_error($this->error_string());
+ }
+ }
}
// --------------------------------------------------------------------