Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Move database utility load to separate method in CI_Migration class #1509

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+27 −14
Split
@@ -117,26 +117,14 @@ public function __construct($config = array())
// Load migration language
$this->lang->load('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($this->_migration_table))
- {
- $this->dbforge->add_field(array(
- 'version' => array('type' => 'INT', 'constraint' => 3),
- ));
-
- $this->dbforge->create_table($this->_migration_table, TRUE);
-
- $this->db->insert($this->_migration_table, array('version' => 0));
- }
+ // Load dbforge and make sure migrations table exists
+ $this->_load_db();
// Do we auto migrate to the latest migration?
if ($this->_migration_auto_latest === TRUE && ! $this->latest())
@@ -347,6 +335,31 @@ protected function find_migrations()
// --------------------------------------------------------------------
/**
+ * Loads database utility, creates migrations table if missing
+ *
+ * @return void Load dbforge lib
+ */
+ protected function _load_db()
+ {
+ // They'll probably be using dbforge
+ $this->load->dbforge();
+
+ // If the migrations table is missing, make it
+ if ( ! $this->db->table_exists($this->_migration_table))
+ {
+ $this->dbforge->add_field(array(
+ 'version' => array('type' => 'INT', 'constraint' => 3),
+ ));
+
+ $this->dbforge->create_table($this->_migration_table, TRUE);
+
+ $this->db->insert($this->_migration_table, array('version' => 0));
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Retrieves current schema version
*
* @return int Current Migration