-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure pghistory.track supports concrete inheritance (#164)
- Loading branch information
1 parent
27d8d4a
commit 8a70865
Showing
7 changed files
with
151 additions
and
6 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
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
122 changes: 122 additions & 0 deletions
122
pghistory/tests/migrations/0013_concreteparent_concretechild_concretechildevent_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,122 @@ | ||
# Generated by Django 4.2.6 on 2024-09-11 00:46 | ||
|
||
import django.db.models.deletion | ||
import pgtrigger.compiler | ||
import pgtrigger.migrations | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("pghistory", "0006_delete_aggregateevent"), | ||
("tests", "0012_alter_bigautofieldmodelevent_pgh_context_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="ConcreteParent", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("name", models.CharField(max_length=32)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="ConcreteChild", | ||
fields=[ | ||
( | ||
"concreteparent_ptr", | ||
models.OneToOneField( | ||
auto_created=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
parent_link=True, | ||
primary_key=True, | ||
serialize=False, | ||
to="tests.concreteparent", | ||
), | ||
), | ||
("age", models.IntegerField()), | ||
], | ||
bases=("tests.concreteparent",), | ||
), | ||
migrations.CreateModel( | ||
name="ConcreteChildEvent", | ||
fields=[ | ||
( | ||
"concreteparent_ptr", | ||
models.ForeignKey( | ||
auto_created=True, | ||
db_constraint=False, | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
parent_link=True, | ||
related_name="+", | ||
related_query_name="+", | ||
serialize=False, | ||
to="tests.concreteparent", | ||
), | ||
), | ||
("pgh_id", models.AutoField(primary_key=True, serialize=False)), | ||
("pgh_created_at", models.DateTimeField(auto_now_add=True)), | ||
("pgh_label", models.TextField(help_text="The event label.")), | ||
("age", models.IntegerField()), | ||
( | ||
"pgh_context", | ||
models.ForeignKey( | ||
db_constraint=False, | ||
null=True, | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
related_name="+", | ||
to="pghistory.context", | ||
), | ||
), | ||
( | ||
"pgh_obj", | ||
models.ForeignKey( | ||
db_constraint=False, | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
related_name="events", | ||
to="tests.concretechild", | ||
), | ||
), | ||
], | ||
options={ | ||
"abstract": False, | ||
}, | ||
), | ||
pgtrigger.migrations.AddTrigger( | ||
model_name="concretechild", | ||
trigger=pgtrigger.compiler.Trigger( | ||
name="insert_insert", | ||
sql=pgtrigger.compiler.UpsertTriggerSql( | ||
func='INSERT INTO "tests_concretechildevent" ("age", "concreteparent_ptr_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."age", NEW."concreteparent_ptr_id", _pgh_attach_context(), NOW(), \'insert\', NEW."concreteparent_ptr_id"); RETURN NULL;', # noqa: E501 | ||
hash="5740a1af0415e809c3fec2214084f412670d95f9", | ||
operation="INSERT", | ||
pgid="pgtrigger_insert_insert_a6cf2", | ||
table="tests_concretechild", | ||
when="AFTER", | ||
), | ||
), | ||
), | ||
pgtrigger.migrations.AddTrigger( | ||
model_name="concretechild", | ||
trigger=pgtrigger.compiler.Trigger( | ||
name="update_update", | ||
sql=pgtrigger.compiler.UpsertTriggerSql( | ||
condition='WHEN (OLD."age" IS DISTINCT FROM (NEW."age") OR OLD."concreteparent_ptr_id" IS DISTINCT FROM (NEW."concreteparent_ptr_id"))', # noqa: E501 | ||
func='INSERT INTO "tests_concretechildevent" ("age", "concreteparent_ptr_id", "pgh_context_id", "pgh_created_at", "pgh_label", "pgh_obj_id") VALUES (NEW."age", NEW."concreteparent_ptr_id", _pgh_attach_context(), NOW(), \'update\', NEW."concreteparent_ptr_id"); RETURN NULL;', # noqa: E501 | ||
hash="3bbc47abd3ad6a8677edfd77204000b426c45357", | ||
operation="UPDATE", | ||
pgid="pgtrigger_update_update_1163f", | ||
table="tests_concretechild", | ||
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
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