diff options
author | Kyle Farris <kylefarris@kylefarris.gotdns.org> | 2011-10-14 21:43:25 +0200 |
---|---|---|
committer | Kyle Farris <kylefarris@kylefarris.gotdns.org> | 2011-10-14 21:43:25 +0200 |
commit | ad17f4b932b3728c1e299b48f28b3ae0dbdd6b0b (patch) | |
tree | fdb357433e76000bdef60c4d18e5ab0540b07aeb /system/libraries/Migration.php | |
parent | db46d02ac23b8e0bc2416e197494d3b795b57530 (diff) | |
parent | a2125a5d830fd390b4cf35f77e9bb0558cfa2dd7 (diff) |
Merged with development
Diffstat (limited to 'system/libraries/Migration.php')
-rw-r--r-- | system/libraries/Migration.php | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 3943ec130..840cefe08 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -32,7 +32,9 @@ class CI_Migration { protected $_migration_enabled = FALSE; protected $_migration_path = NULL; protected $_migration_version = 0; - + protected $_migration_table = 'migrations'; + protected $_migration_auto_latest = FALSE; + protected $_error_string = ''; public function __construct($config = array()) @@ -57,7 +59,7 @@ class CI_Migration { } // If not set, set it - $this->_migration_path == '' OR $this->_migration_path = APPPATH . 'migrations/'; + $this->_migration_path == '' AND $this->_migration_path = APPPATH . 'migrations/'; // Add trailing slash if not set $this->_migration_path = rtrim($this->_migration_path, '/').'/'; @@ -68,16 +70,31 @@ class CI_Migration { // They'll probably be using dbforge $this->load->dbforge(); + // Make sure the migration table name was set. + if (empty($this->_migration_table)) + { + show_error('Migrations configuration file (migration.php) must have "migration_table" set.'); + } + // If the migrations table is missing, make it - if ( ! $this->db->table_exists('migrations')) + if ( ! $this->db->table_exists($this->_migration_table)) { $this->dbforge->add_field(array( 'version' => array('type' => 'INT', 'constraint' => 3), )); - $this->dbforge->create_table('migrations', TRUE); + $this->dbforge->create_table($this->_migration_table, TRUE); - $this->db->insert('migrations', array('version' => 0)); + $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()); + } } } @@ -299,7 +316,7 @@ class CI_Migration { */ protected function _get_version() { - $row = $this->db->get('migrations')->row(); + $row = $this->db->get($this->_migration_table)->row(); return $row ? $row->version : 0; } @@ -314,7 +331,7 @@ class CI_Migration { */ protected function _update_version($migrations) { - return $this->db->update('migrations', array( + return $this->db->update($this->_migration_table, array( 'version' => $migrations )); } |