From 0b76e52a6591f0c764342e162f18f8cb8be3c986 Mon Sep 17 00:00:00 2001 From: Ramin Date: Tue, 23 Apr 2024 04:56:16 +0330 Subject: [PATCH 1/7] add Group Parent for SuperFluid --- .../1713834025817-addGroupParentSuperFluid.ts | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 migrations/1713834025817-addGroupParentSuperFluid.ts diff --git a/migrations/1713834025817-addGroupParentSuperFluid.ts b/migrations/1713834025817-addGroupParentSuperFluid.ts new file mode 100644 index 0000000..0094d1c --- /dev/null +++ b/migrations/1713834025817-addGroupParentSuperFluid.ts @@ -0,0 +1,49 @@ +import { MigrationInterface, QueryRunner } from "typeorm" +import { NOTIFICATION_CATEGORY } from '../src/types/general'; +import { NotificationType } from '../src/entities/notificationType'; +import { MICRO_SERVICES } from '../src/utils/utils'; +import { NOTIFICATION_CATEGORY_GROUPS } from '../src/entities/notificationSetting'; + +export const superFluidNotificationTypes = [ + { + isGlobal: false, + isGroupParent: true, + showOnSettingPage: true, + webDefaultValue: true, + emailDefaultValue: true, + isEmailEditable: true, + isWebEditable: true, + name: 'Stream Balance Warnings', + description: 'Notify me when any of my Stream Balances are running low', + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.SUPPORTED_PROJECTS, + schemaValidator: null, + emailNotifierService: null, + emailNotificationId: null, + pushNotifierService: null, + categoryGroup: NOTIFICATION_CATEGORY_GROUPS.SUPERFLUID, + title: 'Stream Balance Warnings', + }, +] + +export class addGroupParentSuperFluid1713834025817 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + // Fetch the notificationTypeIds for the "superfluid" categoryGroup + const notificationTypeIds = (await queryRunner.query(` + SELECT "id" FROM "notification_type" WHERE "categoryGroup" = 'superfluid'; + `)).map((i: any) => i.id); + await queryRunner.query( + `UPDATE notification_type + SET showOnSettingPage = false, emailDefaultValue = true, category = ${NOTIFICATION_CATEGORY.SUPPORTED_PROJECTS} + WHERE id IN (${notificationTypeIds.join(", ")})` + ); + await queryRunner.manager.save( + NotificationType, + superFluidNotificationTypes, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + } + +} From 680f0dc11c3612af43cdd0b36e870629dd28d937 Mon Sep 17 00:00:00 2001 From: Ramin Date: Tue, 23 Apr 2024 05:10:58 +0330 Subject: [PATCH 2/7] fix lint error --- migrations/1713834025817-addGroupParentSuperFluid.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/migrations/1713834025817-addGroupParentSuperFluid.ts b/migrations/1713834025817-addGroupParentSuperFluid.ts index 0094d1c..7277831 100644 --- a/migrations/1713834025817-addGroupParentSuperFluid.ts +++ b/migrations/1713834025817-addGroupParentSuperFluid.ts @@ -44,6 +44,8 @@ export class addGroupParentSuperFluid1713834025817 implements MigrationInterface } public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `DELETE FROM notification_type WHERE "categoryGroup" = 'superfluid' AND "name" = 'Stream Balance Warnings';`, + ); } - } From dbd9c56a6a024d789a73dfd71e92c83fa8526937 Mon Sep 17 00:00:00 2001 From: Ramin Date: Tue, 23 Apr 2024 15:04:59 +0330 Subject: [PATCH 3/7] change enum to string --- migrations/1713834025817-addGroupParentSuperFluid.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/1713834025817-addGroupParentSuperFluid.ts b/migrations/1713834025817-addGroupParentSuperFluid.ts index 7277831..84b9c4e 100644 --- a/migrations/1713834025817-addGroupParentSuperFluid.ts +++ b/migrations/1713834025817-addGroupParentSuperFluid.ts @@ -34,7 +34,7 @@ export class addGroupParentSuperFluid1713834025817 implements MigrationInterface `)).map((i: any) => i.id); await queryRunner.query( `UPDATE notification_type - SET showOnSettingPage = false, emailDefaultValue = true, category = ${NOTIFICATION_CATEGORY.SUPPORTED_PROJECTS} + SET showOnSettingPage = false, emailDefaultValue = true, category = '${NOTIFICATION_CATEGORY.SUPPORTED_PROJECTS}' WHERE id IN (${notificationTypeIds.join(", ")})` ); await queryRunner.manager.save( From e21ebfac08ffb794c4d29f0c2b7584ca6e53523c Mon Sep 17 00:00:00 2001 From: Ramin Date: Tue, 23 Apr 2024 15:09:27 +0330 Subject: [PATCH 4/7] fix column names --- migrations/1713834025817-addGroupParentSuperFluid.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/1713834025817-addGroupParentSuperFluid.ts b/migrations/1713834025817-addGroupParentSuperFluid.ts index 84b9c4e..627db75 100644 --- a/migrations/1713834025817-addGroupParentSuperFluid.ts +++ b/migrations/1713834025817-addGroupParentSuperFluid.ts @@ -34,7 +34,7 @@ export class addGroupParentSuperFluid1713834025817 implements MigrationInterface `)).map((i: any) => i.id); await queryRunner.query( `UPDATE notification_type - SET showOnSettingPage = false, emailDefaultValue = true, category = '${NOTIFICATION_CATEGORY.SUPPORTED_PROJECTS}' + SET "showOnSettingPage" = false, "emailDefaultValue" = true, "category" = '${NOTIFICATION_CATEGORY.SUPPORTED_PROJECTS}' WHERE id IN (${notificationTypeIds.join(", ")})` ); await queryRunner.manager.save( From 37b8d8f30876a71bb4cdf941988eaacc30282c72 Mon Sep 17 00:00:00 2001 From: Ramin Date: Tue, 23 Apr 2024 18:26:07 +0330 Subject: [PATCH 5/7] add parent superfluid notification to all users --- ...883053900-addSuperFluidParentToAllUsers.ts | 40 +++++++++++++++++++ package.json | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 migrations/1713883053900-addSuperFluidParentToAllUsers.ts diff --git a/migrations/1713883053900-addSuperFluidParentToAllUsers.ts b/migrations/1713883053900-addSuperFluidParentToAllUsers.ts new file mode 100644 index 0000000..e9d7319 --- /dev/null +++ b/migrations/1713883053900-addSuperFluidParentToAllUsers.ts @@ -0,0 +1,40 @@ +import { MigrationInterface, QueryRunner } from "typeorm" + +export class addSuperFluidParentToAllUsers1713883053900 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + // Fetch the notificationTypeIds for the "superfluid" parent + const notificationTypeId = (await queryRunner.query(` + SELECT "id" FROM "notification_type" WHERE "categoryGroup" = 'superfluid' AND "isGroupParent" = true; + `)).map((i: any) => i.id)[0]; + + // Fetch all unique userAddressIds + const userAddressIds = await queryRunner.query(` + SELECT "id" FROM "user_address"; + `); + + // For each userAddressId, insert a new row + for (const { id } of userAddressIds) { + await queryRunner.query(` + INSERT INTO "notification_setting" ( + "allowNotifications", + "allowEmailNotification", + "allowDappPushNotification", + "notificationTypeId", + "userAddressId" + ) VALUES (true, true, true, ${notificationTypeId}, ${id}); + `); + } + } + + public async down(queryRunner: QueryRunner): Promise { + // Fetch the notificationTypeIds for the "superfluid" categoryGroup + const notificationTypeId = await queryRunner.query(` + SELECT "id" FROM "notification_type" WHERE "categoryGroup" = 'superfluid' AND "isGroupParent" = true; + `); + const id = notificationTypeId.map((nt: { id: number; }) => nt.id)[0] + // Delete the rows with the fetched notificationTypeId for all userAddressIds + await queryRunner.query(` + DELETE FROM "notification_setting" WHERE "notificationTypeId" = ${id}; + `); + } +} diff --git a/package.json b/package.json index 1043198..6f591da 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", "prettify": "prettier --write '**/*.ts*'", - "db:migrate:run:local": "NODE_ENV=development npx typeorm-ts-node-esm migration:run -d ./src/dataSource.ts ", + "db:migrate:run:local": "NODE_ENV=development npx typeorm-ts-node-commonjs migration:run -d ./src/dataSource.ts ", "db:migrate:run:staging": "NODE_ENV=staging npx typeorm-ts-node-esm migration:run -d ./src/dataSource.ts ", "db:migrate:revert:local": "NODE_ENV=development npx typeorm-ts-node-esm migration:revert -d ./src/dataSource.ts ", "db:migrate:run:test": "NODE_ENV=test npx typeorm-ts-node-esm migration:run -d ./src/dataSource.ts ", From 714d0c9d817efc60b47dbc6b121cee8f81d7d771 Mon Sep 17 00:00:00 2001 From: Ramin Date: Tue, 23 Apr 2024 19:35:33 +0330 Subject: [PATCH 6/7] fix uppercase words --- migrations/1713834025817-addGroupParentSuperFluid.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/1713834025817-addGroupParentSuperFluid.ts b/migrations/1713834025817-addGroupParentSuperFluid.ts index 627db75..4ed35ea 100644 --- a/migrations/1713834025817-addGroupParentSuperFluid.ts +++ b/migrations/1713834025817-addGroupParentSuperFluid.ts @@ -13,7 +13,7 @@ export const superFluidNotificationTypes = [ emailDefaultValue: true, isEmailEditable: true, isWebEditable: true, - name: 'Stream Balance Warnings', + name: 'Stream balance warnings', description: 'Notify me when any of my Stream Balances are running low', microService: MICRO_SERVICES.givethio, category: NOTIFICATION_CATEGORY.SUPPORTED_PROJECTS, From fde2ca41be992754f33db184af4298b2f865f4ed Mon Sep 17 00:00:00 2001 From: Ramin Date: Tue, 23 Apr 2024 19:43:14 +0330 Subject: [PATCH 7/7] fix uppercase words --- migrations/1713834025817-addGroupParentSuperFluid.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/1713834025817-addGroupParentSuperFluid.ts b/migrations/1713834025817-addGroupParentSuperFluid.ts index 4ed35ea..05ee03e 100644 --- a/migrations/1713834025817-addGroupParentSuperFluid.ts +++ b/migrations/1713834025817-addGroupParentSuperFluid.ts @@ -22,7 +22,7 @@ export const superFluidNotificationTypes = [ emailNotificationId: null, pushNotifierService: null, categoryGroup: NOTIFICATION_CATEGORY_GROUPS.SUPERFLUID, - title: 'Stream Balance Warnings', + title: 'Stream balance warnings', }, ]