PostgreSQLSchemaManager
class PostgreSQLSchemaManager extends DBSchemaManager (View source)
PostgreSQL schema manager
Constants
ID |
Identifier for this schema, used for configuring schema-specific table
creation options |
Properties
protected | PostgreSQLDatabase | $database | Instance of the database controller this schema belongs to |
|
protected | bool | $supressOutput | If this is false, then information about database operations will be displayed, eg creation of tables. |
from DBSchemaManager |
protected | array | $tableList | The table list, generated by the tableList() function. |
from DBSchemaManager |
protected | bool | $schemaIsUpdating | Keeps track whether we are currently updating the schema. |
from DBSchemaManager |
protected | array | $schemaUpdateTransaction | Large array structure that represents a schema update transaction |
from DBSchemaManager |
protected static | array | $cached_constraints | This holds a copy of all the constraint results that are returned via the function constraintExists(). This is a bit faster than repeatedly querying this column, and should allow the database to use it's built-in caching features for better queries. |
|
protected static | array | $cached_fieldlists | This holds a copy of all the queries that run through the function fieldList() This is one of the most-often called functions, and repeats itself a great deal in the unit tests. |
Methods
Execute the given SQL query.
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 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
Handler for the other transXXX methods - mark the given table as being altered if it doesn't already exist
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.
Splits a spec string safely, considering quoted columns, whitespace, and cleaning brackets
Builds a properly quoted column list from an array
Given an index specification in the form of a string ensure that each column name is property quoted, stripping brackets and modifiers.
Given an index spec determines the index type
Converts an array or string index spec into a universally useful array
This takes the index spec which has been provided by a class (ie static $indexes = blah blah) and turns it into a proper string.
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.
Returns the values of the given enum field
Alter an index on a table.
Determines the key that should be used to identify this index when retrieved from DBSchemaManager->indexList.
Create a new table.
Alter a table's schema.
Change the database column name of the given field.
This allows the cached values for a table's field list to be erased.
Creates a postgres database, ignoring model_schema_as_database
Determines if a postgres database exists, ignoring model_schema_as_database
Determines the list of all postgres databases, ignoring model_schema_as_database
Drops a postgres database, ignoring model_schema_as_database
Builds the internal Postgres index name given the silverstripe table and index name
Builds the internal Postgres trigger name given the silverstripe table and trigger name
Change the database type of the given field.
Create an index on a table.
No description
Given a trigger name attempt to determine the columns upon which it acts
Find out what the constraint information is, given a constraint name.
A function to return the field names and datatypes for the particular table
Pass a legit trigger name and it will be dropped This assumes that the trigger has been named in a unique fashion
This will return the fields that the trigger is monitoring
Return a boolean type-formatted string
Return a decimal type-formatted string
Return a float type-formatted string cause double is not supported
Return a datetime type-formatted string For PostgreSQL, we simply return the word 'timestamp', no other parameters are necessary
Return a varchar type-formatted string
Create a fulltext search datatype for PostgreSQL This will also return a trigger to be applied to this table
Get the actual enum fields from the constraint value:
No description
Return a set type-formatted string This is used for Multi-enum support, which isn't actually supported by Postgres.
Details
setDatabase(SS_Database $database)
Injector injection point for database controller
quiet()
Enable supression of database messages.
SS_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.
SS_Query
preparedQuery(string $sql, array $parameters, int $errorLevel = E_USER_ERROR)
Execute the given SQL parameterised query with the specified arguments
schemaUpdate($callback)
Initiates a schema update within a single callback
cancelSchemaUpdate()
Cancels the schema updates requested during (but not after) schemaUpdate() call.
bool
isSchemaUpdating()
Returns true if we are during a schema update.
bool
doesSchemaNeedUpdating()
Returns true if schema modifications were requested during (but not after) schemaUpdate() call.
transCreateTable(string $table, array $options = null, array $advanced_options = null)
Instruct the schema manager to record a table creation to later execute
transAlterTable(string $table, array $options, array $advanced_options)
Instruct the schema manager to record a table alteration to later execute
transCreateField(string $table, string $field, string $schema)
Instruct the schema manager to record a field to be later created
transCreateIndex(string $table, string $index, array $schema)
Instruct the schema manager to record an index to be later created
transAlterField(string $table, string $field, string $schema)
Instruct the schema manager to record a field to be later updated
transAlterIndex(string $table, string $index, array $schema)
Instruct the schema manager to record an index to be later updated
protected
transInitTable(string $table)
Handler for the other transXXX methods - mark the given table as being altered if it doesn't already exist
requireTable(string $table, array $fieldSchema = null, array $indexSchema = null, bool $hasAutoIncPK = true, string $options = array(), array $extensions = false)
Generate the following table in the database, modifying whatever already exists as necessary.
dontRequireTable(string $table)
If the given table exists, move it out of the way by renaming it to obsolete(tablename).
requireIndex(string $table, string $index, string|array|bool $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.
protected array
explodeColumnString(string $spec)
Splits a spec string safely, considering quoted columns, whitespace, and cleaning brackets
protected string
implodeColumnList(array $columns)
Builds a properly quoted column list from an array
protected string
quoteColumnSpecString(string $spec)
Given an index specification in the form of a string ensure that each column name is property quoted, stripping brackets and modifiers.
This index may also be in the form of a "CREATE INDEX..." sql fragment
protected string
determineIndexType(array|string $spec)
Given an index spec determines the index type
protected array
parseIndexSpec($name, string|array $spec)
Converts an array or string index spec into a universally useful array
protected
convertIndexSpec(string|array $indexSpec)
This takes the index spec which has been provided by a class (ie static $indexes = blah blah) and turns it into a proper string.
Some indexes may be arrays, such as fulltext and unique indexes, and this allows database-specific arrays to be created. See requireTable() for details on the index format.
bool
hasTable($tableName)
Returns true if the given table is exists in the current database
bool
hasField(string $tableName, string $fieldName)
Return true if the table exists and already has a the field specified
requireField(string $table, string $field, array|string $spec)
Generate the given field on the table, modifying whatever already exists as necessary.
dontRequireField(string $table, string $fieldName)
If the given field exists, move it out of the way by renaming it to obsolete(fieldname).
alterationMessage(string $message, string $type = "")
Show a message about database alteration
string
IdColumn(bool $asDbValue = false, bool $hasAutoIncPK = true)
This returns the data type for the id column which is the primary key for each table
bool
checkAndRepairTable(string $tableName)
Checks a table's integrity and repairs it if necessary.
array
enumValuesForField(string $tableName, string $fieldName)
Returns the values of the given enum field
dbDataType($type)
No description
array
databaseList()
Retrieves the list of all databases the user has access to
bool
databaseExists(string $name)
Determine if the database with the specified name exists
bool
createDatabase(string $name)
Create a database with the specified name
dropDatabase(string $name)
Drops a database with the specified name
alterIndex(string $tableName, string $indexName, string $indexSpec)
Alter an index on a table.
protected string
indexKey(string $table, string $index, array $spec)
Determines the key that should be used to identify this index when retrieved from DBSchemaManager->indexList.
In some connectors this is the database-visible name, in others the usercode-visible name.
indexList(string $table)
Return the list of indexes in a table.
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.
string
createTable(string $table, array $fields = null, array $indexes = null, array $options = null, $advancedOptions = null)
Create a new table.
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.
renameTable(string $oldTableName, string $newTableName)
Rename a table.
createField(string $table, string $field, string $spec)
Create a new field on a table.
renameField(string $tableName, string $oldName, string $newName)
Change the database column name of the given field.
array
fieldList(string $table)
Get a list of all the fields for the given table.
Returns a map of field name => field spec.
bool
clearCachedFieldlist(string $tableName = false)
This allows the cached values for a table's field list to be erased.
If $tablename is empty, then the whole cache is erased.
createPostgresDatabase(string $name)
Creates a postgres database, ignoring model_schema_as_database
bool
postgresDatabaseExists(string $name)
Determines if a postgres database exists, ignoring model_schema_as_database
array
postgresDatabaseList()
Determines the list of all postgres databases, ignoring model_schema_as_database
dropPostgresDatabase(string $name)
Drops a postgres database, ignoring model_schema_as_database
bool
schemaExists(string $name)
Returns true if the schema exists in the current database
createSchema(string $name)
Creates a schema in the current database
dropSchema(string $name)
Drops a schema from the database. Use carefully!
array
schemaList()
Returns the list of all available schemas on the current database
protected string
buildPostgresIndexName(string $tableName, string $indexName, string $prefix = 'ix')
Builds the internal Postgres index name given the silverstripe table and index name
string
buildPostgresTriggerName(string $tableName, string $triggerName)
Builds the internal Postgres trigger name given the silverstripe table and trigger name
alterField(string $tableName, string $fieldName, string $fieldSpec)
Change the database type of the given field.
createIndex(string $tableName, string $indexName, string $indexSpec)
Create an index on a table.
protected
getIndexSqlDefinition($tableName, $indexName, $indexSpec, $asDbValue = false)
No description
protected array
extractTriggerColumns(string $triggerName)
Given a trigger name attempt to determine the columns upon which it acts
protected false|array
constraintExists(string $constraint, bool $cache = true)
Find out what the constraint information is, given a constraint name.
We also cache this result, so the next time we don't need to do a query all over again.
array
tableDetails(string $tableName)
A function to return the field names and datatypes for the particular table
protected
dropTrigger(string $triggerName, string $tableName)
Pass a legit trigger name and it will be dropped This assumes that the trigger has been named in a unique fashion
protected array
triggerFieldsFromTrigger(string $trigger)
This will return the fields that the trigger is monitoring
string
boolean(array $values, bool $asDbValue = false)
Return a boolean type-formatted string
string
date(array $values)
Return a date type-formatted string
string
decimal(array $values, bool $asDbValue = false)
Return a decimal type-formatted string
string
enum(array $values)
Return a enum type-formatted string
string
float(array $values, bool $asDbValue = false)
Return a float type-formatted string
string
double(array $values, bool $asDbValue = false)
Return a float type-formatted string cause double is not supported
string
int(array $values, bool $asDbValue = false)
Return a int type-formatted string
string
bigint(array $values, bool $asDbValue = false)
Return a bigint type-formatted string
string
SS_Datetime(array $values, bool $asDbValue = false)
Return a datetime type-formatted string For PostgreSQL, we simply return the word 'timestamp', no other parameters are necessary
string
text(array $values, bool $asDbValue = false)
Return a text type-formatted string
string
time(array $values)
Return a time type-formatted string
string
varchar(array $values, bool $asDbValue = false)
Return a varchar type-formatted string
year($values, $asDbValue = false)
No description
protected
fulltext(array $this_index, string $tableName, string $name)
Create a fulltext search datatype for PostgreSQL This will also return a trigger to be applied to this table
protected array
enumValuesFromConstraint(string $constraint)
Get the actual enum fields from the constraint value:
createOrReplaceTablespace($name, $location)
No description
createOrReplacePartition(string $tableName, array $partitions, array $indexes, array $extensions)
No description
createLanguage($language)
No description
string
set(array $values)
Return a set type-formatted string This is used for Multi-enum support, which isn't actually supported by Postgres.
Throws a user error to show our lack of support, and return an "int", specifically for sapphire tests that test multi-enums. This results in a test failure, but not crashing the test run.