Skip to content

Commit

Permalink
fix(data-warehouse): add edit to materialized views (#25400)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
EDsCODE and github-actions[bot] authored Oct 9, 2024
1 parent 25f7fa6 commit 7e12e54
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 13 deletions.
8 changes: 7 additions & 1 deletion frontend/src/lib/components/DatabaseTableTree/TreeRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,27 @@ export function TreeFolderRow({ item, depth, onClick, selectedRow, dropdownOverl
if (item.table.status === 'Failed') {
return `Materialization failed`
}
if (item.table.status === 'Modified') {
return `View definition modified since last materialization`
}
if (item.table.status === 'Completed') {
return `Last materialized ${humanFriendlyDetailedTime(item.table.last_run_at)}`
}
}
return ''
}

const getIconColor = (): 'text-primary' | 'text-danger' | 'text-success' => {
const getIconColor = (): 'text-primary' | 'text-danger' | 'text-warning' | 'text-success' => {
if (item.table?.type === 'materialized_view') {
if (item.table.status === 'Running') {
return 'text-primary'
}
if (item.table.status === 'Failed') {
return 'text-danger'
}
if (item.table.status === 'Modified') {
return 'text-warning'
}
}
return 'text-success'
}
Expand Down
23 changes: 12 additions & 11 deletions frontend/src/scenes/data-warehouse/external/DataWarehouseTables.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,18 @@ export const DatabaseTableTreeWithItems = ({ inline }: DatabaseTableTreeProps):
>
Add join
</LemonButton>
{table.type == 'view' && (
<LemonButton
onClick={() => {
router.actions.push(urls.dataWarehouseView(table.id))
}}
data-attr="schema-list-item-edit"
fullWidth
>
Edit view definition
</LemonButton>
)}
{table.type == 'view' ||
(table.type == 'materialized_view' && (
<LemonButton
onClick={() => {
router.actions.push(urls.dataWarehouseView(table.id))
}}
data-attr="schema-list-item-edit"
fullWidth
>
Edit view definition
</LemonButton>
))}
{featureFlags[FEATURE_FLAGS.DATA_MODELING] && table.type === 'view' && (
<LemonButton
onClick={() => {
Expand Down
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: 0484_productintent
posthog: 0485_alter_datawarehousesavedquery_status
sessions: 0001_initial
social_django: 0010_uid_db_index
two_factor: 0007_auto_20201201_1019
28 changes: 28 additions & 0 deletions posthog/migrations/0485_alter_datawarehousesavedquery_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.15 on 2024-10-04 15:59

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("posthog", "0484_productintent"),
]

operations = [
migrations.AlterField(
model_name="datawarehousesavedquery",
name="status",
field=models.CharField(
choices=[
("Cancelled", "Cancelled"),
("Modified", "Modified"),
("Completed", "Completed"),
("Failed", "Failed"),
("Running", "Running"),
],
help_text="The status of when this SavedQuery last ran.",
max_length=64,
null=True,
),
),
]
1 change: 1 addition & 0 deletions posthog/warehouse/api/saved_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def update(self, instance: Any, validated_data: Any) -> Any:
try:
view.columns = view.get_columns()
view.external_tables = view.s3_tables
view.status = DataWarehouseSavedQuery.Status.MODIFIED
except RecursionError:
raise serializers.ValidationError("Model contains a cycle")

Expand Down
1 change: 1 addition & 0 deletions posthog/warehouse/models/datawarehouse_saved_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Status(models.TextChoices):
"""Possible states of this SavedQuery."""

CANCELLED = "Cancelled"
MODIFIED = "Modified" # if the model definition has changed and hasn't been materialized since
COMPLETED = "Completed"
FAILED = "Failed"
RUNNING = "Running"
Expand Down

0 comments on commit 7e12e54

Please sign in to comment.