Methods summary
public
|
#
__construct( array $schema = array(), string $dbNamespace = null )
Constructor
Parameters
- $schema
- The array of schema definition
- $dbNamespace
- The namespace for the database schema
|
public
object
|
#
setSchema( array $schema )
Setter for the property schema
Setter for the property schema
Parameters
- $schema
- The array of schema definition
Returns
object SchemaManager
|
public
array
|
#
getSchema( )
Getter for the property schema
Getter for the property schema
Returns
array The array of schema definition
|
public
string
|
#
getDriver( )
Getter for the property driver
Getter for the property driver
Returns
string
|
public
object
|
#
setDbNamespace( string $namespace )
Setter for the property dbNamespace
Setter for the property dbNamespace
Parameters
Returns
object SchemaManager
|
public
string
|
#
getDbNamespace( )
Getter for the property dbNamespace
Getter for the property dbNamespace
Returns
string
|
public
string
|
#
getFieldStatement( string $field, array $definition, string $collate = null )
Get field statement for CREATE TABLE
Get field statement for CREATE TABLE
Parameters
- $field
- The field name
- $definition
- SchemaManager field definition
- $collate
- The collation for the field; if it is null, db collation is used
Returns
string The field statement
|
public
string
|
#
getVendorFieldType( array & $definition )
Get field type
Parameters
- $definition
- SchemaManager field definition
Returns
string The underlying db field type
|
public
integer
|
#
getFieldLength( array & $definition )
Get field length
Parameters
- $definition
- SchemaManager field definition
Returns
integer The field length
|
protected
array
|
#
getFKField( string $fkTable, array $relation )
Get foreign key schema definition
Get foreign key schema definition
Parameters
- $fkTable
- The reference table name
- $relation
- The relationship definition
Returns
array Foreign key schema definition
|
protected
array|null
|
#
getFKConstraint( string $fkTable, array $relation, array $schema = array() )
Get foreign key constraint definition
Get foreign key constraint definition
Parameters
- $fkTable
- The reference table name
- $relation
- The relationship definition
- $schema
- The whole schema definition
Returns
array|null Foreign key constraint definition
|
public
boolean
|
#
build( string $dbNamespace = null, boolean $backup = false )
Export the built schema definition into a file
Export the built schema definition into a file
Parameters
- $dbNamespace
- The namespace for the database
- $backup
- Create a backup file or not
Returns
boolean TRUE for success; FALSE for failure
|
public
boolean
|
#
import( string $dbNamespace = null )
Import schema to the database
Import schema to the database
Parameters
- $dbNamespace
- The namespace for the database
Returns
boolean TRUE for success; FALSE for failure
|
public
boolean
|
#
export( string $dbNamespace = null )
Export sql dump file
Parameters
- $dbNamespace
- The namespace for the database
Returns
boolean TRUE for success; FALSE for failure
|
public
boolean
|
#
update( LucidFrame\Console\Command $cmd, string $dbNamespace = null )
Update schema to the latest version
Update schema to the latest version
Parameters
- $cmd
- LucidFrame\Console\Command
- $dbNamespace
- The namespace for the database
Returns
boolean TRUE for success; FALSE for failure
|
public
boolean
|
#
diff( LucidFrame\Console\Command $cmd, string $dbNamespace = null )
Find the schema difference and generate SQL file
Find the schema difference and generate SQL file
Parameters
- $cmd
- LucidFrame\Console\Command
- $dbNamespace
- The namespace for the database
Returns
boolean TRUE for SQL file exported; FALSE for no updates
|
public
array
|
#
generateSqlFromDiff( array $schemaFrom, array $schemaTo, LucidFrame\Console\Command $cmd )
Get schema difference and generate SQL statements
Get schema difference and generate SQL statements
Parameters
- $schemaFrom
- Array of the current schema data
- $schemaTo
- Array of the updated schema data
- $cmd
- LucidFrame\Console\Command
Returns
array
|
public
string|boolean
|
#
migrate( array $versions, array $schemaFrom, array $schemaTo, boolean $verbose = true )
Migrate db to the latest version
Migrate db to the latest version
Parameters
- $versions
- Array of versions (older to newer)
- $schemaFrom
- Array of the current schema data
- $schemaTo
- Array of the updated schema data
- $verbose
- Output in console or not
Returns
string|boolean
|
public
boolean
|
#
isSchemaChanged( array $from, array $to )
Check if schema changed
Parameters
- $from
- The last schema
- $to
- The changed schema
Returns
boolean TRUE if the schema is changed, otherwise FALSE
|
public
integer
|
#
getCurrentVersion( )
Get the current db version
Get the current db version
Returns
integer The version number
|
public
mixed
|
#
checkVersions( array $schema )
Check db version files in the version directory against the current version in $schema[_options][version]
Check db version files in the version directory against the current version in $schema[_options][version]
Parameters
- $schema
- The schema to check in
Returns
mixed 0 if there is no version file;
1 if the schema is up-to-date;
ARRAY if there is version file to migrate
|
public
boolean
|
#
isLoaded( )
Check if the schema is parsed and fully loaded
Check if the schema is parsed and fully loaded
Returns
boolean TRUE/FALSE
|
protected
mixed
|
#
isRenamed( string $needle, array $haystack )
Check if a table or field is renamed
Check if a table or field is renamed
Parameters
- $needle
- The table or field name
- $haystack
- Array of renamed fields or tables
Returns
mixed The renamed table name or field name or false
|
public
boolean
|
#
hasTable( string $table )
Check if the table exists
Check if the table exists
Parameters
Returns
boolean TRUE if the table exists, otherwise FALSE
|
public
boolean
|
#
hasField( string $table, string $field )
Check if a field exists
Parameters
- $table
- The table name
- $field
- The field name
Returns
boolean TRUE if the table exists, otherwise FALSE
|
public
boolean
|
#
hasTimestamps( string $table )
Check if the table has the timestamp fields or not
Check if the table has the timestamp fields or not
Parameters
- $table
- The table name without prefix
Returns
boolean TRUE if the table has the timestamp fields, otherwise FALSE
|
public
boolean
|
#
hasSlug( string $table )
Check if the table has the slug field or not
Check if the table has the slug field or not
Parameters
- $table
- The table name without prefix
Returns
boolean TRUE if the table has the slug field, otherwise FALSE
|
public
string
|
#
getFieldType( string $table, string $field )
Get data type of the field
Get data type of the field
Parameters
- $table
- The table name
- $field
- The field name in the table
Returns
string The data type or null if there is no field
|
protected
array
|
#
getOptions( )
Get schema options if it is defined
otherwise return the default options
Get schema options if it is defined
otherwise return the default options
Returns
array
|
protected
array
|
#
getTableOptions( array $tableDef )
Get table options if it is defined
otherwise return the default options
Get table options if it is defined
otherwise return the default options
Parameters
- $tableDef
- The table definition
Returns
array
|
public
array
|
#
populatePrimaryKeys( array & $schema )
Populate primary keys acccording to the schema defined
Populate primary keys acccording to the schema defined
Parameters
- $schema
- The database schema
Returns
array
|
public
array
|
#
populatePivots( array & $schema )
Populate pivot tables (joint tables fo many-to-many relationship) into the schema
Populate pivot tables (joint tables fo many-to-many relationship) into the schema
Parameters
- $schema
- The database schema
Returns
array Array of constraints
|
public
string
|
#
createTableStatement( string $table, array & $schema, array & $pkFields, array & $constraints )
Generate CREATE TABLE SQL
Generate CREATE TABLE SQL
Parameters
- $table
- The new table name
- $schema
- The database schema
- $pkFields
- Array of PK fields
- $constraints
- Array of FK constraints
Returns
string
|
public
array
|
#
createConstraintStatements( array $constraints = null )
Generate foreign key constraints SQL statements
Generate foreign key constraints SQL statements
Parameters
- $constraints
- Array of populated constraints
Returns
array Array of SQL statements
|
public
array
|
#
dropConstraintStatements( array $constraints = null )
Generate DROP foreign key constraints SQL statements
Generate DROP foreign key constraints SQL statements
Parameters
- $constraints
- Array of populated constraints
Returns
array Array of SQL statements
|
public
|
#
setPrimaryKeys( array $pkFields )
Set the populated primary keys into the schema database options
Set the populated primary keys into the schema database options
Parameters
- $pkFields
- Array of primary keys
|
public
array
|
#
getPrimaryKeys( array $schema = null )
Get the populated primary keys from the schema database options
Get the populated primary keys from the schema database options
Parameters
- $schema
- The schema definition
Returns
array Array of primary keys
|
public
|
#
setConstraints( array $constraints )
Set the populated foreign key constraints into the schema database options
Set the populated foreign key constraints into the schema database options
Parameters
- $constraints
- Array of FK constraints
|
public
array
|
#
getConstraints( array $schema = null )
Get the populated foreign key constraints from the schema database options
Get the populated foreign key constraints from the schema database options
Parameters
- $schema
- The schema definition
Returns
array Array of FK constraints
|
public
string
|
#
getTableCollation( string $table, array $schema = null )
Return table collation from the schema definition
Return table collation from the schema definition
Parameters
- $table
- The table name
- $schema
- The schema definition (optional)
Returns
string
|
public static
array
|
#
getSchemaLockDefinition( string $dbNamespace = null )
Get schema definition from the built schema file
Get schema definition from the built schema file
Parameters
- $dbNamespace
- The namespace for the database
Returns
array The schema definition; NULL when there is no file
|
public static
string
|
#
getSchemaLockFileName( string $dbNamespace = null, boolean $backupFileName = false )
Get schema lock file name
Get schema lock file name
Parameters
- $dbNamespace
- The namespace for the database
- $backupFileName
- If true, ~ will be prefixed in the file name
Returns
string The file name with full path
|