Skip to content

Commit b113da2

Browse files
committed
fix: add default cli notifs
1 parent 5a5bf80 commit b113da2

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

supabase/functions/_backend/utils/org_email_notifications.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export type EmailPreferenceKey
7575
| 'device_error'
7676
| 'channel_self_rejected'
7777
| 'daily_fail_ratio'
78+
| 'cli_realtime_feed'
7879

7980
export interface EmailPreferences {
8081
usage_limit?: boolean
@@ -89,6 +90,7 @@ export interface EmailPreferences {
8990
device_error?: boolean
9091
channel_self_rejected?: boolean
9192
daily_fail_ratio?: boolean
93+
cli_realtime_feed?: boolean
9294
}
9395

9496
interface OrgWithPreferences {

supabase/functions/_backend/utils/postgres_schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export const users = pgTable('users', {
138138
bundle_deployed: true,
139139
device_error: true,
140140
channel_self_rejected: true,
141+
cli_realtime_feed: true,
141142
}),
142143
})
143144

supabase/functions/_backend/utils/user_preferences.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const EMAIL_PREF_DISABLED_TAGS: Record<EmailPreferenceKey, string> = {
2323
device_error: 'device_error_disabled',
2424
channel_self_rejected: 'channel_self_rejected_disabled',
2525
daily_fail_ratio: 'daily_fail_ratio_disabled',
26+
cli_realtime_feed: 'cli_realtime_feed_disabled',
2627
}
2728

2829
const ALL_LEGACY_TAGS = [NOTIFICATION_TAG, NEWSLETTER_TAG]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- Add cli_realtime_feed preference for users and set default to true
2+
3+
-- Backfill cli_realtime_feed preference for existing users who have email_preferences set
4+
UPDATE public.users
5+
SET email_preferences = email_preferences || '{"cli_realtime_feed": true}'::jsonb
6+
WHERE email_preferences IS NOT NULL
7+
AND NOT (email_preferences ? 'cli_realtime_feed');
8+
9+
-- Update the default value for email_preferences on users table
10+
ALTER TABLE public.users
11+
ALTER COLUMN email_preferences SET DEFAULT '{
12+
"usage_limit": true,
13+
"credit_usage": true,
14+
"onboarding": true,
15+
"weekly_stats": true,
16+
"monthly_stats": true,
17+
"billing_period_stats": true,
18+
"deploy_stats_24h": true,
19+
"bundle_created": true,
20+
"bundle_deployed": true,
21+
"device_error": true,
22+
"channel_self_rejected": true,
23+
"cli_realtime_feed": true
24+
}'::jsonb;
25+
26+
-- Update column comments
27+
COMMENT ON COLUMN public.users.email_preferences IS 'Per-user email notification preferences. Keys: usage_limit, credit_usage, onboarding, weekly_stats, monthly_stats, billing_period_stats, deploy_stats_24h, bundle_created, bundle_deployed, device_error, channel_self_rejected, cli_realtime_feed. Values are booleans.';

supabase/tests/40_test_email_preferences.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ SELECT
7979
AND email_preferences ? 'bundle_created'
8080
AND email_preferences ? 'bundle_deployed'
8181
AND email_preferences ? 'device_error'
82+
AND email_preferences ? 'cli_realtime_feed'
8283
FROM public.users
8384
WHERE id = (SELECT user_id FROM email_pref_context)
8485
),
85-
'email_preferences default contains all 9 preference keys'
86+
'email_preferences default contains all 10 preference keys'
8687
);
8788

8889
-- Test 4: Verify all default values are true
@@ -99,6 +100,7 @@ SELECT
99100
AND (email_preferences ->> 'bundle_created')::boolean = true
100101
AND (email_preferences ->> 'bundle_deployed')::boolean = true
101102
AND (email_preferences ->> 'device_error')::boolean = true
103+
AND (email_preferences ->> 'cli_realtime_feed')::boolean = true
102104
FROM public.users
103105
WHERE id = (SELECT user_id FROM email_pref_context)
104106
),

0 commit comments

Comments
 (0)