\Migration
All migrations that must be executed must be descended from this class and define both an ->up() and a ->down() method. Migrations will be executed in alphanumeric order
- Author: Patrick Nelson, pat@catchyour.com
Synopsis
class Migration
implements
MigrationInterface
{
- // members
- protected boolean $obsolete = false;
- // methods
- public abstract void up()
- public abstract void down()
- public bool isObsolete()
- public static bool tableExists()
- public static bool tableColumnExists()
- public static bool tableColumnsExist()
- public static array getTableColumns()
- public static string getTableForField()
- public static array dropColumnsFromTable()
- public static array addColumnsToTable()
- public static string getRowValueFromTable()
- public static array getRowValuesFromTable()
- public static bool setRowValuesOnTable()
- public static void publish()
- public static void unpublish()
- protected static void whileAdmin()
- protected static void loginAsAdmin()
- public static void setPageType()
- public static void transitionField()
- public static void copyTable()
- public static void copyVersionedTable()
Hierarchy
Implements
Tasks
Line | Task |
---|---|
222 | This should maybe throw an exception instead. |
449 | Should this be optional? |
Members
protected
- $obsolete
Methods
protected
- loginAsAdmin() — Ensures we have permissions to manipulate pages (gets around access issues with global state). Unfortunately, the creation of a default admin account below is necessary because SilverStripe will reference global state via Member::currentUser() and the only surefire way around this is to login as a default admin with full access.
- whileAdmin() — The intent with this function is to allow it to maintain it's own state while allowing you to execute your own arbitrary code within that state (i.e. while logged in as an administrator).
public
- addColumnsToTable() — Add columns to a database table if they don't exist.
- copyTable() — Copies all values from one table to another. Will override any existing values with matching ID's.
- copyVersionedTable() — Same exact purpose as ::copyTable(), however, also applies changes to other tables associated with versioned objects. Also, this could be potentially much slower due to the extra tables being copied.
- down()
- dropColumnsFromTable() — Drops columns from a database table.
- getRowValueFromTable() — Gets the value for a single column in a row from the database by the ID column.
- getRowValuesFromTable() — Gets the values for multiple rows on a database table by the ID column.
- getTableColumns() — Returns an array of columns for a database table
- getTableForField() — Allows to you fetch the specific table (and thus DataObject) that a particular field exists on, since they're merged at runtime. This will actually iterate through the class ancestry in order to determine the table in which a field actually exists.
- isObsolete() — Indicates that the migration is no longer relevant or able to be run from scratch due to backward incompatibilities, which may occur as the codebase changes over time. Useful when wanting to retain old migration files for reference purposes and consistency.
- publish() — Simplifies publishing of an actual page instance (since migrations are run from command line).
- setPageType() — Shorthand to make it easier to update the page type, since SilverStripe has a very specific method for accomplishing this.
- setRowValuesOnTable() — Sets the values for multiple rows on a database table by the ID column.
- tableColumnExists() — Returns true if a column exists in a database table
- tableColumnsExist() — Returns true if an array of columns exist on a database table
- tableExists() — Returns true if the table exists in the database
- transitionField() — Allows you to easily transition data from one field name to the next. Works with generic data objects as well as instances of the SiteTree.
- unpublish() — Simplifies UN-publishing of an actual page instance (since migrations are run from command line).
- up()