Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record view dependencies and recreate dependent views when needed #35

Open
dolfandringa opened this issue May 29, 2024 · 1 comment
Open
Assignees
Labels
enhancement New feature or request

Comments

@dolfandringa
Copy link

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.

@BezBartek
Copy link
Owner

BezBartek commented May 29, 2024

@dolfandringa
Hello, Thank you for the idea, it sounds good. I am happy to welcome new contributors!

I will try to illustrate what need to be done, to be sure that we understand each other.
If view B(dependent one) depends on view A:

  • If view A definition changes, make migration with operations that drops views in order: view B, view A, then recreate in order: view A, view B. (created migration has 4 operations)
  • Optional feature: add optional parameter to refresh method, if we refresh view A, refresh all dependent views (B).

Is it what we want here? If so, then feel free to start work, I am here to help you and review it.

To discuss:
What if view depends on regular table? I am fine with limiting that relation (dependency) to views only. But it would be a nice thing to consider here. It feels natural, that a view model can depend on both things.

@BezBartek BezBartek added the enhancement New feature or request label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants