Skip to content

Commit

Permalink
chore(data-warehouse): Implemented soft deletes for data warehouse mo…
Browse files Browse the repository at this point in the history
…dels (#24392)

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Gilbert09 and github-actions[bot] authored Aug 15, 2024
1 parent dd2a0a9 commit 17ae6d1
Show file tree
Hide file tree
Showing 13 changed files with 318 additions and 56 deletions.
2 changes: 1 addition & 1 deletion latest_migrations.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ contenttypes: 0002_remove_content_type_name
ee: 0016_rolemembership_organization_member
otp_static: 0002_throttling
otp_totp: 0002_auto_20190420_0723
posthog: 0456_hogfunction_masking
posthog: 0457_datawarehousejoin_deleted_at_and_more
sessions: 0001_initial
social_django: 0010_uid_db_index
two_factor: 0007_auto_20201201_1019
11 changes: 7 additions & 4 deletions posthog/hogql/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,8 @@ def define_mappings(warehouse: dict[str, Table], get_table: Callable):
else:
warehouse_tables = define_mappings(
warehouse_tables,
lambda team, warehouse_modifier: DataWarehouseTable.objects.filter(
team_id=team.pk, name=warehouse_modifier.table_name
)
lambda team, warehouse_modifier: DataWarehouseTable.objects.exclude(deleted=True)
.filter(team_id=team.pk, name=warehouse_modifier.table_name)
.select_related("credential", "external_data_source")
.latest("created_at"),
)
Expand Down Expand Up @@ -512,7 +511,11 @@ def serialize_database(
else []
)
warehouse_schemas = (
list(ExternalDataSchema.objects.filter(table_id__in=[table.id for table in warehouse_tables]).all())
list(
ExternalDataSchema.objects.exclude(deleted=True)
.filter(table_id__in=[table.id for table in warehouse_tables])
.all()
)
if len(warehouse_tables) > 0
else []
)
Expand Down
72 changes: 72 additions & 0 deletions posthog/migrations/0457_datawarehousejoin_deleted_at_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Generated by Django 4.2.14 on 2024-08-15 10:41

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("posthog", "0456_hogfunction_masking"),
]

operations = [
migrations.AddField(
model_name="datawarehousejoin",
name="deleted_at",
field=models.DateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name="datawarehousesavedquery",
name="deleted_at",
field=models.DateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name="datawarehousetable",
name="deleted_at",
field=models.DateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name="datawarehouseviewlink",
name="deleted_at",
field=models.DateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name="externaldataschema",
name="deleted",
field=models.BooleanField(blank=True, default=False, null=True),
),
migrations.AddField(
model_name="externaldataschema",
name="deleted_at",
field=models.DateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name="externaldatasource",
name="deleted",
field=models.BooleanField(blank=True, default=False, null=True),
),
migrations.AddField(
model_name="externaldatasource",
name="deleted_at",
field=models.DateTimeField(blank=True, null=True),
),
migrations.AlterField(
model_name="datawarehousejoin",
name="deleted",
field=models.BooleanField(blank=True, default=False, null=True),
),
migrations.AlterField(
model_name="datawarehousesavedquery",
name="deleted",
field=models.BooleanField(blank=True, default=False, null=True),
),
migrations.AlterField(
model_name="datawarehousetable",
name="deleted",
field=models.BooleanField(blank=True, default=False, null=True),
),
migrations.AlterField(
model_name="datawarehouseviewlink",
name="deleted",
field=models.BooleanField(blank=True, default=False, null=True),
),
]
3 changes: 2 additions & 1 deletion posthog/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ class Meta:


class DeletedMetaFields(models.Model):
deleted: models.BooleanField = models.BooleanField(null=True, blank=True)
deleted: models.BooleanField = models.BooleanField(null=True, blank=True, default=False)
deleted_at: models.DateTimeField = models.DateTimeField(null=True, blank=True)

class Meta:
abstract = True
Expand Down
Loading

0 comments on commit 17ae6d1

Please sign in to comment.