Skip to content

Record view dependencies and recreate dependent views when needed #35

@dolfandringa

Description

@dolfandringa

For discussion:
I am using DBViews where one view selects data from another view. In my use-case I do it because we have complex JSONB data in a (PostgreSQL) field that I am selecting and deconstructing to tabular data, which i then select from in multiple other views.
In the DependentView i am then using f"SELECT ... FROM {MainView._meta.db_table}". This creates a problem when i want to change MainView later on since that view cant be dropped because DependentView depends on it. With a DROP CASCADE this could be solved, but then the DependentView would be gone.

One workaround for now is to manually modify the migrations by adding operations to first empty and then recreate the DependentView (in both directions)

What would be nicer though is if there would be a way to specify

class DependentView(DBView):
    depends_on=[MainView]

which would then make sure that if MainView changes, DependentView is first dropped, and then recreated after MainView is changed.

Does this sound like an interesting feature? If it does, I would be willing to put in time to contribute the code.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions