-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compatibility between Notification V1 and Notification V2. Integrate Notification V2 methods into Notification V1 to begin populating the database in advance of the data migration, ensuring clients can transition to V2 seamlessly without any changes on their end.
- Loading branch information
Showing
50 changed files
with
2,334 additions
and
1,585 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class NotificationCleanup1726452966034 implements MigrationInterface { | ||
name = 'NotificationCleanup1726452966034'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`DROP TRIGGER IF EXISTS "update_push_notification_devices_updated_at" ON "push_notification_devices"`, | ||
); | ||
await queryRunner.query( | ||
`DROP TRIGGER IF EXISTS "update_notification_subscriptions_updated_at" ON "notification_subscriptions"`, | ||
); | ||
await queryRunner.query( | ||
`DROP TYPE IF EXISTS "notification_types_name_enum" CASCADE`, | ||
); | ||
await queryRunner.query( | ||
`DROP TYPE IF EXISTS "push_notification_devices_device_type_enum" CASCADE`, | ||
); | ||
await queryRunner.query(`DROP FUNCTION IF EXISTS update_updated_at()`); | ||
await queryRunner.query( | ||
`DROP TABLE IF EXISTS "push_notification_devices" CASCADE`, | ||
); | ||
await queryRunner.query( | ||
`DROP TABLE IF EXISTS "notification_subscriptions" CASCADE`, | ||
); | ||
await queryRunner.query( | ||
`DROP TABLE IF EXISTS "notification_subscription_notification_types" CASCADE`, | ||
); | ||
await queryRunner.query( | ||
`DROP TABLE IF EXISTS "notification_types" CASCADE`, | ||
); | ||
} | ||
|
||
public async down(): Promise<void> {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 0 additions & 23 deletions
23
src/datasources/notifications/__tests__/test.notifications.datasource.module.ts
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
src/datasources/notifications/entities/__tests__/notification-devices.entity.db.builder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { IBuilder } from '@/__tests__/builder'; | ||
import { Builder } from '@/__tests__/builder'; | ||
import type { NotificationDevice } from '@/datasources/notifications/entities/notification-devices.entity.db'; | ||
import { DeviceType } from '@/domain/notifications/v2/entities/device-type.entity'; | ||
import { faker } from '@faker-js/faker/.'; | ||
import type { UUID } from 'crypto'; | ||
|
||
export function notificationDeviceBuilder(): IBuilder<NotificationDevice> { | ||
return new Builder<NotificationDevice>() | ||
.with('id', faker.number.int()) | ||
.with('device_uuid', faker.string.uuid() as UUID) | ||
.with('device_type', faker.helpers.enumValue(DeviceType)) | ||
.with( | ||
'cloud_messaging_token', | ||
faker.string.alphanumeric({ length: { min: 10, max: 255 } }), | ||
) | ||
.with('created_at', new Date()) | ||
.with('updated_at', new Date()); | ||
} |
16 changes: 16 additions & 0 deletions
16
...tions/entities/__tests__/notification-subscription-notification-type.entity.db.builder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { IBuilder } from '@/__tests__/builder'; | ||
import { Builder } from '@/__tests__/builder'; | ||
import { faker } from '@faker-js/faker/.'; | ||
import { notificationTypeBuilder } from '@/datasources/notifications/entities/__tests__/notification-type.entity.db.builder'; | ||
import { notificationSubscriptionBuilder } from '@/datasources/notifications/entities/__tests__/notification-subscription.entity.db.builder'; | ||
import type { NotificationSubscriptionNotificationType } from '@/datasources/notifications/entities/notification-subscription-notification-type.entity.db'; | ||
|
||
export function notificationSubscriptionNotificationTypeTypeBuilder(): IBuilder<NotificationSubscriptionNotificationType> { | ||
return new Builder<NotificationSubscriptionNotificationType>() | ||
.with('id', faker.number.int()) | ||
.with( | ||
'notification_subscription', | ||
notificationSubscriptionBuilder().build(), | ||
) | ||
.with('notification_type', notificationTypeBuilder().build()); | ||
} |
18 changes: 18 additions & 0 deletions
18
...tasources/notifications/entities/__tests__/notification-subscription.entity.db.builder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { IBuilder } from '@/__tests__/builder'; | ||
import { Builder } from '@/__tests__/builder'; | ||
import { notificationDeviceBuilder } from '@/datasources/notifications/entities/__tests__/notification-devices.entity.db.builder'; | ||
import type { NotificationSubscription } from '@/datasources/notifications/entities/notification-subscription.entity.db'; | ||
import { faker } from '@faker-js/faker/.'; | ||
import { getAddress } from 'viem'; | ||
|
||
export function notificationSubscriptionBuilder(): IBuilder<NotificationSubscription> { | ||
return new Builder<NotificationSubscription>() | ||
.with('id', faker.number.int()) | ||
.with('chain_id', faker.number.int({ min: 1, max: 100 }).toString()) | ||
.with('safe_address', getAddress(faker.finance.ethereumAddress())) | ||
.with('signer_address', getAddress(faker.finance.ethereumAddress())) | ||
.with('created_at', new Date()) | ||
.with('updated_at', new Date()) | ||
.with('notification_subscription_notification_type', []) | ||
.with('push_notification_device', notificationDeviceBuilder().build()); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/datasources/notifications/entities/__tests__/notification-type.entity.db.builder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { IBuilder } from '@/__tests__/builder'; | ||
import { Builder } from '@/__tests__/builder'; | ||
import type { NotificationType } from '@/datasources/notifications/entities/notification-type.entity.db'; | ||
import { faker } from '@faker-js/faker/.'; | ||
import { NotificationType as NotificationTypeEnum } from '@/domain/notifications/v2/entities/notification.entity'; | ||
|
||
export function notificationTypeBuilder(): IBuilder<NotificationType> { | ||
return new Builder<NotificationType>() | ||
.with('id', faker.number.int()) | ||
.with('name', faker.helpers.enumValue(NotificationTypeEnum)) | ||
.with('notification_subscription_notification_type', []); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...tasources/notifications/entities/notification-subscription-notification-type.entity.db.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
Entity, | ||
JoinColumn, | ||
ManyToOne, | ||
PrimaryGeneratedColumn, | ||
Unique, | ||
} from 'typeorm'; | ||
import { NotificationType } from '@/datasources/notifications/entities/notification-type.entity.db'; | ||
import { NotificationSubscription } from '@/datasources/notifications/entities/notification-subscription.entity.db'; | ||
import { z } from 'zod'; | ||
|
||
export const NotificationSubscriptionNotificationTypeSchema = z.object({ | ||
id: z.number(), | ||
}); | ||
|
||
@Entity('notification_subscription_notification_types') | ||
@Unique(['notification_subscription', 'notification_type']) | ||
export class NotificationSubscriptionNotificationType | ||
implements z.infer<typeof NotificationSubscriptionNotificationTypeSchema> | ||
{ | ||
@PrimaryGeneratedColumn() | ||
id!: number; | ||
|
||
@ManyToOne( | ||
() => NotificationSubscription, | ||
(subscription) => subscription.id, | ||
{ onDelete: 'CASCADE' }, | ||
) | ||
@JoinColumn({ | ||
name: 'notification_subscription_id', | ||
}) | ||
notification_subscription!: NotificationSubscription; | ||
|
||
@ManyToOne( | ||
() => NotificationType, | ||
(notificationType) => | ||
notificationType.notification_subscription_notification_type, | ||
{ | ||
onDelete: 'CASCADE', | ||
}, | ||
) | ||
@JoinColumn({ name: 'notification_type_id' }) | ||
notification_type!: NotificationType; | ||
} |
20 changes: 0 additions & 20 deletions
20
src/datasources/notifications/entities/notification-subscription-notification-type.entity.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.