From 3a9f325cdff1fda2f2b37498a689ac2cde058195 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 25 Feb 2014 11:47:45 +0200 Subject: Use strings instead of integers for migration version numbers - Allows timestamp versions to work on 32-bit systems. - Fixes #2902. - Supersedes PR #2368. --- system/language/english/migration_lang.php | 6 +++--- system/libraries/Migration.php | 29 +++++++++++++++-------------- 2 files changed, 18 insertions(+), 17 deletions(-) (limited to 'system') diff --git a/system/language/english/migration_lang.php b/system/language/english/migration_lang.php index 8e8b606c0..923f244f3 100644 --- a/system/language/english/migration_lang.php +++ b/system/language/english/migration_lang.php @@ -27,9 +27,9 @@ defined('BASEPATH') OR exit('No direct script access allowed'); $lang['migration_none_found'] = 'No migrations were found.'; -$lang['migration_not_found'] = 'No migration could be found with the version number: %d.'; -$lang['migration_sequence_gap'] = 'There is a gap in the migration sequence near version number: %d.'; -$lang['migration_multiple_version'] = 'There are multiple migrations with the same version number: %d.'; +$lang['migration_not_found'] = 'No migration could be found with the version number: %s.'; +$lang['migration_sequence_gap'] = 'There is a gap in the migration sequence near version number: %s.'; +$lang['migration_multiple_version'] = 'There are multiple migrations with the same version number: %s.'; $lang['migration_class_doesnt_exist'] = 'The migration class "%s" could not be found.'; $lang['migration_missing_up_method'] = 'The migration class "%s" is missing an "up" method.'; $lang['migration_missing_down_method'] = 'The migration class "%s" is missing a "down" method.'; diff --git a/system/libraries/Migration.php b/system/libraries/Migration.php index 2ead3aec1..b226ee804 100644 --- a/system/libraries/Migration.php +++ b/system/libraries/Migration.php @@ -179,13 +179,14 @@ class CI_Migration { * Calls each migration step required to get to the schema version of * choice * - * @param int $target_version Target schema version - * @return mixed TRUE if already latest, FALSE if failed, int if upgraded + * @param string $target_version Target schema version + * @return mixed TRUE if already latest, FALSE if failed, string if upgraded */ public function version($target_version) { - $current_version = (int) $this->_get_version(); - $target_version = (int) $target_version; + // Note: We use strings, so that timestamp versions work on 32-bit systems + $current_version = $this->_get_version(); + $target_version = (string) $target_version; $migrations = $this->find_migrations(); @@ -224,7 +225,7 @@ class CI_Migration { return FALSE; } - include_once $file; + include_once($file); $class = 'Migration_'.ucfirst(strtolower($this->_get_migration_name(basename($file, '.php')))); // Validate the migration file structure @@ -274,7 +275,7 @@ class CI_Migration { /** * Sets the schema to the latest migration * - * @return mixed TRUE if already latest, FALSE if failed, int if upgraded + * @return mixed TRUE if already latest, FALSE if failed, string if upgraded */ public function latest() { @@ -289,7 +290,7 @@ class CI_Migration { $last_migration = basename(end($migrations)); // Calculate the last migration step from existing migration - // filenames and procceed to the standard version migration + // filenames and proceed to the standard version migration return $this->version($this->_get_migration_number($last_migration)); } @@ -298,7 +299,7 @@ class CI_Migration { /** * Sets the schema to the migration version set in config * - * @return mixed TRUE if already current, FALSE if failed, int if upgraded + * @return mixed TRUE if already current, FALSE if failed, string if upgraded */ public function current() { @@ -359,12 +360,12 @@ class CI_Migration { * Extracts the migration number from a filename * * @param string $migration - * @return int Numeric portion of a migration filename + * @return string Numeric portion of a migration filename */ protected function _get_migration_number($migration) { - return sscanf($migration, '%d', $number) - ? $number : 0; + return sscanf($migration, '%[0-9]+', $number) + ? $number : '0'; } // -------------------------------------------------------------------- @@ -387,12 +388,12 @@ class CI_Migration { /** * Retrieves current schema version * - * @return int Current Migration + * @return string Current migration version */ protected function _get_version() { $row = $this->db->select('version')->get($this->_migration_table)->row(); - return $row ? $row->version : 0; + return $row ? $row->version : '0'; } // -------------------------------------------------------------------- @@ -400,7 +401,7 @@ class CI_Migration { /** * Stores the current schema version * - * @param int $migration Migration reached + * @param string $migration Migration reached * @return void Outputs a report of the migration */ protected function _update_version($migration) -- cgit v1.2.3-24-g4f1b