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:
@@ -86,7 +86,7 @@ jobs:
|
||||
# the generator's geometry. The provider suites use a fake transport: they
|
||||
# prove the documented contract, not the integration.
|
||||
- name: Print-file geometry and provider adapters
|
||||
run: $COMPOSE exec -T api python -m unittest tests.test_printfile tests.test_mercadopago tests.test_tiny tests.test_cnpj tests.test_payment_messages tests.test_jadlog tests.test_quote_review tests.test_large_files tests.test_grade_check -v
|
||||
run: $COMPOSE exec -T api python -m unittest tests.test_printfile tests.test_mercadopago tests.test_tiny tests.test_cnpj tests.test_payment_messages tests.test_jadlog tests.test_quote_review tests.test_large_files tests.test_grade_check tests.test_schema -v
|
||||
|
||||
- name: Runtime and retention regressions
|
||||
run: |
|
||||
|
||||
@@ -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'));
|
||||
|
||||
20
tests/test_schema.py
Normal file
20
tests/test_schema.py
Normal file
@@ -0,0 +1,20 @@
|
||||
"""The schema runs on every start (app/bootstrap.py), so each constraint it
|
||||
re-adds must be defined once: an earlier, narrower copy would refuse rows
|
||||
written under a later one, and the database would never finish starting.
|
||||
Run from the repository root: python3 -m unittest tests.test_schema
|
||||
"""
|
||||
import re
|
||||
import unittest
|
||||
from collections import Counter
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class SchemaTest(unittest.TestCase):
|
||||
def test_each_constraint_is_added_once(self):
|
||||
schema = Path(__file__).resolve().parent.parent.joinpath('app', 'schema.sql').read_text()
|
||||
added = Counter(re.findall(r'ADD CONSTRAINT\s+(\w+)', schema, re.I))
|
||||
self.assertEqual([name for name, count in added.items() if count > 1], [])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user