updated models

This commit is contained in:
bill bittner 2017-09-25 20:30:45 -07:00
parent ede4d4804f
commit 6e60e0aa2f
8 changed files with 157 additions and 6 deletions

View file

@ -0,0 +1,79 @@
module.exports = {
up: (queryInterface, Sequelize) => {
// logic for transforming into the new state
const p1 = queryInterface.removeColumn(
'Certificate',
'UserId'
);
const p2 = queryInterface.addColumn(
'Certificate',
'ChannelId',
{
type : Sequelize.INTEGER,
allowNull: true,
}
);
const p3 = queryInterface.addConstraint(
'Certificate',
['ChannelId'],
{
type : 'FOREIGN KEY',
name : 'Certificate_ibfk_1',
references: {
table: 'Channel',
field: 'id',
},
onUpdate: 'cascade',
onDelete: 'cascade',
}
);
const p4 = queryInterface.changeColumn(
'Claim',
'FileId',
{
type : Sequelize.INTEGER,
allowNull: true,
}
);
const p5 = queryInterface.addConstraint(
'Claim',
['FileId'],
{
type : 'FOREIGN KEY',
name : 'Claim_ibfk_1',
references: {
table: 'File',
field: 'id',
},
onUpdate: 'cascade',
onDelete: 'cascade',
}
);
const p6 = queryInterface.removeColumn(
'File',
'UserId'
);
return Promise.all([p1, p2, p3, p4, p5, p6]);
},
down: (queryInterface, Sequelize) => {
// logic for reverting the changes
const p1 = queryInterface.addColumn(
'Certificate',
'UserId',
{
type : Sequelize.INTEGER,
allowNull: true,
}
);
const p2 = queryInterface.addColumn(
'File',
'UserId',
{
type : Sequelize.INTEGER,
allowNull: true,
}
);
return Promise.all([p1, p2]);
},
};

View file

@ -0,0 +1,46 @@
module.exports = {
up: (queryInterface, Sequelize) => {
// logic for transforming into the new state
const p1 = queryInterface.addColumn(
'User',
'userName',
{
type : Sequelize.STRING,
allowNull: true,
}
);
const p2 = queryInterface.removeColumn(
'User',
'channelName'
);
const p3 = queryInterface.removeColumn(
'User',
'channelClaimId'
);
return Promise.all([p1, p2, p3]);
},
down: (queryInterface, Sequelize) => {
// logic for reverting the changes
const p1 = queryInterface.removeColumn(
'User',
'userName'
);
const p2 = queryInterface.addColumn(
'User',
'channelName',
{
type : Sequelize.STRING,
allowNull: true,
}
);
const p3 = queryInterface.addColumn(
'User',
'channelClaimId',
{
type : Sequelize.STRING,
allowNull: true,
}
);
return Promise.all([p1, p2, p3]);
},
};

View file

@ -85,6 +85,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D
}, },
{ {
freezeTableName: true, freezeTableName: true,
underscored : true,
} }
); );

26
models/channel.js Normal file
View file

@ -0,0 +1,26 @@
module.exports = (sequelize, { STRING }) => {
const Channel = sequelize.define(
'Channel',
{
channelName: {
type : STRING,
allowNull: false,
},
channelClaimId: {
type : STRING,
allowNull: false,
},
},
{
freezeTableName: true,
underscored : true,
}
);
Channel.associate = db => {
Channel.belongsTo(db.User);
Channel.hasOne(db.Certificate);
};
return Channel;
};

View file

@ -137,6 +137,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D
}, },
{ {
freezeTableName: true, freezeTableName: true,
underscored : true,
} }
); );

View file

@ -47,6 +47,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER }) => {
}, },
{ {
freezeTableName: true, freezeTableName: true,
underscored : true,
} }
); );

View file

@ -22,6 +22,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, TEXT }) => {
}, },
{ {
freezeTableName: true, freezeTableName: true,
underscored : true,
} }
); );

View file

@ -2,11 +2,7 @@ module.exports = (sequelize, { STRING }) => {
const User = sequelize.define( const User = sequelize.define(
'User', 'User',
{ {
channelName: { userName: {
type : STRING,
allowNull: false,
},
channelClaimId: {
type : STRING, type : STRING,
allowNull: false, allowNull: false,
}, },
@ -17,11 +13,11 @@ module.exports = (sequelize, { STRING }) => {
}, },
{ {
freezeTableName: true, freezeTableName: true,
underscored : true,
} }
); );
User.associate = db => { User.associate = db => {
User.hasMany(db.File);
User.hasOne(db.Certificate); User.hasOne(db.Certificate);
}; };