-
Notifications
You must be signed in to change notification settings - Fork 194
Libraries Plain Migration
Library | Extends | Path |
---|---|---|
Plain_Migration | CI_Migration | /application/libraries/Plain_Migration.php |
This library extends the default Codeigniter Migration. It allows us to customize a few methods to make better use of migrations.
Called automatically which in turn calls the parent constructor.
Migrate to specified version. Overwrites the default Migrations library behaviour, so we can create database backup before migrating.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$target_version | int | N/A | Yes | Target schema version |
Create database backup and save it to file.
Create database backup file in backup folder.
Remove database backup file
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$backupFile | string | N/A | Yes | Path to a database backup file. |
Checks to make sure all the columns sent exist in the table sent. If not it logs an error, shows a 500 error and stops the migration. Easy way to check if all the columns per table exist before you run the migration.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$columns | Mixed | N/A | Yes | A string or array of columns to check for in the table. |
$table | String | N/A | Yes | The table name to check for the columns in. |
// check a single column
parent::checkForColumns('column', 'table_name');
// check multiple columns
parent::checkForColumns(array('column', 'column1'), 'table_name');
Checks to make sure all the tables sent exist. If not it logs an error, shows a 500 error and stops the migration. Easy way to check for the tables to be used in the current migration for you run the migration.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$tables | Mixed | N/A | Yes | A string or array of table to check if exist. |
// check a single table
parent::checkForTables('table_name');
// check multiple columns
parent::checkForTables(array('table_name', 'table_name_1'));
Gets the columns from a table. Codeigniter already does this but it caches them. When running multiple migrations in a row, the Codeigniter calls will fail.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$table | String | N/A | Yes | The table name to extract the columns from. |
// Get all the columns from a table
$columns = self::getColumns('table_name');
Returns true or false if a table exists. Codeigniter already does this but it caches the tables. When running multiple migrations in a row, the Codeigniter calls will fail.
Variable | Type | Default | Required | Description |
---|---|---|---|---|
$table | String | N/A | Yes | The table name to check for. |
// Check for table
if (self::tableExists('table')) {
// Run shiz
}