blob: 009b54fb4e8c8365177e1ed872ece9ebf779b019 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Phil Sturgeon9758d842011-02-07 20:39:00 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Phil Sturgeon9758d842011-02-07 20:39:00 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Eric Barnesdd81c432011-11-16 11:07:35 -05008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Eric Barnesdd81c432011-11-16 11:07:35 -050010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Phil Sturgeon9758d842011-02-07 20:39:00 +000019 * @package CodeIgniter
20 * @author EllisLab Dev Team
darwinel871754a2014-02-11 17:34:57 +010021 * @copyright Copyright (c) 2006 - 2014, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Phil Sturgeon9758d842011-02-07 20:39:00 +000023 * @link http://codeigniter.com
Derek Jonesf4a4bd82011-10-20 12:18:42 -050024 * @since Version 3.0
Phil Sturgeon9758d842011-02-07 20:39:00 +000025 * @filesource
26 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Phil Sturgeon9758d842011-02-07 20:39:00 +000028
Phil Sturgeon9758d842011-02-07 20:39:00 +000029/**
30 * Migration Class
31 *
32 * All migrations should implement this, forces up() and down() and gives
33 * access to the CI super-global.
34 *
35 * @package CodeIgniter
36 * @subpackage Libraries
37 * @category Libraries
38 * @author Reactor Engineers
39 * @link
40 */
41class CI_Migration {
42
Timothy Warren86611db2012-04-27 10:06:25 -040043 /**
44 * Whether the library is enabled
45 *
46 * @var bool
47 */
Phil Sturgeon96bd33b2011-05-04 01:30:36 +010048 protected $_migration_enabled = FALSE;
Andrey Andreev39eb8062012-11-13 03:36:40 +020049
Jonathon Hill34c8b9c2012-10-31 14:02:35 -040050 /**
Jonathon Hillb719bfd2012-11-12 09:03:36 -050051 * Migration numbering type
Jonathon Hill34c8b9c2012-10-31 14:02:35 -040052 *
Andrey Andreev39eb8062012-11-13 03:36:40 +020053 * @var bool
Jonathon Hill34c8b9c2012-10-31 14:02:35 -040054 */
Jonathon Hillb719bfd2012-11-12 09:03:36 -050055 protected $_migration_type = 'sequential';
Andrey Andreev56454792012-05-17 14:32:19 +030056
Timothy Warren86611db2012-04-27 10:06:25 -040057 /**
58 * Path to migration classes
59 *
60 * @var string
61 */
Phil Sturgeon96bd33b2011-05-04 01:30:36 +010062 protected $_migration_path = NULL;
Andrey Andreev56454792012-05-17 14:32:19 +030063
Timothy Warren86611db2012-04-27 10:06:25 -040064 /**
65 * Current migration version
66 *
67 * @var mixed
68 */
Phil Sturgeon96bd33b2011-05-04 01:30:36 +010069 protected $_migration_version = 0;
Andrey Andreev56454792012-05-17 14:32:19 +030070
Timothy Warren86611db2012-04-27 10:06:25 -040071 /**
72 * Database table with migration info
73 *
74 * @var string
75 */
Cloudmanic Labs, LLC539dcb02011-09-18 12:08:56 -070076 protected $_migration_table = 'migrations';
Andrey Andreev56454792012-05-17 14:32:19 +030077
Timothy Warren86611db2012-04-27 10:06:25 -040078 /**
79 * Whether to automatically run migrations
80 *
Andrey Andreev39eb8062012-11-13 03:36:40 +020081 * @var bool
Timothy Warren86611db2012-04-27 10:06:25 -040082 */
Cloudmanic Labs, LLCd1ba8f72011-09-18 12:23:00 -070083 protected $_migration_auto_latest = FALSE;
Andrey Andreev39eb8062012-11-13 03:36:40 +020084
Jonathon Hill34c8b9c2012-10-31 14:02:35 -040085 /**
86 * Migration basename regex
87 *
88 * @var bool
89 */
90 protected $_migration_regex = NULL;
Eric Barnesdd81c432011-11-16 11:07:35 -050091
Timothy Warren86611db2012-04-27 10:06:25 -040092 /**
93 * Error message
94 *
95 * @var string
96 */
Phil Sturgeoncb06c652011-05-04 10:50:25 +010097 protected $_error_string = '';
Phil Sturgeon9758d842011-02-07 20:39:00 +000098
Timothy Warren86611db2012-04-27 10:06:25 -040099 /**
100 * Initialize Migration Class
101 *
Andrey Andreev39eb8062012-11-13 03:36:40 +0200102 * @param array $config
Andrey Andreev56454792012-05-17 14:32:19 +0300103 * @return void
Timothy Warren86611db2012-04-27 10:06:25 -0400104 */
Phil Sturgeon96bd33b2011-05-04 01:30:36 +0100105 public function __construct($config = array())
Phil Sturgeon9758d842011-02-07 20:39:00 +0000106 {
Andrey Andreev8151cbb2013-01-30 13:57:56 +0200107 // Only run this constructor on main library load
108 if ( ! in_array(get_class($this), array('CI_Migration', config_item('subclass_prefix').'Migration'), TRUE))
Phil Sturgeon9758d842011-02-07 20:39:00 +0000109 {
110 return;
111 }
112
113 foreach ($config as $key => $val)
114 {
Andrey Andreev56454792012-05-17 14:32:19 +0300115 $this->{'_'.$key} = $val;
Phil Sturgeon9758d842011-02-07 20:39:00 +0000116 }
117
118 log_message('debug', 'Migrations class initialized');
119
120 // Are they trying to use migrations while it is disabled?
121 if ($this->_migration_enabled !== TRUE)
122 {
123 show_error('Migrations has been loaded but is disabled or set up incorrectly.');
124 }
125
126 // If not set, set it
Alex Bilbied261b1e2012-06-02 11:12:16 +0100127 $this->_migration_path !== '' OR $this->_migration_path = APPPATH.'migrations/';
Phil Sturgeon9758d842011-02-07 20:39:00 +0000128
129 // Add trailing slash if not set
130 $this->_migration_path = rtrim($this->_migration_path, '/').'/';
131
Phil Sturgeon96bd33b2011-05-04 01:30:36 +0100132 // Load migration language
133 $this->lang->load('migration');
134
Phil Sturgeon9758d842011-02-07 20:39:00 +0000135 // They'll probably be using dbforge
136 $this->load->dbforge();
137
Cloudmanic Labs, LLC539dcb02011-09-18 12:08:56 -0700138 // Make sure the migration table name was set.
Cloudmanic Labs, LLC63b61e32011-09-19 09:35:05 -0700139 if (empty($this->_migration_table))
Cloudmanic Labs, LLC539dcb02011-09-18 12:08:56 -0700140 {
Eric Barnesdd81c432011-11-16 11:07:35 -0500141 show_error('Migrations configuration file (migration.php) must have "migration_table" set.');
Cloudmanic Labs, LLC539dcb02011-09-18 12:08:56 -0700142 }
Andrey Andreev39eb8062012-11-13 03:36:40 +0200143
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400144 // Migration basename regex
Jonathon Hill4ddf9442012-11-12 18:30:59 -0500145 $this->_migration_regex = ($this->_migration_type === 'timestamp')
Andrey Andreev838a9d62012-12-03 14:37:47 +0200146 ? '/^\d{14}_(\w+)$/'
147 : '/^\d{3}_(\w+)$/';
Andrey Andreev39eb8062012-11-13 03:36:40 +0200148
Jonathon Hillb719bfd2012-11-12 09:03:36 -0500149 // Make sure a valid migration numbering type was set.
150 if ( ! in_array($this->_migration_type, array('sequential', 'timestamp')))
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400151 {
Jonathon Hillb719bfd2012-11-12 09:03:36 -0500152 show_error('An invalid migration numbering type was specified: '.$this->_migration_type);
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400153 }
Cloudmanic Labs, LLC539dcb02011-09-18 12:08:56 -0700154
Phil Sturgeon9758d842011-02-07 20:39:00 +0000155 // If the migrations table is missing, make it
Cloudmanic Labs, LLC539dcb02011-09-18 12:08:56 -0700156 if ( ! $this->db->table_exists($this->_migration_table))
Phil Sturgeon9758d842011-02-07 20:39:00 +0000157 {
158 $this->dbforge->add_field(array(
Jonathon Hill275cf272012-11-12 08:42:28 -0500159 'version' => array('type' => 'BIGINT', 'constraint' => 20),
Phil Sturgeon9758d842011-02-07 20:39:00 +0000160 ));
161
Cloudmanic Labs, LLC539dcb02011-09-18 12:08:56 -0700162 $this->dbforge->create_table($this->_migration_table, TRUE);
Phil Sturgeon9758d842011-02-07 20:39:00 +0000163
Cloudmanic Labs, LLC539dcb02011-09-18 12:08:56 -0700164 $this->db->insert($this->_migration_table, array('version' => 0));
Phil Sturgeon9758d842011-02-07 20:39:00 +0000165 }
Eric Barnesdd81c432011-11-16 11:07:35 -0500166
Cloudmanic Labs, LLCd1ba8f72011-09-18 12:23:00 -0700167 // Do we auto migrate to the latest migration?
Andrey Andreev9b1db792012-03-26 19:45:51 +0300168 if ($this->_migration_auto_latest === TRUE && ! $this->latest())
Cloudmanic Labs, LLCd1ba8f72011-09-18 12:23:00 -0700169 {
Andrey Andreevdd4702f2011-12-24 19:33:44 +0200170 show_error($this->error_string());
Cloudmanic Labs, LLCd1ba8f72011-09-18 12:23:00 -0700171 }
Phil Sturgeon9758d842011-02-07 20:39:00 +0000172 }
173
174 // --------------------------------------------------------------------
175
176 /**
177 * Migrate to a schema version
178 *
179 * Calls each migration step required to get to the schema version of
180 * choice
181 *
Andrey Andreev3a9f3252014-02-25 11:47:45 +0200182 * @param string $target_version Target schema version
183 * @return mixed TRUE if already latest, FALSE if failed, string if upgraded
Phil Sturgeon9758d842011-02-07 20:39:00 +0000184 */
Phil Sturgeon96bd33b2011-05-04 01:30:36 +0100185 public function version($target_version)
Phil Sturgeon9758d842011-02-07 20:39:00 +0000186 {
Andrey Andreev3a9f3252014-02-25 11:47:45 +0200187 // Note: We use strings, so that timestamp versions work on 32-bit systems
188 $current_version = $this->_get_version();
Ahmad Anbar9b198872014-04-01 01:13:05 +0300189 $target_version = (string) $target_version;
190
191 if ($this->_migration_type == 'sequential')
192 {
193 $target_version = str_pad($target_version, 3, '0', STR_PAD_LEFT);
194 }
Andrey Andreev39eb8062012-11-13 03:36:40 +0200195
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400196 $migrations = $this->find_migrations();
Andrey Andreev39eb8062012-11-13 03:36:40 +0200197
Jonathon Hill02ea66e2012-11-12 17:26:36 -0500198 if ($target_version > 0 && ! isset($migrations[$target_version]))
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400199 {
200 $this->_error_string = sprintf($this->lang->line('migration_not_found'), $target_version);
201 return FALSE;
202 }
Andrey Andreev39eb8062012-11-13 03:36:40 +0200203
Phil Sturgeon9758d842011-02-07 20:39:00 +0000204 if ($target_version > $current_version)
205 {
206 // Moving Up
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400207 $method = 'up';
Phil Sturgeon9758d842011-02-07 20:39:00 +0000208 }
Phil Sturgeon9758d842011-02-07 20:39:00 +0000209 else
210 {
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400211 // Moving Down, apply in reverse order
212 $method = 'down';
213 krsort($migrations);
Phil Sturgeon9758d842011-02-07 20:39:00 +0000214 }
Eric Barnesdd81c432011-11-16 11:07:35 -0500215
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400216 if (empty($migrations))
Phil Sturgeon9758d842011-02-07 20:39:00 +0000217 {
218 return TRUE;
219 }
Andrey Andreev39eb8062012-11-13 03:36:40 +0200220
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400221 $previous = FALSE;
Phil Sturgeon9758d842011-02-07 20:39:00 +0000222
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400223 // Validate all available migrations, and run the ones within our target range
224 foreach ($migrations as $number => $file)
Phil Sturgeon9758d842011-02-07 20:39:00 +0000225 {
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400226 // Check for sequence gaps
Jonathon Hill02ea66e2012-11-12 17:26:36 -0500227 if ($this->_migration_type === 'sequential' && $previous !== FALSE && abs($number - $previous) > 1)
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400228 {
229 $this->_error_string = sprintf($this->lang->line('migration_sequence_gap'), $number);
230 return FALSE;
231 }
Andrey Andreev39eb8062012-11-13 03:36:40 +0200232
Andrey Andreev3a9f3252014-02-25 11:47:45 +0200233 include_once($file);
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400234 $class = 'Migration_'.ucfirst(strtolower($this->_get_migration_name(basename($file, '.php'))));
Phil Sturgeon9758d842011-02-07 20:39:00 +0000235
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400236 // Validate the migration file structure
Andrey Andreev49e68de2013-02-21 16:30:55 +0200237 if ( ! class_exists($class, FALSE))
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400238 {
239 $this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class);
240 return FALSE;
241 }
Andrey Andreev39eb8062012-11-13 03:36:40 +0200242
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400243 $previous = $number;
244
245 // Run migrations that are inside the target range
246 if (
Jonathon Hill02ea66e2012-11-12 17:26:36 -0500247 ($method === 'up' && $number > $current_version && $number <= $target_version) OR
248 ($method === 'down' && $number <= $current_version && $number > $target_version)
249 )
250 {
Andrey Andreeve1d6c462012-11-28 19:06:20 +0200251 $instance = new $class();
252 if ( ! is_callable(array($instance, $method)))
253 {
254 $this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class);
255 return FALSE;
256 }
257
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400258 log_message('debug', 'Migrating '.$method.' from version '.$current_version.' to version '.$number);
Andrey Andreeve1d6c462012-11-28 19:06:20 +0200259 call_user_func(array($instance, $method));
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400260 $current_version = $number;
261 $this->_update_version($current_version);
262 }
263 }
Andrey Andreev39eb8062012-11-13 03:36:40 +0200264
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400265 // This is necessary when moving down, since the the last migration applied
266 // will be the down() method for the next migration up from the target
267 if ($current_version <> $target_version)
268 {
269 $current_version = $target_version;
Phil Sturgeon9758d842011-02-07 20:39:00 +0000270 $this->_update_version($current_version);
271 }
272
Phil Sturgeon96bd33b2011-05-04 01:30:36 +0100273 log_message('debug', 'Finished migrating to '.$current_version);
Phil Sturgeon9758d842011-02-07 20:39:00 +0000274
275 return $current_version;
276 }
277
278 // --------------------------------------------------------------------
279
280 /**
Jacob Tabak35f6a542014-02-19 15:38:26 -0600281 * Sets the schema to the latest migration
Phil Sturgeon9758d842011-02-07 20:39:00 +0000282 *
Andrey Andreev3a9f3252014-02-25 11:47:45 +0200283 * @return mixed TRUE if already latest, FALSE if failed, string if upgraded
Phil Sturgeon9758d842011-02-07 20:39:00 +0000284 */
285 public function latest()
286 {
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400287 $migrations = $this->find_migrations();
Andrey Andreev39eb8062012-11-13 03:36:40 +0200288
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400289 if (empty($migrations))
Phil Sturgeon9758d842011-02-07 20:39:00 +0000290 {
Cloudmanic Labs, LLC3d036e32011-11-11 22:46:21 -0800291 $this->_error_string = $this->lang->line('migration_none_found');
Alex Bilbieafee2262012-07-15 18:59:01 +0100292 return FALSE;
Phil Sturgeon9758d842011-02-07 20:39:00 +0000293 }
294
295 $last_migration = basename(end($migrations));
Andrey Andreev39eb8062012-11-13 03:36:40 +0200296
Phil Sturgeon9758d842011-02-07 20:39:00 +0000297 // Calculate the last migration step from existing migration
Andrey Andreev3a9f3252014-02-25 11:47:45 +0200298 // filenames and proceed to the standard version migration
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400299 return $this->version($this->_get_migration_number($last_migration));
Phil Sturgeon9758d842011-02-07 20:39:00 +0000300 }
301
302 // --------------------------------------------------------------------
303
304 /**
Jacob Tabak35f6a542014-02-19 15:38:26 -0600305 * Sets the schema to the migration version set in config
Phil Sturgeon9758d842011-02-07 20:39:00 +0000306 *
Andrey Andreev3a9f3252014-02-25 11:47:45 +0200307 * @return mixed TRUE if already current, FALSE if failed, string if upgraded
Phil Sturgeon9758d842011-02-07 20:39:00 +0000308 */
309 public function current()
310 {
Phil Sturgeon96bd33b2011-05-04 01:30:36 +0100311 return $this->version($this->_migration_version);
312 }
313
314 // --------------------------------------------------------------------
315
316 /**
317 * Error string
318 *
Phil Sturgeon96bd33b2011-05-04 01:30:36 +0100319 * @return string Error message returned as a string
320 */
321 public function error_string()
322 {
Phil Sturgeoncb06c652011-05-04 10:50:25 +0100323 return $this->_error_string;
Phil Sturgeon9758d842011-02-07 20:39:00 +0000324 }
325
326 // --------------------------------------------------------------------
327
328 /**
Dumk05db48272012-07-05 02:58:10 +0300329 * Retrieves list of available migration scripts
Phil Sturgeon9758d842011-02-07 20:39:00 +0000330 *
Dumk05db48272012-07-05 02:58:10 +0300331 * @return array list of migration file paths sorted by version
Phil Sturgeon9758d842011-02-07 20:39:00 +0000332 */
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400333 public function find_migrations()
Phil Sturgeon9758d842011-02-07 20:39:00 +0000334 {
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400335 $migrations = array();
Andrey Andreev39eb8062012-11-13 03:36:40 +0200336
Phil Sturgeon9758d842011-02-07 20:39:00 +0000337 // Load all *_*.php files in the migrations path
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400338 foreach (glob($this->_migration_path.'*_*.php') as $file)
Phil Sturgeon9758d842011-02-07 20:39:00 +0000339 {
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400340 $name = basename($file, '.php');
Andrey Andreev39eb8062012-11-13 03:36:40 +0200341
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400342 // Filter out non-migration files
343 if (preg_match($this->_migration_regex, $name))
Phil Sturgeon9758d842011-02-07 20:39:00 +0000344 {
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400345 $number = $this->_get_migration_number($name);
Andrey Andreev39eb8062012-11-13 03:36:40 +0200346
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400347 // There cannot be duplicate migration numbers
348 if (isset($migrations[$number]))
349 {
350 $this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $number);
351 show_error($this->_error_string);
352 }
Andrey Andreev39eb8062012-11-13 03:36:40 +0200353
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400354 $migrations[$number] = $file;
Phil Sturgeon9758d842011-02-07 20:39:00 +0000355 }
356 }
Eric Barnesdd81c432011-11-16 11:07:35 -0500357
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400358 ksort($migrations);
359 return $migrations;
360 }
361
362 // --------------------------------------------------------------------
363
364 /**
365 * Extracts the migration number from a filename
366 *
Andrey Andreev39eb8062012-11-13 03:36:40 +0200367 * @param string $migration
Andrey Andreev3a9f3252014-02-25 11:47:45 +0200368 * @return string Numeric portion of a migration filename
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400369 */
370 protected function _get_migration_number($migration)
371 {
Andrey Andreev3a9f3252014-02-25 11:47:45 +0200372 return sscanf($migration, '%[0-9]+', $number)
373 ? $number : '0';
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400374 }
375
376 // --------------------------------------------------------------------
377
378 /**
379 * Extracts the migration class name from a filename
380 *
Andrey Andreev39eb8062012-11-13 03:36:40 +0200381 * @param string $migration
382 * @return string text portion of a migration filename
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400383 */
384 protected function _get_migration_name($migration)
385 {
386 $parts = explode('_', $migration);
387 array_shift($parts);
388 return implode('_', $parts);
Phil Sturgeon9758d842011-02-07 20:39:00 +0000389 }
390
391 // --------------------------------------------------------------------
392
393 /**
394 * Retrieves current schema version
395 *
Andrey Andreev3a9f3252014-02-25 11:47:45 +0200396 * @return string Current migration version
Phil Sturgeon9758d842011-02-07 20:39:00 +0000397 */
Phil Sturgeon96bd33b2011-05-04 01:30:36 +0100398 protected function _get_version()
Phil Sturgeon9758d842011-02-07 20:39:00 +0000399 {
Phil Sturgeond268eda2011-12-31 16:20:11 +0000400 $row = $this->db->select('version')->get($this->_migration_table)->row();
Andrey Andreev3a9f3252014-02-25 11:47:45 +0200401 return $row ? $row->version : '0';
Phil Sturgeon9758d842011-02-07 20:39:00 +0000402 }
403
404 // --------------------------------------------------------------------
405
406 /**
407 * Stores the current schema version
408 *
Andrey Andreev3a9f3252014-02-25 11:47:45 +0200409 * @param string $migration Migration reached
Andrey Andreev9b1db792012-03-26 19:45:51 +0300410 * @return void Outputs a report of the migration
Phil Sturgeon9758d842011-02-07 20:39:00 +0000411 */
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400412 protected function _update_version($migration)
Phil Sturgeon9758d842011-02-07 20:39:00 +0000413 {
Cloudmanic Labs, LLC539dcb02011-09-18 12:08:56 -0700414 return $this->db->update($this->_migration_table, array(
Jonathon Hill34c8b9c2012-10-31 14:02:35 -0400415 'version' => $migration
Phil Sturgeon9758d842011-02-07 20:39:00 +0000416 ));
417 }
418
419 // --------------------------------------------------------------------
420
421 /**
Phil Sturgeon9758d842011-02-07 20:39:00 +0000422 * Enable the use of CI super-global
423 *
Andrey Andreev39eb8062012-11-13 03:36:40 +0200424 * @param string $var
Phil Sturgeon9758d842011-02-07 20:39:00 +0000425 * @return mixed
426 */
427 public function __get($var)
428 {
429 return get_instance()->$var;
430 }
Andrey Andreev56454792012-05-17 14:32:19 +0300431
Phil Sturgeon96bd33b2011-05-04 01:30:36 +0100432}
433
434/* End of file Migration.php */
Andrey Andreev9b1db792012-03-26 19:45:51 +0300435/* Location: ./system/libraries/Migration.php */