Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
wants to merge 1 commit into from

3 participants

Dumk0 Phil Sturgeon Andrey Andreev
Dumk0

It is wise to move dbforge loader out of __construct(), else the CI_Migration class is hard to extend.
With this change developers can use other db utility, skip automatic table creation, etc.

Phil Sturgeon

Based on the use-case it might be more logical to rename this to something else.

_check_schema() or whatever.

Dumk0

I would also name with a general word like _init() or something, up to you guys. I just need to overwrite it in my extension. :)

Andrey Andreev
Owner

You're still calling that new method from within the constructor, so what does that improve?

Andrey Andreev
Owner

Outdated, no feedback for 3 months and no obvious benefit from it - closing.

Andrey Andreev narfbg closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 19, 2012
  1. Dumk0
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 14 deletions.
  1. +27 −14 system/libraries/Migration.php
41 system/libraries/Migration.php
View
@@ -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
Something went wrong with that request. Please try again.