@@ -55,55 +55,55 @@ The following skeleton shows a typical migration file. All migrations are
```js
module.exports={
up:function(migration,DataTypes){
up:function(queryInterface,Sequelize){
// logic for transforming into the new state
},
down:function(migration,DataTypes){
down:function(queryInterface,Sequelize){
// logic for reverting the changes
}
}
```
The passed `migration` object can be used to modify the database. The `DataTypes` object stores the available data types such as `STRING` or `INTEGER`. The third parameter is a callback function which needs to be called once everything was executed. The first parameter of the callback function can be used to pass a possible error. In that case, the migration will be marked as failed. Here is some code:
The passed `queryInterface` object can be used to modify the database. The `Sequelize` object stores the available data types such as `STRING` or `INTEGER`. The third parameter is a callback function which needs to be called once everything was executed. The first parameter of the callback function can be used to pass a possible error. In that case, the migration will be marked as failed. Here is some code:
```js
module.exports={
up:function(migration,DataTypes){
returnmigration.dropAllTables();
up:function(queryInterface,Sequelize){
returnqueryInterface.dropAllTables();
}
}
```
The available methods of the migration object are the following.
The available methods of the queryInterface object are the following.
## Functions
Using the `migration` object describe before, you will have access to most of already introduced functions. Furthermore there are some other methods, which are designed to actually change the database schema.
Using the `queryInterface` object describe before, you will have access to most of already introduced functions. Furthermore there are some other methods, which are designed to actually change the database schema.
This method allows creation of new tables. It is allowed to pass simple or complex attribute definitions. You can define the encoding of the table and the table's engine via options
```js
migration.createTable(
queryInterface.createTable(
'nameOfTheNewTable',
{
id:{
type:DataTypes.INTEGER,
type:Sequelize.INTEGER,
primaryKey:true,
autoIncrement:true
},
createdAt:{
type:DataTypes.DATE
type:Sequelize.DATE
},
updatedAt:{
type:DataTypes.DATE
type:Sequelize.DATE
},
attr1:DataTypes.STRING,
attr2:DataTypes.INTEGER,
attr1:Sequelize.STRING,
attr2:Sequelize.INTEGER,
attr3:{
type:DataTypes.BOOLEAN,
type:Sequelize.BOOLEAN,
defaultValue:false,
allowNull:false
}
...
...
@@ -120,7 +120,7 @@ migration.createTable(
This method allows deletion of an existing table.
This method changes the meta data of an attribute. It is possible to change the default value, allowance of null or the data type. Please make sure, that you are completely describing the new data type. Missing information are expected to be defaults.