[LRUG] Rails and DB Views
Ed James (Alt)
ed.james.spam at gmail.com
Fri Jan 17 04:48:12 PST 2014
Great, thanks for you help guys.
On Friday, 17 January 2014 at 12:29, Tom Lea wrote:
> A long time ago, in a galaxy far far away, I wrote this: https://github.com/cwninja/mysql_view_support to fiddle with the kind of stuff.
>
> I think the use case was views that were regenerated each time, but /would/ be seen in schema.rb so we could seed data in in the test suite.
>
> I doubt it will run with recent rails, or do what you’re after, but the approach of using a customised connection adapter is probably still solid, and could put you on a possible right path.
>
> So it may be worth a look.
>
> Here’s what’s left of my memories of it:
>
> https://github.com/cwninja/mysql_view_support/blob/master/lib/active_record/connection_adapters/mysql_with_views_adapter.rb adds some utility methods for migrations, and also ensures that id columns in views are visible as primary keys.
> To keep it out of the schema.rb, you’re probably looking at modifying the result of the tables method, or whatever the schema dumper uses.
>
> https://github.com/cwninja/mysql_view_support/blob/master/tasks/views.rake looks to be about dealing with the fact our adapter name is not understood, and running the views migrations every time (the view creation migrations should be idempotent, so we want to just overwrite them.
>
>
> - Tom (being possibly of little assistance)
>
>
> On 17 Jan 2014, at 11:20, Ed James (Alt) <ed.james.spam at gmail.com (mailto:ed.james.spam at gmail.com)> wrote:
> > Hi all
> >
> > Is anyone using db views in a Rails app? If so, maybe you can help.
> >
> > My issue lies more around the management of the views, rather than using them in the app. I’ve done this before in a previous project but I don’t have access to that codebase anymore and I can’t remember what the hell I did.
> > How do you make ActiveRecord recognise the view and exclude it from the schema.rb file?
> > I seem to remember keeping the views as .sql files which were executed after a migration (by enhancing the db:migrate task). Any variations on this?
> >
> > The only gem I’ve managed to find is this one: https://github.com/railsware/db_structure_ext/tree/master/lib/db_structure_ext
> > Seems very old though and this seems like something which doesn’t need a gem. I know we didn’t use one previously.
> >
> > Unfortunately using the word “view” in search criteria is not very useful ;)
> >
> > Thanks,
> > Ed.
> > _______________________________________________
> > Chat mailing list
> > Chat at lists.lrug.org (mailto:Chat at lists.lrug.org)
> > http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20140117/a4bb40c7/attachment-0003.html>
More information about the Chat
mailing list