PHP Class MigrationVersion

Show file Open project: cakedc/migrations Class Usage Examples

Public Properties

Property Type Description
$Version Model Instance of SchemaMigrations model
$connection string Connection used for the migration_schema table of the migration versions
$dry boolean If try, the SQL will be outputted to screen rather than applied to the database
$jumpTo null | string Jump to a certain migration.
$log array This is used for dry run
$migrationConnection null | string This can be used to override the connection of migration file
$precheck string Precheck mode
$skip array Skip a version or it can skip many version using comma as separate.

Protected Properties

Property Type Description
$_mapping array Mapping cache

Public Methods

Method Description
__construct ( array $options = [] ) Constructor
getMapping ( string $type, boolean $cache = true ) : mixed Get mapping for the given type
getMigration ( string $name, string $class, string $type, array $options = [] ) : boolean | CakeMigration Load and make a instance of the migration
getVersion ( string $type ) : integer Get last version for given type
getVersionByName ( array $mapping ) : boolean | string Will return a version based in the migration name
initVersion ( ) : void Get a new SchemaMigration instance
jump ( array $version, array $type ) : void Jump to a certain migration and mark the preceding migrations as executed.
run ( array $options ) : boolean Run the migrations
setVersion ( integer $version, string $type, boolean $migrated = true ) : boolean Set current version for given type

Protected Methods

Method Description
_enumerateMigrations ( string $type ) : array Returns a map of all available migrations for a type (app or plugin)
_enumerateNewMigrations ( string $type ) : array Returns a map of all available migrations for a type (app or plugin) using inflection
_enumerateOldMigrations ( string $type ) : array Returns a map of all available migrations for a type (app or plugin) using regular expressions
_initMigrations ( ) : void Initialize the migrations schema and keep it up-to-date
_loadFile ( string $name, string $type ) : mixed Load a file based on name and type

Method Details

__construct() public method

Constructor
public __construct ( array $options = [] )
$options array optional load object properties

_enumerateMigrations() protected method

Returns a map of all available migrations for a type (app or plugin)
protected _enumerateMigrations ( string $type ) : array
$type string Can be 'app' or a plugin name
return array containing a list of migration versions ordered by filename

_enumerateNewMigrations() protected method

Returns a map of all available migrations for a type (app or plugin) using inflection
protected _enumerateNewMigrations ( string $type ) : array
$type string Can be 'app' or a plugin name
return array containing a list of migration versions ordered by filename

_enumerateOldMigrations() protected method

Returns a map of all available migrations for a type (app or plugin) using regular expressions
protected _enumerateOldMigrations ( string $type ) : array
$type string Can be 'app' or a plugin name
return array containing a list of migration versions ordered by filename

_initMigrations() protected method

Initialize the migrations schema and keep it up-to-date
protected _initMigrations ( ) : void
return void

_loadFile() protected method

Load a file based on name and type
protected _loadFile ( string $name, string $type ) : mixed
$name string File name to be loaded
$type string Can be 'app' or a plugin name
return mixed Throw an exception in case of no file found, array with mapping

getMapping() public method

Get mapping for the given type
public getMapping ( string $type, boolean $cache = true ) : mixed
$type string Can be 'app' or a plugin name
$cache boolean Whether to return the cached value or not
return mixed False in case of no file found or empty mapping, array with mapping

getMigration() public method

Load and make a instance of the migration
public getMigration ( string $name, string $class, string $type, array $options = [] ) : boolean | CakeMigration
$name string File name where migration resides
$class string Migration class name
$type string Can be 'app' or a plugin name
$options array Extra options to send to CakeMigration class
return boolean | CakeMigration False in case of no file found, instance of the migration

getVersion() public method

Get last version for given type
public getVersion ( string $type ) : integer
$type string Can be 'app' or a plugin name
return integer Last version migrated

getVersionByName() public method

Will return a version based in the migration name
public getVersionByName ( array $mapping ) : boolean | string
$mapping array mapping of all migrations.
return boolean | string

initVersion() public method

Get a new SchemaMigration instance
public initVersion ( ) : void
return void

jump() public method

Jump to a certain migration and mark the preceding migrations as executed.
public jump ( array $version, array $type ) : void
$version array Version of a migration to jump to.
$type array migration type
return void

run() public method

Options: - direction - Direction to run - version - Until what version want migrate to
public run ( array $options ) : boolean
$options array An array with options.
return boolean

setVersion() public method

Set current version for given type
public setVersion ( integer $version, string $type, boolean $migrated = true ) : boolean
$version integer Current version
$type string Can be 'app' or a plugin name
$migrated boolean If true, will add the record to the database If false, will remove the record from the database
return boolean

Property Details

$Version public property

Instance of SchemaMigrations model
public Model $Version
return Model

$_mapping protected property

Mapping cache
protected array $_mapping
return array

$connection public property

Connection used for the migration_schema table of the migration versions
public string $connection
return string

$dry public property

If try, the SQL will be outputted to screen rather than applied to the database
public bool $dry
return boolean

$jumpTo public property

Jump to a certain migration.
public null|string $jumpTo
return null | string

$log public property

This is used for dry run
public array $log
return array

$migrationConnection public property

This can be used to override the connection of migration file
public null|string $migrationConnection
return null | string

$precheck public property

Precheck mode
public string $precheck
return string

$skip public property

Skip a version or it can skip many version using comma as separate.
public array $skip
return array