Reputation: 33593
In a complex database, Postgres refuse to alter a view since many rules, and many other views depends on it.
I can drop the view with all its dependencies with DROP CASCADE
, but how will I recreate these views afterwards? It's not so easy, since even if I know that both V
and U
depends on the view I want to alter I can't just create them however I want. If view V
depends on U
, I must create V
first and only then create U
.
How can I trace which other views and rules depend on a certain view, so that I'll be able to alter it in the easiest way? I also want to generate a script so that everyone would be able to alter the view with my script, any easy way to generate that?
Upvotes: 0
Views: 1106
Reputation: 20466
I don't know how well this will work for you, but the least laborous way would probably be DROP CASCADE and use apgdiff to re-create the dropped views:
pg_dump -s -f old_schema.sql
to create a schema dump -- which includes all views etc.DROP VIEW x CASCADE
pg_dump -s -f new_schema.sql
apgdiff new_schema.sql old_schema.sql > restore.sql
-- create a script to restore the old schema in the database.psql -f restore.sql
Unfortunately this means that your database will be missing these views for a window of time, so you probably have to take it offline for maintenance.
Upvotes: 0