CRM_Extension_Upgrader_SchemaTrait
(Semi-Deprecated) The SchemaTrait provides utilities for altering tables during an upgrade.
It may be useful for some niche refactorings, but it is not recommended for new code/functionality.
For new code, use E::schema() (aka SchemaHelper.php).
SchemaTrait and E::schema() both provide a list of helper functions, but E::schema()
is more adaptable:
E::schema()can be called in more ways. It can be called by full-size Upgrader classes, by standalone lifecycle-hooks, and/or by sysadmin scripts [cv].E::schema()is amenable to backports.civix upgradecan give you a new version ofE::schema()even if the extension targets older<ver>sions of CiviCRM.
SchemaTrait may have some niche uses when refactoring CRM_Extension_Upgrader_Base (or a
comparable class). This kind of use-case should be extremely rare.
Table of Contents
Methods
- addColumn() : bool
- Add a column to a table if it doesn't already exist
- addIndex() : bool
- Add an index to one or more columns.
- dropColumn() : bool
- Drop a column from a table if it exists.
- dropIndex() : bool
- Drop index from a table if it exists.
Methods
addColumn()
Add a column to a table if it doesn't already exist
public
static addColumn(string $table, string $column, string $properties) : bool
Parameters
- $table : string
- $column : string
- $properties : string
Return values
booladdIndex()
Add an index to one or more columns.
public
static addIndex(string $table, string|array<string|int, mixed> $columns[, string $prefix = 'index' ]) : bool
Parameters
- $table : string
- $columns : string|array<string|int, mixed>
- $prefix : string = 'index'
Return values
booldropColumn()
Drop a column from a table if it exists.
public
static dropColumn(string $table, string $column) : bool
Parameters
- $table : string
- $column : string
Return values
booldropIndex()
Drop index from a table if it exists.
public
static dropIndex(string $table, string $indexName) : bool
Parameters
- $table : string
- $indexName : string