DBSchemaManager
class DBSchemaManager
Represents and handles all schema management for a database
Config options
| check_and_repair_on_build | bool |
Methods
Enable supression of database messages.
Execute the given SQL parameterised query with the specified arguments
Initiates a schema update within a single callback
Cancels the schema updates requested during (but not after) schemaUpdate() call.
Returns true if we are during a schema update.
Returns true if schema modifications were requested during (but not after) schemaUpdate() call.
Instruct the schema manager to record a table creation to later execute
Instruct the schema manager to record a table alteration to later execute
Instruct the schema manager to record a field to be later created
Instruct the schema manager to record an index to be later created
Instruct the schema manager to record a field to be later updated
Instruct the schema manager to record an index to be later updated
Generate the following table in the database, modifying whatever already exists as necessary.
If the given table exists, move it out of the way by renaming it to obsolete(tablename).
Generate the given index in the database, modifying whatever already exists as necessary.
Returns true if the given table is exists in the current database
Return true if the table exists and already has a the field specified
Generate the given field on the table, modifying whatever already exists as necessary.
If the given field exists, move it out of the way by renaming it to obsolete(fieldname).
Show a message about database alteration
This returns the data type for the id column which is the primary key for each table
Checks a table's integrity and repairs it if necessary.
Ensure the given table has the correct case
Returns the values of the given enum field
No description
Retrieves the list of all databases the user has access to
Determine if the database with the specified name exists
Create a database with the specified name
Drops a database with the specified name
Alter an index on a table.
Return the list of indexes in a table.
Returns a list of all tables in the database.
Create a new table.
Alter a table's schema.
Rename a table.
Create a new field on a table.
Change the database column name of the given field.
Get a list of all the fields for the given table.
This allows the cached values for a table's field list to be erased.
Returns data type for 'boolean' column
Returns data type for 'date' column
Returns data type for 'decimal' column
Returns data type for 'set' column
Returns data type for 'set' column
Returns data type for 'float' column
Returns data type for 'int' column
Returns data type for 'datetime' column
Returns data type for 'text' column
Returns data type for 'time' column
Returns data type for 'varchar' column
No description
Details
at line 63
static
showTableNameWarning($table, $class)
deprecated
deprecated 4.0.0:5.0.0
at line 73
setDatabase(Database $database)
Injector injection point for database controller
at line 105
quiet(bool $quiet = true)
Enable supression of database messages.
at line 119
Query
query(string $sql, int $errorLevel = E_USER_ERROR)
Execute the given SQL query.
This abstract function must be defined by subclasses as part of the actual implementation. It should return a subclass of SS_Query as the result.
at line 133
Query
preparedQuery(string $sql, array $parameters, int $errorLevel = E_USER_ERROR)
Execute the given SQL parameterised query with the specified arguments
at line 143
schemaUpdate(callable $callback)
Initiates a schema update within a single callback
at line 205
cancelSchemaUpdate()
Cancels the schema updates requested during (but not after) schemaUpdate() call.
at line 216
boolean
isSchemaUpdating()
Returns true if we are during a schema update.
at line 226
boolean
doesSchemaNeedUpdating()
Returns true if schema modifications were requested during (but not after) schemaUpdate() call.
at line 240
transCreateTable(string $table, array $options = null, array $advanced_options = null)
Instruct the schema manager to record a table creation to later execute
at line 258
transAlterTable(string $table, array $options, array $advanced_options)
Instruct the schema manager to record a table alteration to later execute
at line 272
transCreateField(string $table, string $field, string $schema)
Instruct the schema manager to record a field to be later created
at line 285
transCreateIndex(string $table, string $index, array $schema)
Instruct the schema manager to record an index to be later created
at line 298
transAlterField(string $table, string $field, string $schema)
Instruct the schema manager to record a field to be later updated
at line 311
transAlterIndex(string $table, string $index, array $schema)
Instruct the schema manager to record an index to be later updated
at line 354
requireTable(string $table, array $fieldSchema = null, array $indexSchema = null, boolean $hasAutoIncPK = true, array $options = array(), array|bool $extensions = false)
Generate the following table in the database, modifying whatever already exists as necessary.
at line 456
dontRequireTable(string $table)
If the given table exists, move it out of the way by renaming it to obsolete(tablename).
at line 489
requireIndex(string $table, string $index, string|array|boolean $spec)
Generate the given index in the database, modifying whatever already exists as necessary.
The keys of the array are the names of the index. The values of the array can be one of: - true: Create a single column index on the field named the same as the index. - array('type' => 'index|unique|fulltext', 'value' => 'FieldA, FieldB'): This gives you full control over the index.
at line 628
abstract boolean
hasTable(string $tableName)
Returns true if the given table is exists in the current database
at line 637
bool
hasField(string $tableName, string $fieldName)
Return true if the table exists and already has a the field specified
at line 656
requireField(string $table, string $field, array|string $spec)
Generate the given field on the table, modifying whatever already exists as necessary.
at line 762
dontRequireField(string $table, string $fieldName)
If the given field exists, move it out of the way by renaming it to obsolete(fieldname).
at line 786
alterationMessage(string $message, string $type = "")
Show a message about database alteration
at line 849
abstract string
IdColumn(boolean $asDbValue = false, boolean $hasAutoIncPK = true)
This returns the data type for the id column which is the primary key for each table
at line 857
abstract boolean
checkAndRepairTable(string $tableName)
Checks a table's integrity and repairs it if necessary.
at line 865
fixTableCase(string $tableName)
Ensure the given table has the correct case
at line 897
abstract array
enumValuesForField(string $tableName, string $fieldName)
Returns the values of the given enum field
at line 908
abstract
dbDataType($type)
at line 915
abstract array
databaseList()
Retrieves the list of all databases the user has access to
at line 923
abstract boolean
databaseExists(string $name)
Determine if the database with the specified name exists
at line 931
abstract boolean
createDatabase(string $name)
Create a database with the specified name
at line 938
abstract
dropDatabase(string $name)
Drops a database with the specified name
at line 948
abstract
alterIndex(string $tableName, string $indexName, array $indexSpec)
Alter an index on a table.
at line 971
abstract array[array]
indexList(string $table)
Return the list of indexes in a table.
at line 980
abstract array
tableList()
Returns a list of all tables in the database.
Keys are table names in lower case, values are table names in case that database expects.
at line 995
abstract string
createTable(string $table, array $fields = null, array $indexes = null, array $options = null, array $advancedOptions = null)
Create a new table.
at line 1014
abstract
alterTable(string $table, array $newFields = null, array $newIndexes = null, array $alteredFields = null, array $alteredIndexes = null, array $alteredOptions = null, array $advancedOptions = null)
Alter a table's schema.
at line 1030
abstract
renameTable(string $oldTableName, string $newTableName)
Rename a table.
at line 1039
abstract
createField(string $table, string $field, string $spec)
Create a new field on a table.
at line 1048
abstract
renameField(string $tableName, string $oldName, string $newName)
Change the database column name of the given field.
at line 1057
abstract array
fieldList(string $table)
Get a list of all the fields for the given table.
Returns a map of field name => field spec.
at line 1067
boolean
clearCachedFieldlist(string $tableName = null)
This allows the cached values for a table's field list to be erased.
If $tablename is empty, then the whole cache is erased.
at line 1079
abstract string
boolean(array $values)
Returns data type for 'boolean' column
at line 1087
abstract string
date(array $values)
Returns data type for 'date' column
at line 1095
abstract string
decimal(array $values)
Returns data type for 'decimal' column
at line 1103
abstract string
enum(array $values)
Returns data type for 'set' column
at line 1111
abstract string
set(array $values)
Returns data type for 'set' column
at line 1119
abstract string
float(array $values)
Returns data type for 'float' column
at line 1127
abstract string
int(array $values)
Returns data type for 'int' column
at line 1135
abstract string
datetime(array $values)
Returns data type for 'datetime' column
at line 1143
abstract string
text(array $values)
Returns data type for 'text' column
at line 1151
abstract string
time(array $values)
Returns data type for 'time' column
at line 1159
abstract string
varchar(array $values)
Returns data type for 'varchar' column