Claim each print follow-up before it is sent, and copy launch counts from existing Rules.
This commit is contained in:
1 parent
d9c475a967
commit
214da262df
5 files changed
+108
-21
No files matched your search
@@ -3,6 +3,36 @@ ALTER TABLE "PublishedRule" ADD COLUMN "communityLocation" TEXT;
|
||||
ALTER TABLE "PublishedRule" ADD COLUMN "orgType" TEXT;
|
||||
ALTER TABLE "PublishedRule" ADD COLUMN "followUpEmailSentAt" TIMESTAMP(3);
|
||||
|
||||
-- Copy place and group type already stored on the published document.
|
||||
UPDATE "PublishedRule"
|
||||
SET
|
||||
"communityLocation" = LEFT(
|
||||
NULLIF(
|
||||
BTRIM(REGEXP_REPLACE(COALESCE("document"->>'communityLocation', ''), '[[:space:]]+', ' ', 'g')),
|
||||
''
|
||||
),
|
||||
200
|
||||
),
|
||||
"orgType" = CASE
|
||||
WHEN BTRIM(COALESCE("document"->>'orgType', '')) IN (
|
||||
'dao',
|
||||
'forProfit',
|
||||
'mutualAid',
|
||||
'nonprofit',
|
||||
'openSource',
|
||||
'workersCoop'
|
||||
)
|
||||
THEN BTRIM("document"->>'orgType')
|
||||
ELSE NULL
|
||||
END
|
||||
WHERE jsonb_typeof("document") = 'object';
|
||||
|
||||
-- Close follow-ups for Rules finished more than seven days before this mail
|
||||
-- existed. Newer unsent rows stay eligible until a run claims them.
|
||||
UPDATE "PublishedRule"
|
||||
SET "followUpEmailSentAt" = CURRENT_TIMESTAMP
|
||||
WHERE "createdAt" < CURRENT_TIMESTAMP - INTERVAL '7 days';
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "PublishedRule_orgType_communityLocation_idx" ON "PublishedRule"("orgType", "communityLocation");
|
||||
|
||||
|
||||
@@ -98,7 +98,8 @@ model PublishedRule {
|
||||
communityLocation String?
|
||||
/// Canonical group type id (`workersCoop`, `mutualAid`, …). Used for launch counts.
|
||||
orgType String?
|
||||
/// Set when the 48-hour print follow-up has been sent to the pen-holder.
|
||||
/// Set when the 48-hour print follow-up has been sent, or when a Rule
|
||||
/// finished more than seven days before this mail existed and will not be sent.
|
||||
followUpEmailSentAt DateTime?
|
||||
|
||||
stakeholders RuleStakeholder[]
|
||||
|
||||
Reference in new issue
Block a user