-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(api): fix trigger order on token CASCADE policy deletion, fixes #995
- Loading branch information
1 parent
a7d2cc7
commit 84fccc4
Showing
3 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
api/desecapi/migrations/0041_remove_token_token_auto_policy_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Generated by Django 5.1.3 on 2024-12-02 10:59 | ||
|
||
import pgtrigger.compiler | ||
import pgtrigger.migrations | ||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("desecapi", "0040_token_auto_policy_token_token_auto_policy_and_more"), | ||
] | ||
|
||
operations = [ | ||
pgtrigger.migrations.RemoveTrigger( | ||
model_name="token", | ||
name="token_auto_policy", | ||
), | ||
pgtrigger.migrations.RemoveTrigger( | ||
model_name="tokendomainpolicy", | ||
name="default_policy_when_auto_policy", | ||
), | ||
pgtrigger.migrations.AddTrigger( | ||
model_name="token", | ||
trigger=pgtrigger.compiler.Trigger( | ||
name="token_auto_policy", | ||
sql=pgtrigger.compiler.UpsertTriggerSql( | ||
constraint="CONSTRAINT", | ||
func="\n IF\n NEW.auto_policy = true AND NOT EXISTS(\n SELECT * FROM desecapi_tokendomainpolicy WHERE token_id = NEW.id AND domain_id IS NULL AND subname IS NULL AND type IS NULL\n )\n THEN\n RAISE EXCEPTION 'Token auto policy without a default policy is not allowed. (token.id=%s)', NEW.id;\n END IF;\n RETURN NULL;\n ", | ||
hash="a940f3a622b7ffdb0dbf5e3de88e28932d6d4c6c", | ||
operation='INSERT OR UPDATE OF "auto_policy"', | ||
pgid="pgtrigger_token_auto_policy_8e6d9", | ||
table="desecapi_token", | ||
timing="DEFERRABLE INITIALLY DEFERRED", | ||
when="AFTER", | ||
), | ||
), | ||
), | ||
pgtrigger.migrations.AddTrigger( | ||
model_name="tokendomainpolicy", | ||
trigger=pgtrigger.compiler.Trigger( | ||
name="default_policy_when_auto_policy", | ||
sql=pgtrigger.compiler.UpsertTriggerSql( | ||
constraint="CONSTRAINT", | ||
func="\n IF\n OLD.domain_id IS NULL AND OLD.subname IS NULL AND OLD.type IS NULL AND (SELECT auto_policy FROM desecapi_token WHERE id = OLD.token_id) = true\n THEN\n RAISE EXCEPTION 'Cannot delete default policy while auto_policy is in effect. (tokendomainpolicy.id=%)', OLD.id;\n END IF;\n RETURN OLD;\n ", | ||
hash="2e38bd8be24da066472012dac4c30f3818b35ca0", | ||
operation="DELETE", | ||
pgid="pgtrigger_default_policy_when_auto_policy_a1fd2", | ||
table="desecapi_tokendomainpolicy", | ||
timing="DEFERRABLE INITIALLY DEFERRED", | ||
when="AFTER", | ||
), | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters