# Easy and reliable way to keep database views updated?

**URL:** <https://www.ruby-forum.com/t/easy-and-reliable-way-to-keep-database-views-updated/104297>\
**Category:** Rails\
**Created:** [May 16, 2007, 3:58pm UTC](https://www.ruby-forum.com/t/easy-and-reliable-way-to-keep-database-views-updated/104297 "2007-05-16T15:58:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [May 16, 2007, 3:58pm UTC](https://www.ruby-forum.com/t/easy-and-reliable-way-to-keep-database-views-updated/104297/1 "2007-05-16T15:58:36Z")

</div>

I’m using a lot of database views to create various lists in my RoR  
applications and I’ve problems keeping them updated.

The problem is, that some of my views are depending on some other views.  
So I have for example:

View A  
View B, depends on View A  
View C, depends on View A

If I need to update View A for any reason, I’ve to cascade drop it and  
re-create View B & C, because Postgresql (8.2 btw.) doesn’t support  
changes to a view very well.

When using rake for database migration, I always have to manually check  
for dependencies first. Then, I’ve to re-create the other views. That  
isn’t working well.

Is there any good attempt to have something like database-view  
migrations with dependencies?

---

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [May 16, 2007, 5:53pm UTC](https://www.ruby-forum.com/t/easy-and-reliable-way-to-keep-database-views-updated/104297/2 "2007-05-16T17:53:49Z")

</div>

On 5/16/07, Joachim G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If I need to update View A for any reason, I’ve to cascade drop it and  
> re-create View B & C, because Postgresql (8.2 btw.) doesn’t support  
> changes to a view very well.
> 
> When using rake for database migration, I always have to manually check  
> for dependencies first. Then, I’ve to re-create the other views. That  
> isn’t working well.

My thought would be to create a custom rake task that drops and  
rebuilds your views. You could then just run that after every  
migration.

---

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [May 17, 2007, 3:31pm UTC](https://www.ruby-forum.com/t/easy-and-reliable-way-to-keep-database-views-updated/104297/3 "2007-05-17T15:31:23Z")

</div>

Bob S. wrote:

> My thought would be to create a custom rake task that drops and  
> rebuilds your views. You could then just run that after every  
> migration.

I don’t like the idea to burn down my house and rebuild it just to  
replace a window.

---

<div class="post-metadata">

**Author:** ![joachimgross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@joachimgross](https://www.ruby-forum.com/u/joachimgross)\
**Post date:** [May 17, 2007, 8:53pm UTC](https://www.ruby-forum.com/t/easy-and-reliable-way-to-keep-database-views-updated/104297/4 "2007-05-17T20:53:40Z")

</div>

On 5/17/07, Joachim G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Bob S. wrote:
> 
> > My thought would be to create a custom rake task that drops and  
> > rebuilds your views. You could then just run that after every  
> > migration.
> 
> I don’t like the idea to burn down my house and rebuild it just to  
> replace a window.

Well alrighty then…
