Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions src/sequelize/migrations/20181113094807-add-missing-constraints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
'use strict';

module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.addConstraint('Flows', ['user_id'], {
type: 'FOREIGN KEY',
name: 'userId',
references: {
name: 'userId',
table: 'Users',
field: 'id'
},
onDelete: 'cascade'
}).then(() => {
return queryInterface.addConstraint('Microservices', ['user_id'], {
type: 'FOREIGN KEY',
name: 'userId',
references: {
name: 'userId',
table: 'Users',
field: 'id'
},
onDelete: 'cascade'
}).then(() => {
return queryInterface.addConstraint('Microservices', ['iofog_uuid'], {
type: 'FOREIGN KEY',
name: 'iofogUuid',
references: {
name: 'iofogUuid',
table: 'Fogs',
field: 'uuid'
},
onDelete: 'cascade'
})
}).then(() => {
return queryInterface.addConstraint('Microservices', ['catalog_item_id'], {
type: 'FOREIGN KEY',
name: 'catalogItemId',
references: {
name: 'catalogItemId',
table: 'CatalogItems',
field: 'id'
},
onDelete: 'cascade'
})
}).then(() => {
return queryInterface.addConstraint('Microservices', ['registry_id'], {
type: 'FOREIGN KEY',
name: 'registryId',
references: {
name: 'registryId',
table: 'Registries',
field: 'id'
},
onDelete: 'cascade'
})
}).then(() => {
return queryInterface.addConstraint('Microservices', ['flow_id'], {
type: 'FOREIGN KEY',
name: 'flowId',
references: {
name: 'flowId',
table: 'Flows',
field: 'id'
},
onDelete: 'cascade'
})
}).then(() => {
return queryInterface.addConstraint('ChangeTrackings', ['iofog_uuid'], {
type: 'FOREIGN KEY',
name: 'iofogUuid',
references: {
name: 'iofogUuid',
table: 'Fogs',
field: 'uuid'
},
onDelete: 'cascade'
})
})
}).then(() => {
return queryInterface.addConstraint('MicroservicePorts', ['user_id'], {
type: 'FOREIGN KEY',
name: 'userId',
references: {
name: 'userId',
table: 'Users',
field: 'id'
},
onDelete: 'cascade'
})
}).then(() => {
return queryInterface.addConstraint('MicroservicePorts', ['microservice_uuid'], {
type: 'FOREIGN KEY',
name: 'microserviceUuid',
references: {
name: 'microserviceUuid',
table: 'Microservices',
field: 'uuid'
},
onDelete: 'cascade'
})
});
},

down:
(queryInterface, Sequelize) => {

// for SQLite
return queryInterface.renameColumn('Flows', 'user_id', 'user_id')
.then(() => {
return queryInterface.renameColumn('Microservices', 'user_id', 'user_id')
}).then(() => {
return queryInterface.renameColumn('ChangeTrackings', 'iofog_uuid', 'iofog_uuid')
}).then(() => {
return queryInterface.renameColumn('MicroservicePorts', 'user_id', 'user_id')
})

// for other DB

// return queryInterface.removeConstraint('Flows', 'userId')
// .then(() => {
// return queryInterface.removeConstraint('Microservices', 'userId')
// }).then(() => {
// return queryInterface.removeConstraint('Microservices', 'iofogUuid')
// }).then(() => {
// return queryInterface.removeConstraint('Microservices', 'catalogItemId')
// }).then(() => {
// return queryInterface.removeConstraint('Microservices', 'registryId')
// }).then(() => {
// return queryInterface.removeConstraint('Microservices', 'flowId')
// }).then(() => {
// return queryInterface.removeConstraint('ChangeTrackings', 'iofogUuid')
// }).then(() => {
// return queryInterface.removeConstraint('MicroservicePorts', 'userId')
// }).then(() => {
// return queryInterface.removeConstraint('MicroservicePorts', 'microserviceUuid')
// });
}
};