# Creating a View(database) with Migration

**URL:** <https://www.ruby-forum.com/t/creating-a-view-database-with-migration/172664>\
**Category:** Rails\
**Created:** [July 24, 2009, 11:15pm UTC](https://www.ruby-forum.com/t/creating-a-view-database-with-migration/172664 "2009-07-24T23:15:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![khagimoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ee59a6/32.png) [@khagimoto](https://www.ruby-forum.com/u/khagimoto)\
**Post date:** [July 24, 2009, 11:15pm UTC](https://www.ruby-forum.com/t/creating-a-view-database-with-migration/172664/1 "2009-07-24T23:15:09Z")

</div>

Hi,

Is there a way to create a view using ruby migration? I could run a  
quick sql script to create a view, but I wanted to do this with  
migration to make it easier during deployment.

Thanks,  
Kumi

---

<div class="post-metadata">

**Author:** ![khagimoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ee59a6/32.png) [@khagimoto](https://www.ruby-forum.com/u/khagimoto)\
**Post date:** [July 24, 2009, 11:19pm UTC](https://www.ruby-forum.com/t/creating-a-view-database-with-migration/172664/2 "2009-07-24T23:19:50Z")

</div>

On Fri, Jul 24, 2009 at 4:13 PM, khagimoto[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Is there a way to create a view using ruby migration?

[http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#M001934](http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#M001934)

You can put execute statements in your migration.

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![khagimoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ee59a6/32.png) [@khagimoto](https://www.ruby-forum.com/u/khagimoto)\
**Post date:** [July 24, 2009, 11:26pm UTC](https://www.ruby-forum.com/t/creating-a-view-database-with-migration/172664/3 "2009-07-24T23:26:18Z")

</div>

I was looking for something equivalent to create\_table, but this is  
pretty handy. Thanks!

---

<div class="post-metadata">

**Author:** ![khagimoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ee59a6/32.png) [@khagimoto](https://www.ruby-forum.com/u/khagimoto)\
**Post date:** [July 25, 2009, 1:54am UTC](https://www.ruby-forum.com/t/creating-a-view-database-with-migration/172664/4 "2009-07-25T01:54:24Z")

</div>

On Fri, Jul 24, 2009 at 5:25 PM, khagimoto[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I was looking for something equivalent to create\_table, but this is  
> pretty handy. Thanks!

I’d offer the observation that scopes in active record can easily  
serve the function of views in many cases.

–  
Rick DeNatale

Blog: [http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)  
Twitter: [http://twitter.com/RickDeNatale](http://twitter.com/RickDeNatale)  
WWR: [http://www.workingwithrails.com/person/9021-rick-denatale](http://www.workingwithrails.com/person/9021-rick-denatale)  
LinkedIn: [http://www.linkedin.com/in/rickdenatale](http://www.linkedin.com/in/rickdenatale)

---

<div class="post-metadata">

**Author:** ![khagimoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ee59a6/32.png) [@khagimoto](https://www.ruby-forum.com/u/khagimoto)\
**Post date:** [August 31, 2009, 11:23pm UTC](https://www.ruby-forum.com/t/creating-a-view-database-with-migration/172664/5 "2009-08-31T23:23:44Z")

</div>

@Michael S.  
Thanks for the info. I’ll have some warehousing to do in the future,  
so rails\_sql\_view will be perfect!

@Rick DeNatale  
I have yet to make use of scopes (still learning… ). Thanks for  
pointing me in that direction. I just read this page:  
[http://api.rubyonrails.org/classes/ActiveRecord/NamedScope/ClassMethods.html](http://api.rubyonrails.org/classes/ActiveRecord/NamedScope/ClassMethods.html)  
Looks like this is what I should do for what I’m trying to do… pretty  
simple!

---

<div class="post-metadata">

**Author:** ![khagimoto](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ee59a6/32.png) [@khagimoto](https://www.ruby-forum.com/u/khagimoto)\
**Post date:** [July 25, 2009, 3:39pm UTC](https://www.ruby-forum.com/t/creating-a-view-database-with-migration/172664/6 "2009-07-25T15:39:37Z")

</div>

On Friday 24 July 2009, khagimoto wrote:

> Is there a way to create a view using ruby migration? I could run a  
> quick sql script to create a view, but I wanted to do this with  
> migration to make it easier during deployment.

Yes, there is a plugin for your purpose

[http://github.com/aeden/rails\_sql\_views](http://github.com/aeden/rails_sql_views)

HTH,  
Michael

–  
Michael S.  
[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.schuerig.de/michael/](http://www.schuerig.de/michael/)
