Created
October 29, 2017 01:57
-
-
Save jrm2k6/4d808c8210ca1f0d57a7a6f885f58da8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = { | |
up: function(queryInterface, Sequelize) { | |
return queryInterface.createTable('pictures', { | |
id: { | |
allowNull: false, | |
autoIncrement: true, | |
primaryKey: true, | |
type: Sequelize.INTEGER | |
}, | |
path: { | |
type: Sequelize.STRING | |
}, | |
userId: { | |
type: Sequelize.INTEGER, | |
allowNull: true, | |
references: { | |
model: 'users', | |
key: 'id' | |
} | |
}, | |
createdAt: { | |
allowNull: false, | |
type: Sequelize.DATE | |
}, | |
updatedAt: { | |
allowNull: false, | |
type: Sequelize.DATE | |
} | |
}); | |
}, | |
down: function(queryInterface, Sequelize) { | |
return queryInterface.dropTable('pictures'); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = { | |
up: function (queryInterface, Sequelize) { | |
return queryInterface.createTable('users', { | |
id: { | |
type: Sequelize.INTEGER, | |
primaryKey: true, | |
autoIncrement: true | |
}, | |
thirdPartyUserId: Sequelize.INTEGER, | |
name: Sequelize.STRING, | |
oauthToken: Sequelize.STRING, | |
oauthTokenSecret: Sequelize.STRING, | |
provider: Sequelize.STRING, | |
createdAt: { | |
type: Sequelize.DATE | |
}, | |
updatedAt: { | |
type: Sequelize.DATE | |
} | |
}); | |
}, | |
down: function (queryInterface, Sequelize) { | |
return queryInterface.dropTable('users'); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = function(sequelize, DataTypes) { | |
var Picture = sequelize.define('Picture', { | |
path: DataTypes.STRING, | |
uploadedByUserId: DataTypes.INTEGER | |
}); | |
Picture.associate = function(models) { | |
Picture.belongsTo(models.User, { | |
foreignKey: { | |
allowNull: true | |
} | |
}); | |
} | |
return Picture; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(sequelize, Sequelize) { | |
const User = sequelize.define('User', { | |
thirdPartyUserId: Sequelize.INTEGER, | |
name: Sequelize.STRING, | |
oauthToken: Sequelize.STRING, | |
oauthTokenSecret: Sequelize.STRING, | |
provider: Sequelize.STRING | |
}); | |
User.prototype.asSafeUser = function() { | |
return { | |
id: this.getDataValue('id'), | |
name: this.getDataValue('name'), | |
provider: this.getDataValue('provider') | |
} | |
} | |
User.associate = function(models) { | |
User.hasMany(models.Picture); | |
} | |
return User; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment