Migration detection of database type (Oracle and SQLite)

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

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…

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!!