| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
ALTER TABLE lists DROP CONSTRAINT IF EXISTS lists_kind_check; |
| 22 |
ALTER TABLE lists ADD CONSTRAINT lists_kind_check CHECK (kind IN ( |
| 23 |
'content', 'devlog', 'patches', 'releases', |
| 24 |
'issues', 'announce', 'marketing', |
| 25 |
'sale', 'follower', 'login', 'status', 'tip' |
| 26 |
)); |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
INSERT INTO lists (scope, scope_id, kind, title, required, owner_id) VALUES |
| 38 |
('platform', NULL, 'sale', 'Sales', FALSE, NULL), |
| 39 |
('platform', NULL, 'follower', 'New followers', FALSE, NULL), |
| 40 |
('platform', NULL, 'releases', 'Releases you follow', FALSE, NULL), |
| 41 |
('platform', NULL, 'issues', 'Issue activity', FALSE, NULL), |
| 42 |
('platform', NULL, 'status', 'Platform status', FALSE, NULL), |
| 43 |
('platform', NULL, 'tip', 'Tips', FALSE, NULL), |
| 44 |
('platform', NULL, 'login', 'Sign-in alerts', TRUE, NULL) |
| 45 |
ON CONFLICT DO NOTHING; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
INSERT INTO list_subscriptions (list_id, user_id, state, source, created_at, unsubscribed_at) |
| 52 |
SELECT l.id, |
| 53 |
u.id, |
| 54 |
CASE WHEN pref.enabled THEN 'confirmed' ELSE 'unsubscribed' END, |
| 55 |
'import', |
| 56 |
u.created_at, |
| 57 |
CASE WHEN pref.enabled THEN NULL ELSE NOW() END |
| 58 |
FROM users u |
| 59 |
CROSS JOIN LATERAL (VALUES |
| 60 |
('sale', u.notify_sale), |
| 61 |
('follower', u.notify_follower), |
| 62 |
('releases', u.notify_release), |
| 63 |
('issues', u.notify_issues), |
| 64 |
('status', u.notify_status), |
| 65 |
('tip', u.notify_tip), |
| 66 |
('login', u.login_notification_enabled) |
| 67 |
) AS pref(kind, enabled) |
| 68 |
JOIN lists l ON l.scope = 'platform' AND l.kind = pref.kind |
| 69 |
ON CONFLICT DO NOTHING; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
INSERT INTO consent_events (subscription_id, event, at, evidence) |
| 75 |
SELECT ls.id, |
| 76 |
'import', |
| 77 |
ls.created_at, |
| 78 |
'Backfilled from the users.notify_* column of the same name. The columns ' |
| 79 |
|| 'recorded only the current value, so the date is the account''s and no ' |
| 80 |
|| 'record of the original choice survives.' |
| 81 |
FROM list_subscriptions ls |
| 82 |
JOIN lists l ON l.id = ls.list_id |
| 83 |
WHERE l.scope = 'platform' |
| 84 |
AND l.kind IN ('sale', 'follower', 'releases', 'issues', 'status', 'tip', 'login') |
| 85 |
AND ls.source = 'import' |
| 86 |
AND NOT EXISTS ( |
| 87 |
SELECT 1 FROM consent_events ce |
| 88 |
WHERE ce.subscription_id = ls.id AND ce.event = 'import' |
| 89 |
); |
| 90 |
|