Files
outline/server/migrations/20230314013103-move-notification-settings.js
codegen-sh[bot] 97f8d0f265 Separate Prettier and ESLint according to best practices (#9565)
* Separate Prettier and ESLint according to best practices

- Create standalone .prettierrc configuration file
- Remove eslint-plugin-prettier integration from ESLint config
- Replace with eslint-config-prettier to disable conflicting rules
- Remove eslint-plugin-prettier dependency
- Add dedicated format and format:check scripts
- Update lint-staged to run Prettier and ESLint separately
- Format entire codebase with new Prettier configuration

This follows the recommended approach from Prettier documentation:
https://prettier.io/docs/integrating-with-linters#notes

* Remove test comment

---------

Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com>
2025-07-08 18:01:48 -04:00

66 lines
1.9 KiB
JavaScript

"use strict";
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.addColumn("users", "notificationSettings", {
type: Sequelize.JSONB,
allowNull: false,
defaultValue: {},
transaction,
});
if (process.env.DEPLOYMENT === "hosted") {
return;
}
// In cloud hosted Outline this migration is done in a script instead due
// to scale considerations.
const users = await queryInterface.sequelize.query(
"SELECT id FROM users",
{
type: queryInterface.sequelize.QueryTypes.SELECT,
transaction,
}
);
for (const user of users) {
const settings = await queryInterface.sequelize.query(
`SELECT * FROM notification_settings WHERE "userId" = :userId`,
{
type: queryInterface.sequelize.QueryTypes.SELECT,
replacements: { userId: user.id },
transaction,
}
);
const eventTypes = settings.map((setting) => setting.event);
if (eventTypes.length > 0) {
const notificationSettings = {};
for (const eventType of eventTypes) {
notificationSettings[eventType] = true;
}
await queryInterface.sequelize.query(
`UPDATE users SET "notificationSettings" = :notificationSettings WHERE id = :userId`,
{
type: queryInterface.sequelize.QueryTypes.UPDATE,
replacements: {
userId: user.id,
notificationSettings: JSON.stringify(notificationSettings),
},
transaction,
}
);
}
}
});
},
async down(queryInterface) {
return queryInterface.removeColumn("users", "notificationSettings");
},
};