diff --git a/spp_analytics/models/service_cache.py b/spp_analytics/models/service_cache.py index 0140c466..e03f42e2 100644 --- a/spp_analytics/models/service_cache.py +++ b/spp_analytics/models/service_cache.py @@ -413,13 +413,10 @@ class AnalyticsCacheEntry(models.Model): help="When this result was computed", ) - _sql_constraints = [ - ( - "cache_key_unique", - "UNIQUE(cache_key)", - "Cache key must be unique", - ), - ] + _cache_key_unique = models.Constraint( + "UNIQUE(cache_key)", + "Cache key must be unique", + ) @api.model def cron_cleanup_expired(self): diff --git a/spp_metric/models/metric_category.py b/spp_metric/models/metric_category.py index 948b42b1..4238fb77 100644 --- a/spp_metric/models/metric_category.py +++ b/spp_metric/models/metric_category.py @@ -59,7 +59,7 @@ class MetricCategory(models.Model): help="Parent category for hierarchical organization", ) - _sql_constraints = [("code_unique", "UNIQUE(code)", "Category code must be unique!")] + _code_unique = models.Constraint("UNIQUE(code)", "Category code must be unique!") @api.constrains("parent_id") def _check_parent_recursion(self): diff --git a/spp_metric/tests/test_metric_category.py b/spp_metric/tests/test_metric_category.py index 0e0069ab..523ca610 100644 --- a/spp_metric/tests/test_metric_category.py +++ b/spp_metric/tests/test_metric_category.py @@ -30,7 +30,7 @@ def test_category_code_unique(self): This test verifies the constraint is defined in the model. """ # Verify the SQL constraint is defined - constraints = {name for name, _, _ in self.env["spp.metric.category"]._sql_constraints} + constraints = {obj.name for obj in self.env["spp.metric.category"]._table_objects.values()} self.assertIn("code_unique", constraints, "SQL unique constraint should be defined for code field") def test_category_parent_child(self): diff --git a/spp_scoring/models/scoring_invalid_value.py b/spp_scoring/models/scoring_invalid_value.py index 45ef31db..083e8346 100644 --- a/spp_scoring/models/scoring_invalid_value.py +++ b/spp_scoring/models/scoring_invalid_value.py @@ -57,13 +57,10 @@ class SppScoringInvalidValue(models.Model): ), ) - _sql_constraints = [ - ( - "spp_scoring_invalid_value_name_uniq", - "unique(name)", - "An invalid-value entry with this string already exists.", - ), - ] + _name_uniq = models.Constraint( + "unique(name)", + "An invalid-value entry with this string already exists.", + ) @api.constrains("name", "match_type") def _check_regex_compiles(self):