-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore primary key field defaults and support for
create()
#10958
- Loading branch information
1 parent
7362455
commit bc800e3
Showing
10 changed files
with
817 additions
and
393 deletions.
There are no files selected for viewing
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,7 @@ | ||
from django.db import models | ||
|
||
|
||
class UUID4(models.Func): | ||
function = "uuid_generate_v4" | ||
arity = 0 | ||
output_field = models.UUIDField() |
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
110 changes: 110 additions & 0 deletions
110
arches/app/models/migrations/10957_refactor_relations_rule.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,110 @@ | ||
# Generated by Django 5.2a1 on 2025-02-12 10:28 | ||
|
||
import django.db.models.functions.text | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("models", "11725_make_tiledata_not_nullable"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunSQL( | ||
""" | ||
DROP RULE relations_check_insert ON relations; | ||
DROP RULE relations_check_update ON relations; | ||
DROP FUNCTION public.__arches_check_dup_relations( | ||
p_conceptid1 uuid, | ||
p_conceptid2 uuid, | ||
p_relationtype text); | ||
""", | ||
""" | ||
CREATE OR REPLACE FUNCTION public.__arches_check_dup_relations( | ||
p_conceptid1 uuid, | ||
p_conceptid2 uuid, | ||
p_relationtype text) | ||
RETURNS text | ||
LANGUAGE 'plpgsql' | ||
COST 100 | ||
VOLATILE | ||
AS $BODY$ | ||
declare | ||
v_return text; | ||
BEGIN | ||
IF | ||
( SELECT count(*) from relations | ||
WHERE 1=1 | ||
AND conceptidfrom = p_conceptid1 | ||
AND conceptidto = p_conceptid2 | ||
AND relationtype = p_relationtype ) > 0 | ||
THEN v_return = 'duplicate'; | ||
ELSIF | ||
( SELECT count(*) from relations | ||
WHERE 1=1 | ||
AND conceptidfrom = p_conceptid2 | ||
AND conceptidto = p_conceptid1 | ||
AND relationtype = p_relationtype ) > 0 | ||
THEN v_return = 'duplicate'; | ||
ELSE v_return = 'unique'; | ||
END IF; | ||
RETURN v_return; | ||
END; | ||
$BODY$; | ||
CREATE OR REPLACE RULE relations_check_insert AS ON INSERT TO relations | ||
WHERE (select * from __arches_check_dup_relations(new.conceptidfrom,new.conceptidto,new.relationtype)) = 'duplicate' | ||
DO INSTEAD NOTHING; | ||
CREATE OR REPLACE RULE relations_check_update AS ON UPDATE TO relations | ||
WHERE (select * from __arches_check_dup_relations(new.conceptidfrom,new.conceptidto,new.relationtype)) = 'duplicate' | ||
DO INSTEAD NOTHING; | ||
""", | ||
), | ||
migrations.AlterUniqueTogether( | ||
name="relation", | ||
unique_together=set(), | ||
), | ||
migrations.AddConstraint( | ||
model_name="relation", | ||
constraint=models.UniqueConstraint( | ||
models.Case( | ||
models.When( | ||
django.db.models.expressions.CombinedExpression( | ||
models.F("conceptfrom"), | ||
"<", | ||
models.F("conceptto"), | ||
output_field=models.BooleanField(), | ||
), | ||
then=django.db.models.functions.text.Concat( | ||
models.F("conceptfrom"), | ||
models.Value(","), | ||
models.F("conceptto"), | ||
output_field=models.TextField(), | ||
), | ||
), | ||
default=django.db.models.functions.text.Concat( | ||
models.F("conceptto"), | ||
models.Value(","), | ||
models.F("conceptfrom"), | ||
output_field=models.TextField(), | ||
), | ||
), | ||
models.F("relationtype"), | ||
name="unique_relation_bidirectional", | ||
), | ||
), | ||
] |
Oops, something went wrong.