Readlebee/server/sequelize/models/Follow.js

74 lines
1.6 KiB
JavaScript
Raw Normal View History

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-02-07 01:27:22 +01:00
fields: ['following', 'followingDomain'],
},
],
scopes: {
2020-01-25 21:52:37 +01:00
internalFollowers: {
where: {
followerDomain: {
[Sequelize.Op.is]: null,
},
2020-01-25 21:52:37 +01:00
},
},
internalFollowing: {
where: {
followingDomain: {
[Sequelize.Op.is]: null,
},
},
},
}
});