Methods |
public
|
__construct(array $schema = [], string $dbNamespace = null)
Constructor
Parameters
$schema |
The array of schema definition
|
$dbNamespace |
The namespace for the database schema
|
|
#
|
public
|
setSchema(array $schema): object
Setter for the property `schema`
Setter for the property schema
Parameters
$schema |
The array of schema definition
|
Returns
|
#
|
public
|
getSchema(): array
Getter for the property `schema`
Getter for the property schema
Returns
The array of schema definition
|
#
|
public
|
getDriver(): string
Getter for the property `driver`
Getter for the property driver
|
#
|
public
|
setDbNamespace(string $namespace): object
Setter for the property `dbNamespace`
Setter for the property dbNamespace
Parameters
Returns
|
#
|
public
|
getDbNamespace(): string
Getter for the property `dbNamespace`
Getter for the property dbNamespace
|
#
|
public
|
getFieldStatement(string $field, array $definition, string $collate = null): string
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
|
#
|
public
|
getVendorFieldType(array &$definition): string
Get field type
Parameters
$definition |
SchemaManager field definition
|
Returns
The underlying db field type
|
#
|
public
|
getFieldLength(array &$definition): integer
Get field length
Parameters
$definition |
SchemaManager field definition
|
Returns
|
#
|
protected
|
getFKField(string $fkTable, array $relation): array
Get foreign key schema definition
Get foreign key schema definition
Parameters
$fkTable |
The reference table name
|
$relation |
The relationship definition
|
Returns
Foreign key schema definition
|
#
|
protected
|
getFKConstraint(string $fkTable, array $relation, array $schema = []): array|null
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
Foreign key constraint definition
|
#
|
public
|
build(string $dbNamespace = null, boolean $backup = false): boolean
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
TRUE for success; FALSE for failure
|
#
|
public
|
import(string $dbNamespace = null): boolean
Import schema to the database
Import schema to the database
Parameters
$dbNamespace |
The namespace for the database
|
Returns
TRUE for success; FALSE for failure
|
#
|
public
|
export(string $dbNamespace = null): boolean
Export sql dump file
Parameters
$dbNamespace |
The namespace for the database
|
Returns
TRUE for success; FALSE for failure
|
#
|
public
|
update(Command $cmd, string $dbNamespace = null): boolean
Update schema to the latest version
Update schema to the latest version
Parameters
$cmd |
LucidFrame\Console\Command
|
$dbNamespace |
The namespace for the database
|
Returns
TRUE for success; FALSE for failure
|
#
|
public
|
diff(Command $cmd, string $dbNamespace = null): boolean
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
TRUE for SQL file exported; FALSE for no updates
|
#
|
public
|
generateSqlFromDiff(array $schemaFrom, array $schemaTo, Command $cmd): array
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
|
|
#
|
public
|
migrate(array $versions, array $schemaFrom, array $schemaTo, bool $verbose = true): string|bool
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
|
|
#
|
public
|
isSchemaChanged(array $from, array $to): bool
Check if schema changed
Parameters
$from |
The last schema
|
$to |
The changed schema
|
Returns
TRUE if the schema is changed, otherwise FALSE
|
#
|
public
|
getCurrentVersion(): integer
Get the current db version
Get the current db version
Returns
|
#
|
public
|
checkVersions(array $schema): mixed
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
|
|
#
|
public
|
isLoaded(): boolean
Check if the schema is parsed and fully loaded
Check if the schema is parsed and fully loaded
Returns
|
#
|
protected
|
isRenamed(string $needle, array $haystack): mixed
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
The renamed table name or field name or false
|
#
|
public
|
hasTable(string $table): boolean
Check if the table exists
Check if the table exists
Parameters
Returns
TRUE if the table exists, otherwise FALSE
|
#
|
public
|
hasField(string $table, string $field): boolean
Check if a field exists
Parameters
$table |
The table name
|
$field |
The field name
|
Returns
TRUE if the table exists, otherwise FALSE
|
#
|
public
|
hasTimestamps(string $table): boolean
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
TRUE if the table has the timestamp fields, otherwise FALSE
|
#
|
public
|
hasSlug(string $table): boolean
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
TRUE if the table has the slug field, otherwise FALSE
|
#
|
public
|
getFieldType(string $table, string $field): string
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
The data type or null if there is no field
|
#
|
protected
|
getOptions(): array
Get schema options if it is defined
otherwise return the default options
Get schema options if it is defined
otherwise return the default options
|
#
|
protected
|
getTableOptions(array $tableDef): array
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
|
|
#
|
public
|
populatePrimaryKeys(array &$schema): array
Populate primary keys acccording to the schema defined
Populate primary keys acccording to the schema defined
Parameters
$schema |
The database schema
|
|
#
|
public
|
populatePivots(array &$schema): array
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
|
#
|
public
|
createTableStatement(string $table, array &$schema, array &$pkFields, array &$constraints): string
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
|
|
#
|
public
|
createConstraintStatements(array $constraints = null): array
Generate foreign key constraints SQL statements
Generate foreign key constraints SQL statements
Parameters
$constraints |
Array of populated constraints
|
Returns
|
#
|
public
|
dropConstraintStatements(array $constraints = null): array
Generate DROP foreign key constraints SQL statements
Generate DROP foreign key constraints SQL statements
Parameters
$constraints |
Array of populated constraints
|
Returns
|
#
|
public
|
setPrimaryKeys(array $pkFields): void
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
|
getPrimaryKeys(array $schema = null): array
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
|
#
|
public
|
setConstraints(array $constraints): void
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
|
getConstraints(array $schema = null): array
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
|
#
|
public
|
getTableCollation(string $table, array $schema = null): string
Return table collation from the schema definition
Return table collation from the schema definition
Parameters
$table |
The table name
|
$schema |
The schema definition (optional)
|
|
#
|
public
static
|
getSchemaLockDefinition(string $dbNamespace = null): array
Get schema definition from the built schema file
Get schema definition from the built schema file
Parameters
$dbNamespace |
The namespace for the database
|
Returns
The schema definition; NULL when there is no file
|
#
|
public
static
|
getSchemaLockFileName(string $dbNamespace = null, boolean $backupFileName = false): string
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
The file name with full path
|
#
|