Files
outline/server/migrations/20230429005039-collection-admins.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

57 lines
1.5 KiB
JavaScript

"use strict";
module.exports = {
async up(queryInterface) {
if (process.env.DEPLOYMENT === "hosted") {
return;
}
await queryInterface.sequelize.transaction(async (transaction) => {
// Convert collection members to admins where the user is the only
// membership in the collection.
await queryInterface.sequelize.query(
`UPDATE collection_users cu
SET permission = 'admin'
WHERE (
SELECT COUNT(*)
FROM collection_users
WHERE "collectionId" = cu."collectionId"
AND permission = 'read_write'
) = 1;`,
{
type: queryInterface.sequelize.QueryTypes.SELECT,
}
);
// Convert collection members to admins where the collection is private
// and they currently have read_write permission
await queryInterface.sequelize.query(
`UPDATE collection_users
SET permission = 'admin'
WHERE permission = 'read_write'
AND "collectionId" IN (
SELECT c."id"
FROM collections c
WHERE c.permission IS NULL
);`,
{
type: queryInterface.sequelize.QueryTypes.SELECT,
}
);
});
},
async down(queryInterface) {
if (process.env.DEPLOYMENT === "hosted") {
return;
}
await queryInterface.sequelize.query(
"UPDATE collection_users SET permission = 'read_write' WHERE permission = 'admin'",
{
type: queryInterface.sequelize.QueryTypes.SELECT,
}
);
},
};