Permalink
Browse files

database utility load moved to separate method

  • Loading branch information...
1 parent f419afe commit c7fb550772461d96f3d62a9a56f8e7283746f8c2 Dumk0 committed Jun 19, 2012
Showing with 27 additions and 14 deletions.
  1. +27 −14 system/libraries/Migration.php
@@ -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

0 comments on commit c7fb550

Please sign in to comment.