Repository navigation
User notifications to people, step 1: the migration and the store - #95
Merged
Merged
Conversation
Migration 00165 and the store code behind the notifications to people (spec notifications-panel-spec, PR 1): the bot of its own, the chats of the people who linked one with their one-time codes, the outbox user_notice, the incidents and the settings. No service, RPC or UI yet. - user_notice is an outbox with at-least-once delivery: dedupe, a lease taken and given back by id, approval for the owner's drafts. A dismissed or expired draft is finished at once (done_at and a result of the same name), so retention purges it. - A failure draft is one per incident while the rows are one per person: draft_id groups them, and approving, dismissing or expiring the draft decides every row (SetUserNoticeApprovalByDraft, ExpireUserNoticeApprovals). - One open incident per person, by a partial unique index; OpenUserIncident returns the open one with ErrUserIncidentOpen. - A chat links atomically against the limit (the insert holds the check); ErrUserTelegramChatLimit, ErrUserTelegramChatTaken. - A different bot, or none, drops the chats, the pending codes and the Telegram channel of the unfinished notices. - Finish and Retry never overwrite what the app writes (the devices that pulled an event); Retry keeps the message ids so a retry sends to the chats that have not got it. - draft_id and incident_id are NULL when absent, so a partial index covers only the rows that have one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hat id Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t and chats Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s it; schema goldens Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Step 1 of the notifications to people (plan: Telegram bot for people + events for the Mistgate app). Storage only: no service, RPC or UI yet.
What
Migration
00165_user_notify.sqland the store for:user_telegram_bot: the people's bot (separate from the admins' one); the token is vault ciphertext.user_telegram_chat: linked chats, the chat id sealed (chat_enc) and found by keyed MAC (chat_mac); the per-person limit is enforced inside the insert.user_telegram_code: one-time link codes, one active per person.user_notice: the outbox for both channels (Telegram = 1, app = 2), with dedupe, leases, retries, owner drafts (approval,draft_id: one failure draft per incident covers every affected person) and Telegram message refs keyed by chat row id for editing an incident message.user_incident: at most one open per person (partial unique index).user_notify_setting/user_notify_override: global and per-person settings; defaults live in code.Replacing or clearing the bot drops chats, codes and the Telegram channel of unfinished notices; app delivery stays.
Tests
go test ./internal/panel/store/...(table tests: chat limit race on the last slot, code races, lease exclusivity with 4 workers, draft approve/expire, purge, incidents, cascade, migration up/down); schema snapshots updated;scripts/test-edge-store.ps1passes (fake D1).🤖 Generated with Claude Code