Skip to content

Conversation

@hanars
Copy link
Collaborator

@hanars hanars commented Dec 16, 2025

Creates a django model class for materialized views and moves all of our existing materialized views from templated RunSql definitions into these models. This makes it clearer what "tables" exist in the database and their relationship to one another just by looking at the models files and not needing to go back through old migrations to find definitions

"model": "clickhouse_search.keylookupsnvindel",
"pk": "1-10439-AC-A",
"fields": {
"key": 1,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than directly insert fixture rows into the clinvar join table, insert into the all variants tables and rely on the materialized view to work correctly. Changing the data like this ensures that out unit tests will catch if those views stop working as intended

@hanars hanars marked this pull request as ready for review December 17, 2025 21:49
@hanars hanars requested a review from bpblanken December 17, 2025 21:49

class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):

def _is_materialzed_view(self, model):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_is_materialzed_view -> _is_materialized_view


def _get_materialized_view_engine_expression(self, model):
sql = f'TO {self._table_name(model._meta, model._meta.to_table)}'
if getattr(model._meta, 'refreshable', False):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One feature that was added in the new reference data views that wasn't in the existing ones was the EMPTY keyword, which prevents an immediate refresh when the view is created.

It's less important for the gt_stats views (when they are created everything should be empty), but we should have support for it, and default to using it, going forwards.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is an example

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to keep this out of scope for now and when I move the reference data views to be defined as models I will extend the behavior

@hanars hanars requested a review from bpblanken January 8, 2026 21:29
@hanars hanars merged commit 521b75b into dev Jan 9, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants