"""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()