Set one-to-one association in sequelize - mysql

I am trying to get a single one-to-one association. This is my code:
Provider code
const Provider = sequelize.define("provider", {
idProvider: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true,
},
idUser: {
type: Sequelize.INTEGER,
primaryKey: true,
//unique: true,
},
isPublicProvider: {
type: Sequelize.BOOLEAN,
},
});
Provider.associate = function (models) {
Provider.hasOne(models.user, {
through: "users",
as: "idUser",
foreignKey: "idUser",
onDelete: "CASCADE",
});
};
In the association part, I have to get one IdUser only from this table
User code
const User = sequelize.define("user", {
idUser: {
type: Sequelize.INTEGER,
autoIncrement: true,
unique: true,
primaryKey: true,
},
nameUser: {
type: Sequelize.STRING,
validate: { notEmpty: true },
},
emailUser: {
type: Sequelize.STRING,
unique: true,
validate: { isEmail: true },
},
activeUser: {
type: Sequelize.BOOLEAN,
},
});
User.associate = (model) => {
User.belongsTo(models.Group, {
through: "providers",
as: "idUser",
foreignKey: "idUser",
});
};
When I check the ERR model, there is no relation between
[This is a image from my diagram] https://i.stack.imgur.com/bWqOo.png
Thanks to all before answer :)

Related

i am a fresher i need help on nodejs

i have three tables (questions , options , answers)
in these three table parent model is questions and then child is options and answers
so, i want to delete child data also calling by parent id
Here is questions models
import Sequelize from "sequelize";
import Exam from "../../models/exam.js";
import sequelize from "../../utilities/database.js";
const Question = sequelize.define("question", {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
allowNull: false,
primaryKey: true,
},
questiontext: {
type: Sequelize.STRING,
allowNull: true,
},
questiontexthindi: {
type: Sequelize.STRING,
allowNull: true,
},
questionImgURL: {
type: Sequelize.STRING,
allowNull: true,
},
description: {
type: Sequelize.TEXT,
allowNull: true,
},
examId: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: Exam,
key: "id",
},
},
isActive: {
type: Sequelize.BOOLEAN,
defaultValue: true,
},
});
export default Question;
options models
import Sequelize from "sequelize";
import sequelize from "../../utilities/database.js";
import Question from "./question.js";
const Option = sequelize.define("option", {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
allowNull: false,
primaryKey: true,
},
optiontext: {
type: Sequelize.STRING,
// (Sequelize.STRING),
allowNull: false,
isLength: [2, 6],
},
questionId: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: Question,
key: "id",
onDelete: "CASCADE",
},
},
isActive: {
type: Sequelize.BOOLEAN,
defaultValue: true,
},
});
export default Option;
Here is answers models
import Sequelize from "sequelize";
import sequelize from "../../utilities/database.js";
import Question from "./question.js";
import Option from "./option.js";
const Answer = sequelize.define("answer", {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
allowNull: false,
primaryKey: true,
},
questionId: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: Question,
key: "id",
onDelete: "CASCADE",
},
},
optionId: {
type: Sequelize.INTEGER,
allowNull: true,
references: {
model: Option,
key: "id",
},
},
correctanswer: {
type: Sequelize.STRING,
allowNull: false,
},
isActive: {
type: Sequelize.BOOLEAN,
defaultValue: true,
},
});
export default Answer;
Here is my controller
//models
import Question from "../../../models/model-tesportal/option.js";
//helpers
import { validationErrorHandler } from "../../../helpers/validation-error-handler.js";
export const deleteTestSeries = async (req, res, next) => {
validationErrorHandler(req, next);
const questionId = req.params.questionId;
try {
const result = await Question.destroy({
where: {
questionId: questionId,
},
});
if (result[0] === 0) {
const error = new Error("Question not found");
error.statusCode = 404;
return next(error);
}
res.status(201).json({
message: "Question Deleted successfully",
});
} catch (err) {
if (!err.statusCode) {
err.statusCode = 500;
}
next(err);
}
};
i want to pass questionId in params and then delete data of that particular questionId will be deleted from parent and child tables
I got the solution from #geeks for geeks
i have to modify in my models where i wanna access those reference key Id
just look at my models now it works perfectly :
here is questions model {parent}
import Sequelize from "sequelize";
import Exam from "../../models/exam.js";
import sequelize from "../../utilities/database.js";
const Question = sequelize.define("question", {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
allowNull: false,
primaryKey: "id", **<----- modify here**
},
questiontext: {
type: Sequelize.STRING,
allowNull: true,
},
questiontexthindi: {
type: Sequelize.STRING,
allowNull: true,
},
questionImgURL: {
type: Sequelize.STRING,
allowNull: true,
},
description: {
type: Sequelize.TEXT,
allowNull: true,
},
examId: {
type: Sequelize.INTEGER,
allowNull: false,
references: {
model: Exam,
key: "id",
},
},
isActive: {
type: Sequelize.BOOLEAN,
defaultValue: true,
},
});
export default Question;
child - options model
import Sequelize from "sequelize";
import sequelize from "../../utilities/database.js";
import Question from "./question.js";
const Option = sequelize.define("option", {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
allowNull: false,
primaryKey: true,
},
optiontext: {
type: Sequelize.STRING,
// (Sequelize.STRING),
allowNull: false,
isLength: [2, 6],
},
questionId: {
type: Sequelize.INTEGER,
allowNull: false,
onDelete: "CASCADE", **<----- modify here**
references: {
model: Question,
key: "id",
FOREIGNKEY: "id", **<----- modify here**
},
},
isActive: {
type: Sequelize.BOOLEAN,
defaultValue: true,
},
});
export default Option;
child - answers models
import Sequelize from "sequelize";
import sequelize from "../../utilities/database.js";
import Question from "./question.js";
import Option from "./option.js";
const Answer = sequelize.define("answer", {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
allowNull: false,
primaryKey: true,
},
questionId: {
type: Sequelize.INTEGER,
allowNull: false,
onDelete: "CASCADE", **<----- modify here**
references: {
model: Question,
key: "id",
FOREIGNKEY: "id", **<----- modify here**
},
},
optionId: {
type: Sequelize.INTEGER,
allowNull: true,
references: {
model: Option,
key: "id",
},
},
correctanswer: {
type: Sequelize.STRING,
allowNull: false,
},
isActive: {
type: Sequelize.BOOLEAN,
defaultValue: true,
},
});
export default Answer;
main code controller
//models
import Question from "../../../models/model-tesportal/question.js";
//helpers
import { validationErrorHandler } from "../../../helpers/validation-error-handler.js";
export const deleteTestSeries = async (req, res, next) => {
validationErrorHandler(req, next);
try {
const result = await Question.destroy({
where: {
id: req.params.questionId,
},
});
if (result[0] === 0) {
const error = new Error("Question not found");
error.statusCode = 404;
return next(error);
}
res.status(201).json({
message: "Hey Admin Question Deleted successfully",
});
} catch (err) {
if (!err.statusCode) {
err.statusCode = 500;
}
next(err);
}
};

Trying to join parent / primary table to child / foreign table in sequelize

I'm trying to get all my articles data from articles table but also user data from users table i've made. I using sequelize to build database to MySQL database and also as a ORM, here's the snippet code
USER TABLE
const User = sequelize.define('users', ({
id: {
type: DataTypes.BIGINT,
primaryKey: true,
autoIncrement: true,
allowNull: false,
},
nama: {
type: DataTypes.STRING(50),
allowNull: false,
},
email: {
type: DataTypes.STRING(50),
allowNull: false,
},
password: {
type: DataTypes.STRING(50),
allowNull: false,
}
}))
ARTICLES CODE
const Articles = sequelize.define('articles', ({
id: {
type: DataTypes.BIGINT,
primaryKey: true,
autoIncrement: true,
allowNull: false,
},
title: {
type: DataTypes.STRING,
allowNull: false,
},
description: {
type: DataTypes.TEXT,
allowNull: false
},
gambar: {
type: DataTypes.STRING,
allowNull: false
},
userId: {
type: DataTypes.BIGINT,
allowNull: false,
}
}))
the relation
User.hasMany(Articles, {
onDelete: 'CASCADE',
onUpdate: 'CASCADE',
})
Articles.belongsTo(User, {
foreignKey: 'userId'
})
the ORM i've try
Articles.findAll({
include: [User]
})
it is always return that users table is not associated to artiles
You have to use as key word during creating relation ship.
Articles.belongsTo(User, {
as: 'user',
foreignKey: 'userId'
})
and then update form
Articles.findAll({include: [{
model: model.User,
as: 'user'
}]})

Obtaining key from Join Table in a Sequelize include

I'm working in Node JS and Sequelize/MySQL. I have two tables Agent and Neighborhood as well as a join table AgentNeighborhood. I'd like, when querying these tables to obtain the join table key.
AgentNeighborhood
const AgentNeighborhood = sequelize.define('agentneighborhood', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false
},
agent_id: {
type: DataTypes.INTEGER,
required: true,
references: {
model: 'Agent',
key: 'id'
},
allowNull: false
},
neighborhood_id: {
type: DataTypes.INTEGER,
required: true,
references: {
model: 'Neighborhood',
key: 'id'
},
allowNull: false
},
},
{
freezeTableName: true,
underscore: true
})
Neighborhood
const Neighborhood = sequelize.define('neighborhood', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
},
...
...
},
{
freezeTableName: true,
})
Neighborhood.associate = (models) => {
Neighborhood.belongsToMany(models.agent, { through: 'agentneighborhood', foreignKey: 'neighborhood_id' })
}
Agent
const Agent = sequelize.define('agent', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false
},
....
},
{
freezeTableName: true,
})
Agent.associate = (models) => {
Agent.belongsToMany(models.neighborhood, { through: 'agentneighborhood', foreignKey: 'agent_id' })
}
How can I query the keys so that my result will be as follows ?
{
id // the primary key for the AgentNeighborhood table
agent_id
agent {
id // should be same as agent_id
...
}
neighborhood_id
neighborhood {
id // should be same as neighborhood_id
...
}
}
I tried the following but get an error that neighborhood is not associated to agentneighborhood.
const agentneighborhoods = await models.agentneighborhood.findAll({where: {agent_id: 1}, include: [
{model: models.neighborhood},
{model: models.agent},
]})
return agentneighborhoods
You need to get list of neighbors associated with that agent_id.
const agentneighborhoods= await models.neighbors.findAll({
where: { "$agentneighborhood.agent_id$": agent_id },
include: [
{
as: "agentneighborhood",
model: models.agentneighborhood,
required: true
}
]
});
return agentneighborhoods

Sequelize belongsToMany not working

Here is my problem:
Table WO -> sparepart_request -> sparepart.
A work order have several sparepart and sparepart can belong to several WO.
This is my code in wo.js (sequelize model)
models.sparepart.belongsToMany(models.wo, { as: 'SPWO', through: 'sparepart_request', foreignKey: 'codSparePart' });
This is my code in sparepart.js (sequelize model).
models.sparepart.belongsToMany(models.wo, { as: 'SPWO', through: 'sparepart_request', foreignKey: 'codSparePart' });
In sparepart_request there is nothing about associations. I've followed the next instructions Sequelize
In my query I have the next code:
exports.readDetailWO = function (req, res) {
models.wo.findAll({
attributes: ['codWO'], // attributes: ['id', 'codWO', 'codSparePart', 'quantity', 'date_request', 'date_reception', 'details', 'codUser', 'received'],
raw: true,
where: {
codWO: req.params.codWO
},
include: [{
model: models.sparepart,
attributes: ['codSparePart', 'name', 'description', 'codManufacturer', 'image_uri', 'stock'],
paranoid: false,
required: false,
as: 'SPWO'
}]
}).then(sparePart => {
if (!sparePart) {
res.status(404);
res.send({
success: false,
message: 'Spare Part not found. ' + req.params.codWO,
data: sparePart
});
} else if (sparePart) {
res.json({
success: true,
message: 'Spare Part found.',
data: sparePart
});
}
}).catch(function (error) {
logger.error(JSON.stringify(error));
res.json({
message: 'Query not successful and error has occured reading',
error: error,
stackError: error.stack
});
return res.status(500);
});
};
But the server's response (using PostMan) is the following:
{
"message": "Query not successful and error has occured reading",
"error": {
"name": "SequelizeEagerLoadingError"
},
"stackError": "SequelizeEagerLoadingError: sparepart is not associated to wo!\n
AS I have been able to read here that maybe the problem that is my primaryKeys are not name id, but now I can change these names...
Where is the problem? Thanks in advance for your help.
Model sparepart_request.js
module.exports = function (sequelize, DataTypes) {
var sparepart_request = sequelize.define('sparepart_request', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
codWo: {
type: DataTypes.STRING(20),
allowNull: false,
foreignKey: {
model: 'wo',
key: 'codWO'
}
},
codSparePart: {
type: DataTypes.STRING(30),
allowNull: false,
references: {
model: 'sparepart',
key: 'codSparePart'
}
},
quantity: {
type: DataTypes.FLOAT,
allowNull: true
},
date_request: {
type: DataTypes.DATEONLY,
allowNull: true
},
date_reception: {
type: DataTypes.DATEONLY,
allowNull: true
},
details: {
type: DataTypes.TEXT,
allowNull: true
},
codUser: {
type: DataTypes.STRING(20),
allowNull: false,
references: {
model: 'user',
key: 'codUser'
}
},
received: {
type: DataTypes.INTEGER(1),
allowNull: false
}
}, {
tableName: 'sparepart_request',
timestamps: false
});
/* sparepart_request.associate = function (models) {
models.sparepart_request.hasMany(models.sparepart, {foreignKey: 'codSparePart', targetKey: 'codSparePart'});
}; */
return sparepart_request;
};
Model wo.js:
/* jshint indent: 1 */
module.exports = function (sequelize, DataTypes) {
var wo = sequelize.define('wo', {
codWO: {
type: DataTypes.STRING(20),
allowNull: false,
primaryKey: true
},
codUser: {
type: DataTypes.STRING(20),
allowNull: false,
references: {
model: 'user',
key: 'codUser'
}
},
codOriginator: {
type: DataTypes.STRING(20),
allowNull: true,
references: {
model: 'user',
key: 'codUser'
}
},
capture_date: {
type: DataTypes.DATE,
allowNull: false
},
active: {
type: DataTypes.INTEGER(1),
allowNull: false
},
codType: {
type: DataTypes.CHAR(3),
allowNull: false,
references: {
model: 'type',
key: 'codType'
}
},
date: {
type: DataTypes.DATEONLY,
allowNull: false
},
title: {
type: DataTypes.STRING(255),
allowNull: true
},
date_finish: {
type: DataTypes.DATEONLY,
allowNull: true
},
codStatus: {
type: DataTypes.STRING(10),
allowNull: false,
references: {
model: 'status',
key: 'codStatus'
}
},
hours_planned: {
type: DataTypes.FLOAT,
allowNull: true
},
codElement: {
type: DataTypes.INTEGER(11),
allowNull: true,
references: {
model: 'element',
key: 'codElement'
}
},
Security: {
type: DataTypes.INTEGER(1),
allowNull: true,
defaultValue: '0'
},
codEquipment: {
type: DataTypes.STRING(20),
allowNull: false,
references: {
model: 'equipment',
key: 'codEquipment'
}
},
codProject: {
type: DataTypes.INTEGER(11),
allowNull: false,
references: {
model: 'project',
key: 'id'
}
},
codTestRoom: {
type: DataTypes.STRING(10),
allowNull: false,
references: {
model: 'testroom',
key: 'codTestRoom'
}
}
}, {
tableName: 'wo',
timestamps: false
});
wo.associate = function (models) {
models.wo.belongsTo(models.wo_operation, {
as: 'wo_operation',
foreignKey: {
name: 'codWO',
allowNull: false
},
targetKey: 'codWO'
});
models.wo.belongsTo(models.dailyinfo_detail, {
as: 'dailyInfo',
foreignKey: {
name: 'codWO',
allowNull: false
},
targetKey: 'codWO'
});
models.wo.hasOne(models.wo_corrective, {
as: 'wo_corrective',
foreignKey: {
name: 'codWO',
allowNull: false
},
targetKey: 'codWO'
});
models.wo.hasOne(models.wo_preventive, {
as: 'wo_preventive',
foreignKey: {
name: 'codWO',
allowNull: false
},
targetKey: 'codWO'
});
models.wo.belongsToMany(models.sparepart_request, { as: 'WOSP', through: 'sparepart_request', foreignKey: 'codWO', otherKey: 'codSparePart' });
};
return wo;
};
Model sparepart.js
/* jshint indent: 1 */
module.exports = function (sequelize, DataTypes) {
var sparepart = sequelize.define('sparepart', {
codSparePart: {
type: DataTypes.STRING(30),
allowNull: false,
primaryKey: true,
references: {
model: 'sparepart_request',
key: 'codSparePart'
}
},
name: {
type: DataTypes.STRING(45),
allowNull: true
},
description: {
type: DataTypes.TEXT,
allowNull: true
},
available: {
type: DataTypes.INTEGER(1),
allowNull: false,
defaultValue: '1'
},
codManufacturer: {
type: DataTypes.INTEGER(11),
allowNull: false,
references: {
model: 'manufacturer',
key: 'codManufacturer'
}
},
stock: {
type: DataTypes.INTEGER(10),
allowNull: true
},
image_uri: {
type: DataTypes.STRING(500),
allowNull: true
},
codProject: {
type: DataTypes.INTEGER(11),
allowNull: true,
references: {
model: 'project',
key: 'id'
}
},
price: {
type: DataTypes.FLOAT,
allowNull: false
}
}, {
tableName: 'sparepart',
timestamps: false
});
sparepart.associate = function (models) {
models.sparepart.belongsTo(models.manufacturer, {
foreignKey: 'codManufacturer',
targetKey: 'codManufacturer'
});
models.sparepart.belongsToMany(models.wo, { as: 'SPWO', through: 'sparepart_request', foreignKey: 'codSparePart', otherKey: 'codWO' });
};
return sparepart;
};
Here you can find my code, the three models and the query. at the moment I'm using postman I don't have anything in the frontEnd.
Here is one solution:
Remove id from sparepart_request.
Include the next code in sparepart_request:
sparepart_request.associate = function (models) {
models.sparepart_request.hasMany(models.sparepart, {foreignKey: 'codSparePart', targetKey: 'codSparePart'});
models.sparepart_request.hasMany(models.wo, {foreignKey: 'codWO', targetKey: 'codWO'});
};
Is it the correct way to do?, Apparently it is working...

How to define unique index on multiple columns in sequelize

How do I define a unique index on a combination of columns in sequelize. For example I want to add a unique index on user_id, count and name.
var Tag = sequelize.define('Tag', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
user_id: {
type: DataTypes.INTEGER(11),
allowNull: false,
},
count: {
type: DataTypes.INTEGER(11),
allowNull: true
},
name: {
type: DataTypes.STRING,
allowNull: true,
})
You can refer to this doc http://docs.sequelizejs.com/en/latest/docs/models-definition/#indexes
You will need to change your definition like shown below and call sync
var Tag = sequelize.define('Tag', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
user_id: {
type: DataTypes.INTEGER(11),
allowNull: false,
},
count: {
type: DataTypes.INTEGER(11),
allowNull: true
},
name: {
type: DataTypes.STRING,
allowNull: true,
}
},
{
indexes: [
{
unique: true,
fields: ['user_id', 'count', 'name']
}
]
});
I have same issue to applied composite unique constraint to multiple
columns but nothing work with Mysql, Sequelize(4.10.2) and NodeJs
8.9.4 finally I fixed through following code.
queryInterface.createTable('actions', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
system_id: {
type: Sequelize.STRING,
unique: 'actions_unique',
},
rule_id: {
type: Sequelize.STRING,
unique: 'actions_unique',
},
plan_id: {
type: Sequelize.INTEGER,
unique: 'actions_unique',
}
}, {
uniqueKeys: {
actions_unique: {
fields: ['system_id', 'rule_id', 'plan_id']
}
}
});
If the accepted one is not working then try the below code. It worked for me in my case rather the accepted one.
var Tag = sequelize.define('Tag', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
user_id: {
type: DataTypes.INTEGER(11),
allowNull: false,
unique: 'uniqueTag',
},
count: {
type: DataTypes.INTEGER(11),
allowNull: true,
unique: 'uniqueTag',
},
name: {
type: DataTypes.STRING,
allowNull: true,
unique: 'uniqueTag',
}
});
I tried to create an index on a single column.
This worked for me. Hope this helps.
Model
module.exports = (sequelize, DataTypes) => {
const Tag = sequelize.define(
"Tag",
{
name: { type: DataTypes.STRING, unique: true },
nVideos: DataTypes.INTEGER
},
{
indexes: [
{
unique: true,
fields: ["name"]
}
]
}
);
return Tag;
};
Migration
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable(
"Tags",
{
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
name: {
type: Sequelize.STRING,
unique: "unique_tag"
},
nVideos: { type: Sequelize.INTEGER },
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
},
{
uniqueKeys: {
unique_tag: {
customIndex: true,
fields: ["name"]
}
}
}
);
},
down: queryInterface => {
return queryInterface.dropTable("Tags");
}
};
I prefer sequelize sync method with composite unique, If not passing indexes name u will get a error as below on adding many indexes in index array.
error: SequelizeDatabaseError: Identifier name 'LONG_NAME' is too long
module.exports = function (sequelize: any, DataTypes: any) {
return sequelize.define('muln_user_goals_transaction', {
id: {
type: DataTypes.INTEGER(11),
allowNull: false,
autoIncrement: true,
primaryKey: true,
},
name: {
type: DataTypes.STRING(),
allowNull: false,
},
email: {
type: DataTypes.STRING(),
allowNull: false,
},
phone: {
type: DataTypes.STRING(),
allowNull: false,
},
amount: {
type: DataTypes.INTEGER(8),
allowNull: false
},
deleted: {
type: DataTypes.BOOLEAN,
defaultValue: false,
},
}, {
tableName: 'muln_user_goals_transaction',
timestamps: false,
indexes: [
{
name: 'unique_index',
unique: true,
fields: ['name', 'email', 'phone', 'amount', 'deleted']
}
],
defaultScope: {
where: {
deleted: false
}
}
});
};
Sequelize composite unique (manual)
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Model', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
fieldOne: {
type: Sequelize.INTEGER,
unique: 'uniqueTag',
allowNull: false,
references: {
model: 'Model1',
key: 'id'
},
onUpdate: 'cascade',
onDelete: 'cascade'
},
fieldsTwo: {
type: Sequelize.INTEGER,
unique: 'uniqueTag',
allowNull: false,
references: {
model: 'Model2',
key: 'id'
},
onUpdate: 'cascade',
onDelete: 'cascade'
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
})
.then(function() {
return queryInterface.sequelize.query(
'ALTER TABLE `UserFriends` ADD UNIQUE `unique_index`(`fieldOne`, `fieldTwo`)'
);
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Model');
}
};