-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(data-modeling): Data modelling django models and API (#24232)
Co-authored-by: Eric Duong <[email protected]>
- Loading branch information
1 parent
cf88e8d
commit f5792a6
Showing
13 changed files
with
1,235 additions
and
46 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
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
74 changes: 74 additions & 0 deletions
74
posthog/migrations/0463_datawarehousemodelpath_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,74 @@ | ||
# Generated by Django 4.2.14 on 2024-08-12 12:04 | ||
|
||
import django.contrib.postgres.indexes | ||
import django.db.models.constraints | ||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
import posthog.models.utils | ||
import posthog.warehouse.models.modeling | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("posthog", "0462_change_replay_team_setting_defaults"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunSQL("CREATE EXTENSION ltree;", reverse_sql="DROP EXTENSION ltree;"), | ||
migrations.CreateModel( | ||
name="DataWarehouseModelPath", | ||
fields=[ | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
("updated_at", models.DateTimeField(auto_now=True, null=True)), | ||
( | ||
"id", | ||
models.UUIDField( | ||
default=posthog.models.utils.UUIDT, editable=False, primary_key=True, serialize=False | ||
), | ||
), | ||
("path", posthog.warehouse.models.modeling.LabelTreeField()), | ||
( | ||
"created_by", | ||
models.ForeignKey( | ||
blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL | ||
), | ||
), | ||
( | ||
"saved_query", | ||
models.ForeignKey( | ||
default=None, | ||
null=True, | ||
on_delete=django.db.models.deletion.SET_NULL, | ||
to="posthog.datawarehousesavedquery", | ||
), | ||
), | ||
( | ||
"table", | ||
models.ForeignKey( | ||
default=None, | ||
null=True, | ||
on_delete=django.db.models.deletion.SET_NULL, | ||
to="posthog.datawarehousetable", | ||
), | ||
), | ||
("team", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="posthog.team")), | ||
], | ||
options={ | ||
"indexes": [ | ||
models.Index(fields=["team_id", "path"], name="team_id_path"), | ||
models.Index(fields=["team_id", "saved_query_id"], name="team_id_saved_query_id"), | ||
django.contrib.postgres.indexes.GistIndex(models.F("path"), name="model_path_path"), | ||
], | ||
}, | ||
), | ||
migrations.AddConstraint( | ||
model_name="datawarehousemodelpath", | ||
constraint=models.UniqueConstraint( | ||
deferrable=django.db.models.constraints.Deferrable["IMMEDIATE"], | ||
fields=("team_id", "path"), | ||
name="unique_team_id_path", | ||
), | ||
), | ||
] |
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,29 @@ | ||
from rest_framework import request, response, serializers, viewsets | ||
|
||
from posthog.api.routing import TeamAndOrgViewSetMixin | ||
from posthog.api.shared import UserBasicSerializer | ||
from posthog.warehouse.models import DataWarehouseModelPath | ||
|
||
|
||
class DataWarehouseModelPathSerializer(serializers.ModelSerializer): | ||
created_by = UserBasicSerializer(read_only=True) | ||
|
||
class Meta: | ||
model = DataWarehouseModelPath | ||
|
||
|
||
class DataWarehouseModelPathViewSet(TeamAndOrgViewSetMixin, viewsets.ReadOnlyModelViewSet): | ||
scope_object = "INTERNAL" | ||
|
||
queryset = DataWarehouseModelPath.objects.all() | ||
serializer_class = DataWarehouseModelPathSerializer | ||
|
||
|
||
class DataWarehouseModelDagViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet): | ||
scope_object = "INTERNAL" | ||
|
||
def list(self, request: request.Request, *args, **kwargs) -> response.Response: | ||
"""Return this team's DAG as a set of edges and nodes""" | ||
dag = DataWarehouseModelPath.objects.get_dag(self.team) | ||
|
||
return response.Response({"edges": dag.edges, "nodes": dag.nodes}) |
Oops, something went wrong.