backend/src/migrations/notifications-without-user.ts (view raw)
1const Strapi = require("@strapi/strapi");
2
3const main = async () => {
4 const appContext = await Strapi.compile();
5 await Strapi(appContext).load();
6
7 const notifications = await strapi.entityService.findMany(
8 "api::notification.notification",
9 {
10 filters: {
11 user: { id: { $null: true } },
12 },
13 limit: -1,
14 }
15 );
16 console.log(`NOTIFICATIONS COUNT: ${notifications.length}`);
17 for (const notification of notifications) {
18 console.log(`Remove ${notification.id}`);
19 await strapi.entityService.delete(
20 "api::notification.notification",
21 notification.id
22 );
23 }
24 process.exit(0);
25};
26
27main().catch((error) => {
28 console.error(error);
29 process.exit(1);
30});