Colubrina/backend/migrations/20220329054753-communications.js

231 lines
4.9 KiB
JavaScript
Raw Permalink Normal View History

2022-06-05 22:58:18 +10:00
"use strict"
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable("Chats", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.BIGINT
},
type: {
type: Sequelize.ENUM(["direct", "group", "channel"])
},
privacy: {
type: Sequelize.ENUM([
"direct",
"everyoneInvited",
"tenantInvited",
"manualInvited"
])
},
name: {
type: Sequelize.STRING,
defaultValue: "Unnamed Group",
allowNull: false
},
userId: {
type: Sequelize.BIGINT,
allowNull: false
},
usersId: {
type: Sequelize.JSON,
defaultValue: [],
allowNull: false
},
icon: {
type: Sequelize.STRING,
defaultValue: null
},
privilegedUserIds: {
type: Sequelize.JSON,
defaultValue: [],
allowNull: false
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
})
await queryInterface.createTable("Messages", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.BIGINT
},
chatId: {
type: Sequelize.BIGINT,
allowNull: false
},
userId: {
type: Sequelize.BIGINT,
allowNull: false
},
content: {
type: Sequelize.TEXT,
allowNull: false
},
type: {
type: Sequelize.ENUM([
"message",
"leave",
"join",
"pin",
"administrator",
"rename",
"system"
])
},
embeds: {
type: Sequelize.JSON,
defaultValue: [],
allowNull: false
},
attachments: {
type: Sequelize.JSON,
defaultValue: [],
allowNull: false
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
})
await queryInterface.createTable("Invites", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.BIGINT
},
invite: {
type: Sequelize.STRING,
allowNull: false
},
chatId: {
type: Sequelize.BIGINT,
allowNull: false
},
userId: {
type: Sequelize.BIGINT,
allowNull: false
},
expiresAt: {
type: Sequelize.DATE,
allowNull: false
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
})
await queryInterface.createTable("BlockedUsers", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.BIGINT
},
userId: {
type: Sequelize.BIGINT,
allowNull: false
},
blockedUserId: {
type: Sequelize.BIGINT,
allowNull: false
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
})
await queryInterface.createTable("MutedChats", {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.BIGINT
},
userId: {
type: Sequelize.BIGINT,
allowNull: false
},
chatId: {
type: Sequelize.BIGINT,
allowNull: false
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
})
2022-07-29 21:56:16 +10:00
await queryInterface.addColumn("Users", "privacy", {
2022-06-05 22:58:18 +10:00
type: Sequelize.JSON,
defaultValue: {
communications: {
enabled: false,
outsideTenant: false,
directMessages: "friendsOnly",
friendRequests: true
}
},
allowNull: false
})
2022-07-29 21:56:16 +10:00
await queryInterface.createTable("Friends", {
2022-06-05 22:58:18 +10:00
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.BIGINT
},
userId: {
type: Sequelize.BIGINT,
allowNull: false
},
friendId: {
type: Sequelize.BIGINT,
allowNull: false
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
})
},
down: async (queryInterface, Sequelize) => {
/**
* Add reverting commands here.
*
* Example:
* await queryInterface.dropTable('users');
*/
}
}