diff --git a/migrations/UpdateAssociationColumns.js b/migrations/UpdateAssociationColumns.js new file mode 100644 index 00000000..22c6def9 --- /dev/null +++ b/migrations/UpdateAssociationColumns.js @@ -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]); + }, +}; diff --git a/migrations/UpdateUserAndChannel.js b/migrations/UpdateUserAndChannel.js new file mode 100644 index 00000000..32c22097 --- /dev/null +++ b/migrations/UpdateUserAndChannel.js @@ -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]); + }, +}; diff --git a/models/certificate.js b/models/certificate.js index f8e8784d..04fee274 100644 --- a/models/certificate.js +++ b/models/certificate.js @@ -85,6 +85,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D }, { freezeTableName: true, + underscored : true, } ); diff --git a/models/channel.js b/models/channel.js new file mode 100644 index 00000000..5478088f --- /dev/null +++ b/models/channel.js @@ -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; +}; diff --git a/models/claim.js b/models/claim.js index ab35576b..d4e09303 100644 --- a/models/claim.js +++ b/models/claim.js @@ -137,6 +137,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D }, { freezeTableName: true, + underscored : true, } ); diff --git a/models/file.js b/models/file.js index dbe74cf4..75a5db8c 100644 --- a/models/file.js +++ b/models/file.js @@ -47,6 +47,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER }) => { }, { freezeTableName: true, + underscored : true, } ); diff --git a/models/request.js b/models/request.js index 846e12c6..b436d23e 100644 --- a/models/request.js +++ b/models/request.js @@ -22,6 +22,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, TEXT }) => { }, { freezeTableName: true, + underscored : true, } ); diff --git a/models/user.js b/models/user.js index 9368d89d..cb44acd5 100644 --- a/models/user.js +++ b/models/user.js @@ -2,11 +2,7 @@ module.exports = (sequelize, { STRING }) => { const User = sequelize.define( 'User', { - channelName: { - type : STRING, - allowNull: false, - }, - channelClaimId: { + userName: { type : STRING, allowNull: false, }, @@ -17,11 +13,11 @@ module.exports = (sequelize, { STRING }) => { }, { freezeTableName: true, + underscored : true, } ); User.associate = db => { - User.hasMany(db.File); User.hasOne(db.Certificate); };