2020-01-20 18:47:31 +01:00
|
|
|
const Sequelize = require('sequelize');
|
|
|
|
|
|
|
|
module.exports = sequelize => sequelize.define('Follow', {
|
|
|
|
id: {
|
|
|
|
type: Sequelize.INTEGER,
|
|
|
|
primaryKey: true,
|
|
|
|
autoIncrement: true,
|
|
|
|
},
|
|
|
|
follower: {
|
|
|
|
type: Sequelize.INTEGER,
|
|
|
|
allowNull: false,
|
|
|
|
references: {
|
|
|
|
model: sequelize.models.User,
|
|
|
|
key: 'id',
|
|
|
|
deferrable: Sequelize.Deferrable.INITIALLY_IMMEDIATE,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
followerDomain: {
|
|
|
|
type: Sequelize.TEXT,
|
|
|
|
allowNull: true,
|
|
|
|
comment: 'A null value means that the following id is on this server, otherwise it is external.',
|
|
|
|
},
|
|
|
|
following: {
|
|
|
|
type: Sequelize.INTEGER,
|
|
|
|
allowNull: false,
|
|
|
|
references: {
|
|
|
|
model: sequelize.models.User,
|
|
|
|
key: 'id',
|
|
|
|
deferrable: Sequelize.Deferrable.INITIALLY_IMMEDIATE,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
followingDomain: {
|
|
|
|
type: Sequelize.TEXT,
|
|
|
|
allowNull: true,
|
|
|
|
comment: 'A null value means that the following id is on this server, otherwise it is external.',
|
|
|
|
},
|
|
|
|
|
|
|
|
// Timestamps
|
|
|
|
createdAt: {
|
|
|
|
type: Sequelize.DATE,
|
|
|
|
allowNull: false,
|
|
|
|
defaultValue: Sequelize.NOW,
|
|
|
|
},
|
|
|
|
updatedAt: {
|
|
|
|
type: Sequelize.DATE,
|
|
|
|
allowNull: false,
|
|
|
|
defaultValue: Sequelize.NOW,
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
indexes: [
|
|
|
|
{
|
2020-02-07 01:27:22 +01:00
|
|
|
fields: ['follower', 'followerDomain'],
|
2020-01-20 18:47:31 +01:00
|
|
|
},
|
|
|
|
{
|
2020-02-07 01:27:22 +01:00
|
|
|
fields: ['following', 'followingDomain'],
|
2020-01-20 18:47:31 +01:00
|
|
|
},
|
|
|
|
],
|
|
|
|
scopes: {
|
2020-01-25 21:52:37 +01:00
|
|
|
internalFollowers: {
|
2020-01-20 18:47:31 +01:00
|
|
|
where: {
|
|
|
|
followerDomain: {
|
|
|
|
[Sequelize.Op.is]: null,
|
|
|
|
},
|
2020-01-25 21:52:37 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
internalFollowing: {
|
|
|
|
where: {
|
2020-01-20 18:47:31 +01:00
|
|
|
followingDomain: {
|
|
|
|
[Sequelize.Op.is]: null,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|