diff options
Diffstat (limited to 'user_guide_src')
-rw-r--r-- | user_guide_src/source/changelog.rst | 4 | ||||
-rw-r--r-- | user_guide_src/source/libraries/migration.rst | 84 |
2 files changed, 59 insertions, 29 deletions
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 1a80f76a3..707d8b3ea 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -40,6 +40,7 @@ Release Date: Not Released - Updated support for csv files in mimes.php. - Added some more doctypes. - Added Romanian, Greek, Vietnamese and Cyrilic characters in *application/config/foreign_characters.php*. + - Added Romanian, Greek and Vietnamese characters in *foreign_characters.php*. - Changed logger to only chmod when file is first created. - Removed previously deprecated SHA1 Library. - Removed previously deprecated use of ``$autoload['core']`` in *application/config/autoload.php*. @@ -249,6 +250,9 @@ Release Date: Not Released - Removed previously deprecated ``sha1()`` method. - Changed :doc:`Language Library <libraries/language>` method ``load()`` to filter the language name with ``ctype_digit()``. - :doc:`Profiler Library <general/profiling>` now also displays database object names. + - :doc:`Migration Library <libraries/migration>` changes include: + - Added support for timestamp-based migrations (enabled by default) + - Added ``$config['migration_style']`` to allow switching between sequential migrations and timestamp migrations - Core diff --git a/user_guide_src/source/libraries/migration.rst b/user_guide_src/source/libraries/migration.rst index cb7d96a6d..246396171 100644 --- a/user_guide_src/source/libraries/migration.rst +++ b/user_guide_src/source/libraries/migration.rst @@ -13,17 +13,40 @@ run so all you have to do is update your application files and call **$this->migrate->current()** to work out which migrations should be run. The current version is found in **config/migration.php**. +******************** +Migration file names +******************** + +Each Migration is run in numeric order forward or backwards depending on the +method taken. Two numbering styles are available: + +* **Sequential:** each migration is numbered in sequence, starting with **001**. + Each number must be three digits, and there must not be any gaps in the + sequence. (This was the numbering scheme prior to CodeIgniter 3.0.) +* **Timestamp:** each migration is numbered using the timestamp when the migration + was created, in **YYYYMMDDHHIISS** format (e.g. **20121031100537**). This + helps prevent numbering conflicts when working in a team environment, and is + the preferred scheme in CodeIgniter 3.0 and later. + +The desired style may be selected using the **$config['migration_style']** +setting in your **migration.php** config file. + +Regardless of which numbering style you choose to use, prefix your migration +files with the migration number followed by an underscore and a descriptive +name for the migration. For example: + +* **001_add_blog.php** (sequential numbering) +* **20121031100537_add_blog.php** (timestamp numbering) + ****************** Create a Migration ****************** - -.. note:: Each Migration is run in numerical order forward or backwards - depending on the method taken. Use a prefix of 3 numbers followed by an - underscore for the filename of your migration. This will be the first migration for a new site which has a blog. All migrations go in the folder **application/migrations/** and have names such -as: **001_add_blog.php**.:: +as **20121031100537_add_blog.php**.:: + + <?php defined('BASEPATH') OR exit('No direct script access allowed'); @@ -47,7 +70,7 @@ as: **001_add_blog.php**.:: 'null' => TRUE, ), )); - + $this->dbforge->add_key('blog_id', TRUE); $this->dbforge->create_table('blog'); } @@ -55,6 +78,7 @@ as: **001_add_blog.php**.:: { $this->dbforge->drop_table('blog'); } + } Then in **application/config/migration.php** set **$config['migration_version'] = 1;**. @@ -65,25 +89,25 @@ Usage Example In this example some simple code is placed in **application/controllers/migrate.php** to update the schema.:: - $this->load->library('migration'); - - if ( ! $this->migration->current()) + <?php + + class Migrate extends CI_Controller { - show_error($this->migration->error_string()); + public function index() + { + $this->load->library('migration'); + + if ($this->migration->current() === FALSE) + { + show_error($this->migration->error_string()); + } + } } ****************** Function Reference ****************** -There are five available methods for the Migration class: - -- $this->migration->current(); -- $this->migration->error_string(); -- $this->migration->find_migrations(); -- $this->migration->latest(); -- $this->migration->version(); - $this->migration->current() ============================ @@ -124,14 +148,16 @@ Migration Preferences The following is a table of all the config options for migrations. -========================== ====================== ============= ============================================= -Preference Default Options Description -========================== ====================== ============= ============================================= -**migration_enabled** FALSE TRUE / FALSE Enable or disable migrations. -**migration_path** APPPATH.'migrations/' None The path to your migrations folder. -**migration_version** 0 None The current version your database should use. -**migration_table** migrations None The table name for storing the shema - version number. -**migration_auto_latest** FALSE TRUE / FALSE Enable or disable automatically - running migrations. -========================== ====================== ============= ============================================= +========================== ====================== ========================== ============================================= +Preference Default Options Description +========================== ====================== ========================== ============================================= +**migration_enabled** FALSE TRUE / FALSE Enable or disable migrations. +**migration_path** APPPATH.'migrations/' None The path to your migrations folder. +**migration_version** 0 None The current version your database should use. +**migration_table** migrations None The table name for storing the schema + version number. +**migration_auto_latest** FALSE TRUE / FALSE Enable or disable automatically + running migrations. +**migration_style** 'timestamp' 'timestamp' / 'sequential' The type of numeric identifier used to name + migration files. +========================== ====================== ========================== ============================================= |