django-pgviews icon indicating copy to clipboard operation
django-pgviews copied to clipboard

Views syncing on every migrate

Open kochhar opened this issue 6 years ago • 4 comments

I have created some materialized views using view.MaterializedView as a base class. I find that every time I run migration, the views are recreated -- dropped and created again.

Is there some way to disable this behaviour?

kochhar avatar May 29 '18 20:05 kochhar

Thanks for posting this. If I recall correctly, this is done so we can migrate the underlying tables without Postgres raising an error when a view depends on a field you may be removing. If you have a potential resolution then I’d be more than happy to look over a PR and ask @tpict to prepare a release.

scott-w avatar Jun 02 '18 06:06 scott-w

Good point, @scott-w. I'm not very familiar with how migrations are implemented.

Do you think it would be possible to examine the migration to determine if the underlying table has been updated? If so, I could create a patch for this.

kochhar avatar Jun 06 '18 03:06 kochhar

@kochhar Hey, sorry for the late reply here. I believe that's possible, yes. You can examine the contents of the modules being migrated perhaps and see if that helps?

scott-w avatar Jul 23 '18 13:07 scott-w

Hello, maybe you can inspire here https://pypi.org/project/django-migrate-sql-deux/. It generates non-standard Django migrations for own SQL objects managed in Python. Very similar to django-pgviews. I think this technique comes very handy on large project with many views and other SQL objects.

petrprikryl avatar Oct 27 '20 12:10 petrprikryl