Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add v2 notifications routes #1787

Merged
merged 53 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
313269c
Add migration for notifications
iamacook Jul 11, 2024
82e755b
Rename token column
iamacook Jul 12, 2024
be971ab
Add `cloud_messaging_token` <> `PUSH_NOTIFICATIONS` medium constraints
iamacook Jul 12, 2024
3fa4b2f
Cleanup test
iamacook Jul 12, 2024
2a356cf
Remove `enabled` column and triggers
iamacook Jul 17, 2024
6193c4f
Add `device_uuid` column
iamacook Jul 17, 2024
dc736e7
Rename `medium` to `channel`
iamacook Jul 17, 2024
aa939ff
Add datasource for notifications
iamacook Jul 22, 2024
422c719
Fix tests
iamacook Jul 22, 2024
6c33fa5
Improve datasource tests
iamacook Jul 22, 2024
107b7da
Merge branch 'main' into notifications-database
iamacook Jul 22, 2024
4e10a90
Fix types
iamacook Jul 22, 2024
8eddd84
Get subscribers with their tokens
iamacook Jul 22, 2024
a644d71
Merge branch 'main' into notifications-database
iamacook Jul 22, 2024
bbf8872
Fix lint and tests
iamacook Jul 23, 2024
906e7b6
Facilitate multiple Safe notifications across devices
iamacook Jul 24, 2024
1db3af7
Remove unnecessary `account_id` from `notification_devices` table
iamacook Jul 24, 2024
bab3f52
Remove unused entities
iamacook Jul 24, 2024
1990006
Merge channel/device tables and move orphan logic to domain
iamacook Jul 24, 2024
e59bf08
Add domain logic for push notifications
iamacook Jul 22, 2024
a73958b
Fix test
iamacook Jul 23, 2024
4d5bd6e
Add feature flag for push notifications
iamacook Jul 23, 2024
6658f68
Only call enqueuer if feature enabled
iamacook Jul 23, 2024
ec8b9c6
Fix interfaces
iamacook Jul 24, 2024
86de998
Cleanup unregistered tokens
iamacook Jul 24, 2024
b59e7f7
Fix tests and cleanup stale tokens
iamacook Jul 24, 2024
b9354c9
Fix query
iamacook Jul 24, 2024
8088fcd
Simplify upsertion logic
iamacook Jul 25, 2024
663d901
Add log and test coverage
iamacook Jul 27, 2024
c63bf4a
Decouple account from notifications
iamacook Jul 30, 2024
8badc91
Decouple notifications from account in datasource
iamacook Jul 30, 2024
2d2ab0d
Move datasource
iamacook Jul 30, 2024
700e552
Merge branch 'main' into notifications-database
iamacook Jul 30, 2024
1ea77f3
Merge branch 'notifications-database' into notifications-domain
iamacook Jul 30, 2024
c908fae
Remove unnecessary entity and fix typos
iamacook Jul 30, 2024
c13f4b8
Dispatch notifications on hook
iamacook Jul 31, 2024
f408883
Add notifications routes
iamacook Jul 25, 2024
a1095d4
Add further test coverage
iamacook Jul 25, 2024
62e64b6
Assert errors are forwarded by datasource
iamacook Jul 25, 2024
71a8cb8
Add `JwtConfigurationModule` override
iamacook Jul 26, 2024
5893e6f
Use test configuration
iamacook Jul 26, 2024
f18abc1
Fix tests
iamacook Jul 27, 2024
e970dc0
Fix tests
iamacook Jul 31, 2024
26f76b4
Remove comment
iamacook Jul 31, 2024
d49aca2
Improve tests and remove unnecessary injection
iamacook Aug 2, 2024
2ef0058
Fix lint
iamacook Aug 2, 2024
2026c12
Merge branch 'notifications-database' into notifications-domain
iamacook Aug 2, 2024
2176668
Merge branch 'notifications-domain' into notifications-routes
iamacook Aug 2, 2024
cd6ae6c
Fix mock
iamacook Aug 2, 2024
6b7f0ca
Merge branch 'notifications-database' into notifications-domain
iamacook Aug 2, 2024
f931f06
Merge branch 'notifications-domain' into notifications-routes
iamacook Aug 2, 2024
2a12161
Address comments
iamacook Aug 5, 2024
bd179e1
Merge branch 'main' into notifications-routes
iamacook Aug 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions migrations/00005_notifications/index.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
DROP TABLE IF EXISTS push_notification_devices, notification_types, notification_subscriptions, notification_subscription_notification_types CASCADE;

--------------------------------------------------------
-- Push notification devices: 'ANDROID', 'IOS', 'WEB' --
--------------------------------------------------------
CREATE TABLE push_notification_devices (
id SERIAL PRIMARY KEY,
device_type VARCHAR(255) CHECK (device_type IN ('ANDROID', 'IOS', 'WEB')) NOT NULL,
device_uuid UUID NOT NULL UNIQUE,
cloud_messaging_token VARCHAR(255) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);

-- Update updated_at when device is updated to track validity of token
CREATE OR REPLACE TRIGGER update_push_notification_devices_updated_at
BEFORE UPDATE ON push_notification_devices
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();

--------------------------------------------
-- Notification types, e.g. INCOMING_TOKEN --
--------------------------------------------
CREATE TABLE notification_types (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL UNIQUE
);

INSERT INTO notification_types (name) VALUES
('CONFIRMATION_REQUEST'), -- PENDING_MULTISIG_TRANSACTION
('DELETED_MULTISIG_TRANSACTION'),
('EXECUTED_MULTISIG_TRANSACTION'),
('INCOMING_ETHER'),
('INCOMING_TOKEN'),
('MESSAGE_CONFIRMATION_REQUEST'), -- MESSAGE_CREATED
('MODULE_TRANSACTION');

-------------------------------------------
-- Safe subscriptions for a given device --
-------------------------------------------
CREATE TABLE notification_subscriptions (
id SERIAL PRIMARY KEY,
push_notification_device_id INT NOT NULL,
chain_id VARCHAR(255) NOT NULL,
safe_address VARCHAR(42) NOT NULL,
signer_address VARCHAR(42) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
FOREIGN KEY (push_notification_device_id) REFERENCES push_notification_devices(id) ON DELETE CASCADE,
UNIQUE(chain_id, safe_address, push_notification_device_id, signer_address)
);

-- Update updated_at when a notification subscription is updated
CREATE OR REPLACE TRIGGER update_notification_subscriptions_updated_at
BEFORE UPDATE ON notification_subscriptions
FOR EACH ROW
EXECUTE FUNCTION update_updated_at_column();

----------------------------------------------------
-- Join table for subscription/notification types --
----------------------------------------------------
CREATE TABLE notification_subscription_notification_types (
id SERIAL PRIMARY KEY,
notification_subscription_id INT NOT NULL,
notification_type_id INT NOT NULL,
FOREIGN KEY (notification_subscription_id) REFERENCES notification_subscriptions(id) ON DELETE CASCADE,
FOREIGN KEY (notification_type_id) REFERENCES notification_types(id) ON DELETE CASCADE,
UNIQUE(notification_subscription_id, notification_type_id)
);
Loading
Loading