diff options
author | Eric Barnes <eric@ericlbarnes.com> | 2011-09-19 21:12:42 +0200 |
---|---|---|
committer | Eric Barnes <eric@ericlbarnes.com> | 2011-09-19 21:12:42 +0200 |
commit | a4fac6b8ac17b6864e632fe821b650291a9d4c42 (patch) | |
tree | 92a6d8f653a3eb8a9495b1c82e0cf1a1835c0d53 /system | |
parent | 4ff4896dbc6bd24efc3d005df90bdb3667255f09 (diff) | |
parent | 63b61e3bedd2a5729bef15b79ea64fa0a9d54893 (diff) |
Merge pull request #462 from cloudmanic/develop
Migrations: Made it so you can set the table name in the migration config.
Diffstat (limited to 'system')
-rw-r--r-- | system/libraries/Migration.php | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 3734e18f5..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()) @@ -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 )); } |