Commit f71081b1 authored by Alejandro Alonso's avatar Alejandro Alonso
Browse files

Adding migration support and delete cascade migration for space references

parent c075c562
//'use strict'; //'use strict';
var Umzug = require('umzug');
//var mongoose = require('mongoose'); //var mongoose = require('mongoose');
//const sqlite3 = require('sqlite3').verbose(); //const sqlite3 = require('sqlite3').verbose();
...@@ -199,7 +200,7 @@ module.exports = { ...@@ -199,7 +200,7 @@ module.exports = {
updated_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW} updated_at: {type: Sequelize.DATE, defaultValue: Sequelize.NOW}
}), }),
init: function() { init: async function() {
User = this.User; User = this.User;
Session = this.Session; Session = this.Session;
Space = this.Space; Space = this.Space;
...@@ -256,7 +257,27 @@ module.exports = { ...@@ -256,7 +257,27 @@ module.exports = {
as: 'space' as: 'space'
}); });
sequelize.sync(); await sequelize.sync();
var umzug = new Umzug({
storage: 'sequelize',
storageOptions: {
sequelize: sequelize
},
migrations: {
params: [
sequelize.getQueryInterface(),
Sequelize
],
path: './models/migrations',
pattern: /\.js$/
}
});
umzug.up().then(function(migrations) {
console.log('Migration complete up!');
});
}, },
getUserRoleInSpace: (originalSpace, user, cb) => { getUserRoleInSpace: (originalSpace, user, cb) => {
......
'use strict';
module.exports = {
up: function(migration, DataTypes) {
return [
migration.changeColumn('memberships', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'CASCADE'
}
),
migration.changeColumn('artifacts', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'CASCADE'
}
),
migration.changeColumn('messages', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'CASCADE'
}
)
]
},
down: function(migration, DataTypes) {
return [
migration.changeColumn('memberships', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'NO ACTION'
}
),
,
migration.changeColumn('artifacts', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'NO ACTION'
}
),
migration.changeColumn('messages', 'space_id',
{
type: DataTypes.STRING,
references: {
model: 'spaces',
key: '_id'
},
onDelete: 'CASCADE',
onUpdate: 'NO ACTION'
}
)
]
}
};
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
"slug": "0.9.1", "slug": "0.9.1",
"sqlite3": "^4.0.0", "sqlite3": "^4.0.0",
"swig": "1.4.2", "swig": "1.4.2",
"umzug": "^2.1.0",
"underscore": "1.8.3", "underscore": "1.8.3",
"uuid": "^3.2.1", "uuid": "^3.2.1",
"validator": "7.0.0", "validator": "7.0.0",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment