mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-15 08:12:18 -06:00
Add constraints to enforce v1/v2-dependent fields
This commit is contained in:
@@ -72,4 +72,29 @@ class Migration(migrations.Migration):
|
||||
name='hmac_digest',
|
||||
field=models.CharField(blank=True, max_length=64, null=True),
|
||||
),
|
||||
|
||||
# Add constraints to enforce v1/v2-dependent fields
|
||||
migrations.AddConstraint(
|
||||
model_name='token',
|
||||
constraint=models.CheckConstraint(
|
||||
name='enforce_version_dependent_fields',
|
||||
condition=models.Q(
|
||||
models.Q(
|
||||
('hmac_digest__isnull', True),
|
||||
('key__isnull', True),
|
||||
('pepper_id__isnull', True),
|
||||
('plaintext__isnull', False),
|
||||
('version', 1)
|
||||
),
|
||||
models.Q(
|
||||
('hmac_digest__isnull', False),
|
||||
('key__isnull', False),
|
||||
('pepper_id__isnull', False),
|
||||
('plaintext__isnull', True),
|
||||
('version', 2)
|
||||
),
|
||||
_connector='OR'
|
||||
)
|
||||
)
|
||||
),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user