fix: the database starts again after an e-mail change notice exists

schema.sql defined the e-mail kinds constraint twice: the signup commit's
copy without "notice", and the e-mail change commit's with it. The schema
runs on every start, so once a "notice" e-mail existed the first copy was
refused and db-init restarted for ever. It is defined once now, and
tests/test_schema fails on any constraint added twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-15 13:18:21 -03:00
parent 7383e44ff4
commit 69997f4598
3 changed files with 25 additions and 6 deletions

View File

@@ -283,11 +283,6 @@ ALTER TABLE dtf_local.orders ADD COLUMN IF NOT EXISTS contact_since timestamptz;
ALTER TABLE dtf_local.orders ADD COLUMN IF NOT EXISTS contact_by text;
ALTER TABLE dtf_local.orders ADD COLUMN IF NOT EXISTS contact_note text;
-- E-mail kinds: a password-recovery link, a signup code, the notice that an
-- account already exists, the team's alerts and a test.
ALTER TABLE dtf_local.mail_queue DROP CONSTRAINT IF EXISTS mail_queue_kind_check;
ALTER TABLE dtf_local.mail_queue ADD CONSTRAINT mail_queue_kind_check
CHECK(kind IN ('reset','code','account','alert','test'));
-- A signup waiting for its e-mail code. The account is created only when the
-- code is entered; the password is already hashed and the code only hashed.
CREATE TABLE IF NOT EXISTS dtf_local.account_signups (
@@ -306,6 +301,10 @@ CREATE TABLE IF NOT EXISTS dtf_local.email_changes (
sent_at timestamptz NOT NULL DEFAULT now(), expires_at timestamptz NOT NULL,
sends int NOT NULL DEFAULT 1, attempts int NOT NULL DEFAULT 0, done_at timestamptz
);
-- E-mail kinds: a password-recovery link, a code, the notice that an account
-- already exists, the notice of a changed e-mail, the team's alerts and a test.
-- Defined once, here: the schema runs on every start, and an earlier, narrower
-- copy would refuse the rows of the kinds added after it.
ALTER TABLE dtf_local.mail_queue DROP CONSTRAINT IF EXISTS mail_queue_kind_check;
ALTER TABLE dtf_local.mail_queue ADD CONSTRAINT mail_queue_kind_check
CHECK(kind IN ('reset','code','account','notice','alert','test'));