Forum: Ruby on Rails Migration detection of database type (Oracle and SQLite)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Don M. (Guest)
on 2007-03-08 19:59
(Received via mailing list)
We are writing a migration which will be used to create the initial
version of the database. We
want to use the same migration to populate both an Oracle and MySQL
database.

We would like to detect the database type so that we can add foreign
keys to Oracle, but
don't want to do it for the SQLite database. Is there a method we can
call from ActiveRecord
which gives us the database type we are connected to?

Thanks in advance,
Don McClean
Philip H. (Guest)
on 2007-03-08 20:18
(Received via mailing list)
> We are writing a migration which will be used to create the initial
> version of the database. We
> want to use the same migration to populate both an Oracle and MySQL
> database.
>
> We would like to detect the database type so that we can add foreign
> keys to Oracle, but
> don't want to do it for the SQLite database. Is there a method we can
> call from ActiveRecord
> which gives us the database type we are connected to?

Not sure what method, but if you look at the 'connection' method of the
adapter you should find something interesting in there...

http://api.rubyonrails.org/classes/ActiveRecord/Ba...
javier ramirez (Guest)
on 2007-03-08 21:51
(Received via mailing list)
> We would like to detect the database type so that we can add foreign
> keys to Oracle, but don't want to do it for the SQLite database. Is there a method we 
can
> call from ActiveRecord which gives us the database type we are connected to?
>
For something similar i've used a case like this

case ActiveRecord::Base.connection.adapter_name.downcase
        when /mysql[.]*/
                ....
 hope it helps!

javier ramirez

--------
Estamos de estreno... si necesitas llevar el control de tus gastos
visita http://www.gastosgem.com !!Es gratis!!
This topic is locked and can not be replied to.