Install ​
- Type
- Class
- Namespace
- craft\migrations
- Inherits
- craft\migrations\Install » craft\db\Migration » yii\db\Migration » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable, yii\db\MigrationInterface
- Uses traits
- yii\db\SchemaBuilderTrait
- Since
- 3.0.0
Installation Migration
Public Properties ​
Property | Description |
---|---|
applyProjectConfigYaml | boolean – Whether to apply the existing project config YAML files, if they exist |
behaviors | yii\base\Behavior – List of behaviors attached to this component. |
compact | boolean – Indicates whether the console output should be compacted. |
db | craft\db\Connection – the DB connection that this command is associated with |
string, null – The admin user’s email | |
maxSqlOutputLength | integer – Max number of characters of the SQL outputted. |
password | string, null – The admin user’s password |
site | craft\models\Site, null – The default site |
username | string, null – The admin user’s username |
applyProjectConfigYaml
​
- Type
- boolean
- Default value
true
- Since
- 3.5.9
Whether to apply the existing project config YAML files, if they exist
email
​
The admin user’s email
password
​
The admin user’s password
site
​
- Type
- craft\models\Site, null
- Default value
null
The default site
username
​
The admin user’s username
Public Methods ​
Method | Description |
---|---|
__call() | Calls the named method which is not a class method. |
__clone() | This method is called after the object is created by cloning an existing one. |
__construct() | Constructor. |
__get() | Returns the value of a component property. |
__isset() | Checks if a property is set, i.e. defined and not null. |
__set() | Sets the value of a component property. |
__unset() | Sets a component property to be null. |
addCheck() | Creates a SQL command for adding a check constraint to an existing table. |
addColumn() | Builds and executes a SQL statement for adding a new DB column. |
addCommentOnColumn() | Builds and execute a SQL statement for adding comment to column. |
addCommentOnTable() | Builds a SQL statement for adding comment to table. |
addForeignKey() | Builds a SQL statement for adding a foreign key constraint to an existing table. |
addForeignKeys() | Adds the foreign keys. |
addPrimaryKey() | Builds and executes a SQL statement for creating a primary key. |
alterColumn() | Builds and executes a SQL statement for changing the definition of a column. |
archiveTableIfExists() | Creates and executes a SQL statement for renaming a DB table to *_old , if it exists. |
attachBehavior() | Attaches a behavior to this component. |
attachBehaviors() | Attaches a list of behaviors to the component. |
batchInsert() | Creates and executes a batch INSERT SQL statement. |
behaviors() | Returns a list of behaviors that this component should behave as. |
bigInteger() | Creates a bigint column. |
bigPrimaryKey() | Creates a big primary key column. |
binary() | Creates a binary column. |
boolean() | Creates a boolean column. |
canGetProperty() | Returns a value indicating whether a property can be read. |
canSetProperty() | Returns a value indicating whether a property can be set. |
char() | Creates a char column. |
className() | Returns the fully qualified name of this class. |
createIndex() | Builds and executes a SQL statement for creating a new index. |
createIndexIfMissing() | Creates a new index if a similar one doesn’t already exist. |
createIndexes() | Creates the indexes. |
createTable() | Builds and executes a SQL statement for creating a new DB table. |
createTables() | Creates the tables. |
date() | Creates a date column. |
dateTime() | Creates a datetime column. |
decimal() | Creates a decimal column. |
delete() | Creates and executes a DELETE SQL statement. |
deleteDuplicates() | Creates and executes a DELETE SQL statement that will only delete duplicate rows from a table. |
detachBehavior() | Detaches a behavior from the component. |
detachBehaviors() | Detaches all behaviors from the component. |
double() | Creates a double column. |
down() | This method contains the logic to be executed when removing this migration. |
dropAllForeignKeysToTable() | Creates and executes a SQL statement for dropping all foreign keys to a table. |
dropCheck() | Creates a SQL command for dropping a check constraint. |
dropColumn() | Builds and executes a SQL statement for dropping a DB column. |
dropCommentFromColumn() | Builds and execute a SQL statement for dropping comment from column. |
dropCommentFromTable() | Builds a SQL statement for dropping comment from table. |
dropForeignKey() | Builds a SQL statement for dropping a foreign key constraint. |
dropForeignKeyIfExists() | Creates and executes a SQL statement for dropping a foreign key if it exists. |
dropIndex() | Builds and executes a SQL statement for dropping an index. |
dropIndexIfExists() | Creates and executes a SQL statement for dropping an index if it exists. |
dropPrimaryKey() | Builds and executes a SQL statement for dropping a primary key. |
dropTable() | Builds and executes a SQL statement for dropping a DB table. |
dropTableIfExists() | Creates and executes a SQL statement for dropping a DB table, if it exists. |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. |
enum() | Creates an enum column for MySQL and PostgreSQL, or a string column with a check constraint for others. |
execute() | Executes a SQL statement. |
float() | Creates a float column. |
getBehavior() | Returns the named behavior object. |
getBehaviors() | Returns all behaviors attached to this component. |
getDb() | returns the connection the DB connection that this command is associated with |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. |
hasMethod() | Returns a value indicating whether a method is defined. |
hasProperty() | Returns a value indicating whether a property is defined for this component. |
init() | Initializes the migration. |
insert() | Creates and executes an INSERT SQL statement. |
insertDefaultData() | Populates the DB with the default data. |
integer() | Creates an integer column. |
json() | Creates a JSON column. |
longText() | Creates a longtext column for MySQL, or text column for others. |
mediumText() | Creates a mediumtext column for MySQL, or text column for others. |
money() | Creates a money column. |
off() | Detaches an existing event handler from this component. |
on() | Attaches an event handler to an event. |
primaryKey() | Creates a primary key column. |
renameColumn() | Builds and executes a SQL statement for renaming a column. |
renameSequence() | Creates and executes a SQL statement for renaming a DB sequence. |
renameTable() | Builds and executes a SQL statement for renaming a DB table and its corresponding sequence (if PostgreSQL). |
replace() | Creates and executes a SQL statement for replacing some text with other text in a given table column. |
restore() | Creates and executes a SQL statement for restoring a soft-deleted row. |
safeDown() | This method contains the logic to be executed when removing this migration. |
safeUp() | This method contains the logic to be executed when applying this migration. |
smallInteger() | Creates a smallint column. |
softDelete() | Creates and executes a SQL statement for soft-deleting a row. |
string() | Creates a string column. |
text() | Creates a text column. |
time() | Creates a time column. |
timestamp() | Creates a timestamp column. |
tinyInteger() | Creates a tinyint column. If tinyint is not supported by the DBMS, smallint will be used. |
tinyText() | Creates a tinytext column for MySQL, or text column for others. |
trigger() | Triggers an event. |
truncateTable() | Builds and executes a SQL statement for truncating a DB table. |
uid() | Shortcut for creating a uid column |
up() | This method contains the logic to be executed when applying this migration. |
update() | Creates and executes an UPDATE SQL statement. |
upsert() | Creates and executes a command to insert rows into a database table if they do not already exist (matching unique constraints), or update them if they do. |
addForeignKeys()
​
Adds the foreign keys.
createIndexes()
​
Creates the indexes.
createTables()
​
Creates the tables.
insertDefaultData()
​
Populates the DB with the default data.
safeDown()
​
This method contains the logic to be executed when removing this migration.
This method differs from down() in that the DB logic implemented here will be enclosed within a DB transaction. Child classes may implement this method instead of down() if the DB logic needs to be within a transaction.
Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples, please refer to implicit commit.
Returns ​
false, void
, mixed
– Return a false value to indicate the migration fails and should not proceed further. All other return values mean the migration succeeds.
safeUp()
​
This method contains the logic to be executed when applying this migration.
This method differs from up() in that the DB logic implemented here will be enclosed within a DB transaction. Child classes may implement this method instead of up() if the DB logic needs to be within a transaction.
Note: Not all DBMS support transactions. And some DB queries cannot be put into a transaction. For some examples, please refer to implicit commit.
Returns ​
false, void
, mixed
– Return a false value to indicate the migration fails and should not proceed further. All other return values mean the migration succeeds.
Protected Methods ​
Method | Description |
---|---|
afterDown() | This method contains the logic to be executed after removing this migration. |
afterUp() | This method contains the logic to be executed after applying this migration. |
beginCommand() | Prepares for a command to be executed, and outputs to the console. |
endCommand() | Finalizes after the command has been executed, and outputs to the console the time elapsed. |
afterUp()
​
- Since
- 5.3.2
This method contains the logic to be executed after applying this migration.