Skip to content

Commit

Permalink
feat: add table and raw data source last updated at (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna authored Feb 4, 2024
1 parent 6ac6da4 commit 0902d5c
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions bd_api/apps/api/v1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,14 +837,30 @@ def get_graphql_contains_information_requests(self):
"""Returns true if there are information requests in the dataset for graphql"""
return self.contains_information_requests

@property
def table_last_updated_at(self):
updates = [
u.last_updated_at for u in self.tables.all()
if u.last_updated_at
] # fmt: skip
return max(updates) if updates else None

def get_graphql_table_last_updated_at(self):
return self.table_last_updated_at

@property
def raw_data_source_last_updated_at(self):
updates = [
u.last_updated_at for u in self.raw_data_sources.all()
if u.last_updated_at
] # fmt: skip
return max(updates) if updates else None

def get_graphql_raw_data_source_last_updated_at(self):
return self.raw_data_source_last_updated_at

class Update(BaseModel):
"""
Update model
Informations about the update of a model - frequency, lag, latest update
Can be linked to a table, a raw data source or an information request
"""

class Update(BaseModel):
id = models.UUIDField(primary_key=True, default=uuid4)
entity = models.ForeignKey(
"Entity", on_delete=models.CASCADE, related_name="updates"
Expand Down Expand Up @@ -1158,6 +1174,14 @@ def get_graphql_neighbors(self) -> list[dict]:
)
return get_unique_list(all_neighbors)

@property
def last_updated_at(self):
updates = [u.latest for u in self.updates.all() if u.latest]
return max(updates) if updates else None

def get_graphql_last_updated_at(self):
return self.last_updated_at

def clean(self):
"""
Clean method for Table model
Expand Down Expand Up @@ -1586,6 +1610,14 @@ class Meta:
def __str__(self):
return f"{self.name} ({self.dataset.name})"

@property
def last_updated_at(self):
updates = [u.latest for u in self.updates.all() if u.latest]
return max(updates) if updates else None

def get_graphql_last_updated_at(self):
return self.last_updated_at


class InformationRequest(BaseModel, OrderedModel):
"""Model definition for InformationRequest."""
Expand Down

0 comments on commit 0902d5c

Please sign in to comment.