PHP Class MigrationShell

Inheritance: extends AppShell
Afficher le fichier Open project: cakedc/migrations

Méthodes publiques

Свойство Type Description
$Version MigrationVersion MigrationVersion instance
$connection null | string Connection used for the migration_schema table of the migration versions
$migrationConnection null | string This can be used to override the connection of migration file
$path string Current path to load and save migrations
$skip array Skip a version or it can skip many version using comma as separate.
$type string Type of migration, can be 'app' or a plugin name

Protected Properties

Свойство Type Description
$_messages array Messages used to display action being performed

Méthodes publiques

Méthode Description
afterMigration ( &$Migration, string $direction ) : void Callback used to create a new line after the migration
beforeAction ( &$Migration, string $type, array $data ) : void Callback used to display actions being performed
beforeMigration ( &$Migration, string $direction ) : void Callback used to display what migration is being runned
generate ( ) : void Generate a new migration file
getOptionParser ( ) : string Get the option parser.
main ( ) : void Override main
run ( ) : void Run the migrations
startup ( ) : void Override startup
status ( ) : void Displays a status of all plugin and app migrations

Méthodes protégées

Méthode Description
_connectionNamesEnum ( ) : array Get a list of connection names.
_execute ( array $options, boolean $once ) : boolean Execute migration
_fieldNamesArray ( array $fields ) : array Return list of field names from array of field/index definitions
_finalizeGeneratedMigration ( &$migration, &$migrationName, &$fromSchema ) : void Finalizes the generated migration - offers to preview it, prompts for a name, writes the file, and updates db version if needed.
_findSchemaFile ( Folder $folder, string $schemaFiles, string $name ) : mixed Finds schema file
_fromComparison ( array $migration, array $comparison, array $oldTables, array $currentTables ) : array Generate a migration string using comparison
_generateDump ( &$migration ) : void Generate a dump of the current database.
_generateFromCliArgs ( &$migration, &$migrationName, &$comparison ) : void Generate a migration from arguments passed in at the command line
_generateFromComparison ( &$migration, &$oldSchema, &$comparison ) : void Generate a migration by comparing schema.php with the database.
_generateFromInverseComparison ( &$migration, &$oldSchema, &$comparison ) : void Generate a migration by comparing the database with schema.php.
_generateMigration ( string $name, string $class, array $migration ) : string Generate a migration
_generateTemplate ( string $template, array $vars ) : string Include and generate a template string based on a template file
_getFieldType ( string $field, string $type, array $validTypes ) : string Return valid field type based on name of field
_getPath ( string $type = null ) : string Return the path used
_getSchema ( string $type = null ) : mixed Load and construct the schema class if exists
_getSchemaClassName ( string $name = null, boolean $suffix = true ) : string Gets the schema class name
_migrationChanges ( array $migration ) : boolean _migrationsChanges method
_outputLog ( array $log ) : void Output the SQL log in dry mode
_overwriteSchema ( ) : void Overwrite the schema.php file
_parseCommandLineFields ( string $name ) : array Parse fields from the command line for use with generating new migration files
_parseSingleCommandLineField ( &$fields, &$indexes, string $field, array $validTypes ) : void Parse a single argument from the command line into the fields array
_promptForMigrationName ( ) : string Prompt the user for a name for their new migration.
_promptVersionOptions ( array $mapping, string $latestVersion ) : array Output prompt with different migration versions to choose from
_readSchema ( ) : array Reads the schema data
_showInfo ( array $mapping, string $type = null ) : void Shows a list of available migrations
_singleStepOptions ( array $mapping, string $latestVersion, array $default = [] ) : array Single step options for up/down migrations
_startMigrationConnection ( ) : string Set a migration connection
_updateSchema ( ) : void Update the schema, making a call to schema shell
_values ( array $values ) : string Format a array/string into a one-line syntax
_writeMigration ( string $name, integer $version, array $migration ) : boolean Write a migration with given name

Method Details

_connectionNamesEnum() protected méthode

Get a list of connection names.
protected _connectionNamesEnum ( ) : array
Résultat array The list of connection names

_execute() protected méthode

Execute migration
protected _execute ( array $options, boolean $once ) : boolean
$options array Options for migration
$once boolean True to only run once, false to retry
Résultat boolean True if success

_fieldNamesArray() protected méthode

Return list of field names from array of field/index definitions
protected _fieldNamesArray ( array $fields ) : array
$fields array Field/index definitions
Résultat array List of field names

_finalizeGeneratedMigration() protected méthode

Finalizes the generated migration - offers to preview it, prompts for a name, writes the file, and updates db version if needed.
protected _finalizeGeneratedMigration ( &$migration, &$migrationName, &$fromSchema ) : void
Résultat void

_findSchemaFile() protected méthode

Finds schema file
protected _findSchemaFile ( Folder $folder, string $schemaFiles, string $name ) : mixed
$folder Folder Folder object with schema folder path.
$schemaFiles string Schema files inside schema folder.
$name string Schema-class name.
Résultat mixed null in case of no file found, schema file.

_fromComparison() protected méthode

Generate a migration string using comparison
protected _fromComparison ( array $migration, array $comparison, array $oldTables, array $currentTables ) : array
$migration array Migration instructions array
$comparison array Result from CakeSchema::compare()
$oldTables array List of tables on schema.php file
$currentTables array List of current tables on database
Résultat array

_generateDump() protected méthode

Generate a dump of the current database.
protected _generateDump ( &$migration ) : void
Résultat void (The variables passed by reference are changed; nothing is returned)

_generateFromCliArgs() protected méthode

Generate a migration from arguments passed in at the command line
protected _generateFromCliArgs ( &$migration, &$migrationName, &$comparison ) : void
Résultat void (The variables passed by reference are changed; nothing is returned)

_generateFromComparison() protected méthode

Generate a migration by comparing schema.php with the database.
protected _generateFromComparison ( &$migration, &$oldSchema, &$comparison ) : void
Résultat void (The variables passed by reference are changed; nothing is returned)

_generateFromInverseComparison() protected méthode

Generate a migration by comparing the database with schema.php.
protected _generateFromInverseComparison ( &$migration, &$oldSchema, &$comparison ) : void
Résultat void (The variables passed by reference are changed; nothing is returned)

_generateMigration() protected méthode

Generate a migration
protected _generateMigration ( string $name, string $class, array $migration ) : string
$name string Name of migration
$class string Class name of migration
$migration array Migration instructions array
Résultat string

_generateTemplate() protected méthode

Include and generate a template string based on a template file
protected _generateTemplate ( string $template, array $vars ) : string
$template string Template file name
$vars array List of variables to be used on tempalte
Résultat string

_getFieldType() protected méthode

Return valid field type based on name of field
protected _getFieldType ( string $field, string $type, array $validTypes ) : string
$field string Name of field
$type string Current type
$validTypes array List of valid types
Résultat string Recognized type (eg. integer vs bigint)

_getPath() protected méthode

Return the path used
protected _getPath ( string $type = null ) : string
$type string Can be 'app' or a plugin name
Résultat string Path used

_getSchema() protected méthode

Load and construct the schema class if exists
protected _getSchema ( string $type = null ) : mixed
$type string Can be 'app' or a plugin name
Résultat mixed False in case of no file found, schema object

_getSchemaClassName() protected méthode

Gets the schema class name
protected _getSchemaClassName ( string $name = null, boolean $suffix = true ) : string
$name string Can be 'app' or a plugin name
$suffix boolean Return the class name with or without the "Schema" suffix, default is true
Résultat string Returns the schema class name

_migrationChanges() protected méthode

_migrationsChanges method
protected _migrationChanges ( array $migration ) : boolean
$migration array list of migrations
Résultat boolean

_outputLog() protected méthode

Output the SQL log in dry mode
protected _outputLog ( array $log ) : void
$log array List of queries per migration
Résultat void

_overwriteSchema() protected méthode

Overwrite the schema.php file
protected _overwriteSchema ( ) : void
Résultat void

_parseCommandLineFields() protected méthode

Parse fields from the command line for use with generating new migration files
protected _parseCommandLineFields ( string $name ) : array
$name string Name of migration
Résultat array

_parseSingleCommandLineField() protected méthode

Parse a single argument from the command line into the fields array
protected _parseSingleCommandLineField ( &$fields, &$indexes, string $field, array $validTypes ) : void
$field string A single command line argument - eg. 'id:primary_key' or 'name:string'
$validTypes array Valid data types for the relevant database - eg. string, integer, biginteger, etc.
Résultat void

_promptForMigrationName() protected méthode

Prompt the user for a name for their new migration.
protected _promptForMigrationName ( ) : string
Résultat string

_promptVersionOptions() protected méthode

Output prompt with different migration versions to choose from
protected _promptVersionOptions ( array $mapping, string $latestVersion ) : array
$mapping array Migration version mappings
$latestVersion string Latest migration version
Résultat array User-chosen options for migration

_readSchema() protected méthode

Reads the schema data
protected _readSchema ( ) : array
Résultat array

_showInfo() protected méthode

Shows a list of available migrations
protected _showInfo ( array $mapping, string $type = null ) : void
$mapping array Migration mapping
$type string Can be 'app' or a plugin name
Résultat void

_singleStepOptions() protected méthode

Single step options for up/down migrations
protected _singleStepOptions ( array $mapping, string $latestVersion, array $default = [] ) : array
$mapping array Migration version mappings
$latestVersion string Latest migration version
$default array Default options for migration
Résultat array Modified options for migration

_startMigrationConnection() protected méthode

Set a migration connection
protected _startMigrationConnection ( ) : string
Résultat string The name of the migration connection.

_updateSchema() protected méthode

Update the schema, making a call to schema shell
protected _updateSchema ( ) : void
Résultat void

_values() protected méthode

Format a array/string into a one-line syntax
protected _values ( array $values ) : string
$values array Array to be converted
Résultat string

_writeMigration() protected méthode

Write a migration with given name
protected _writeMigration ( string $name, integer $version, array $migration ) : boolean
$name string Name of migration
$version integer The version number (timestamp)
$migration array Migration instructions array
Résultat boolean

afterMigration() public méthode

Callback used to create a new line after the migration
public afterMigration ( &$Migration, string $direction ) : void
$direction string Direction being runned
Résultat void

beforeAction() public méthode

Callback used to display actions being performed
public beforeAction ( &$Migration, string $type, array $data ) : void
$type string Type of action. i.e: create_table, drop_table, etc.
$data array Data to send to the callback
Résultat void

beforeMigration() public méthode

Additionally, shows the generation date of the migration, if the version is greater than '2000-01-01'.
public beforeMigration ( &$Migration, string $direction ) : void
$direction string Direction being runned
Résultat void

generate() public méthode

Generate a new migration file
public generate ( ) : void
Résultat void

getOptionParser() public méthode

Get the option parser.
public getOptionParser ( ) : string
Résultat string

main() public méthode

Override main
public main ( ) : void
Résultat void

run() public méthode

Run the migrations
public run ( ) : void
Résultat void

startup() public méthode

Override startup
public startup ( ) : void
Résultat void

status() public méthode

Displays a status of all plugin and app migrations
public status ( ) : void
Résultat void

Property Details

$Version public_oe property

MigrationVersion instance
public MigrationVersion $Version
Résultat MigrationVersion

$_messages protected_oe property

Messages used to display action being performed
protected array $_messages
Résultat array

$connection public_oe property

Connection used for the migration_schema table of the migration versions
public null|string $connection
Résultat null | string

$migrationConnection public_oe property

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

$path public_oe property

Current path to load and save migrations
public string $path
Résultat string

$skip public_oe property

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

$type public_oe property

Type of migration, can be 'app' or a plugin name
public string $type
Résultat string