diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index a9221dc..beffdb3 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -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: | diff --git a/app/schema.sql b/app/schema.sql index b9fbd02..927e0df 100644 --- a/app/schema.sql +++ b/app/schema.sql @@ -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')); diff --git a/tests/test_schema.py b/tests/test_schema.py new file mode 100644 index 0000000..04a6893 --- /dev/null +++ b/tests/test_schema.py @@ -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()