django-postgres-extra
django-postgres-extra copied to clipboard
Support for materialized views
https://www.postgresql.org/docs/9.3/static/sql-creatematerializedview.html
This is a work in progress:
https://github.com/SectorLabs/django-postgres-extra/tree/materialized-views
Done 😄
Looks awesome! Thanks for all your work. Have you got a timeline on release of the Materialized View functionality?
We've been testing this internally and we ran into some trouble. The basics are working just fine. It's mostly polishing and smashing some bugs. One of the issues is that I'd like to support Django querysets for the view's query. This is kind of tricky. During migrations, anything that is not in the model's meta objecy, is discarded. That means that the query has to be in the model's meta object. Custom meta options require some monkey patching in Django, which hasn't really worked reliably so far.
It's sort of usuable in its current state, but don't expect too much, and certainely not in migrations.
Thanks for the interest though! I am actively battle testing and working on this. I can't give an exact timeline unfortunately as it depends on a lot of circumstances. I'd say anywhere between a week and a month before I have a completely stable version that I feel comfortable releasing.
@Photonios Sorry for reviving an old issue. I would like to use materialized views and the documentation does not state any instabilities. Are they resolved? Any pitfalls we should be aware of? Thanks!
like here we can have separate command to sync views instead of using migrations. Any thoughts?
@Photonios whatever happened to this? Seems like the people over at https://github.com/mypebble/django-pgviews have stopped supporting it. Would you be up for a PR to add views to this project?
@Photonios Please take a look at @kingbuzzman's suggestion. Such a solution gives a chance for the development of a frozen project.
You can see my current progress on this here: https://github.com/SectorLabs/django-postgres-extra/compare/master...views
Creating/dropping views and materialized views works (including automatically generating migrations). Following is still missing:
- You can't "update" the query backing a materialized view without dropping it and re-creating it. Not sure how the migrator should handle that.
- No command yet to refresh a materialized view (you can do
Model.refresh()
tho).
Other than that, the way it works is a little different from django-pgviews
. For one, it supports both query sets and raw queries for views/materialized views. I want to make (materialized) views a first class citizen, including support for migrations etc.
Small example of what works now
from psqlextra.models import PostgresMaterializedViewModel
class MyView(PostgresMaterializedViewModel):
class ViewMeta:
query = MyOtherModel.objects.filter(name="test1")
this generates a migration that correctly builds a materialized view backed by the query set
python manage.py pgmakemigrations
@Photonios I see that Materialized Views are in master. They are ready? Can they be tested already? At the moment, I do not see any documentation.