Using ActiveRecord to determine database structure

Hi Folks,

for a project i have to write a program that determines automatically
the stucture of a given database. This means, i have to find out which
tables a database has, which attributes those tables have, which type
those attributes have and also the table constraints.

For this purpose i wanted to use ActiveRecord because as far as i know
it is capable of doing all this things.
I did the “Rolling with Ruby on Rails” tutorial so i know that the
scaffolding mechanism can be used to determine a table’s structure.
When looking into the ActiveRecord sources i found a method named
“structure_dump” in
connection_adapters/abstract/schema_statements.rb, i guess i can use
that to find out of which tables a database consists.

Since i’m very new to Ruby i have a lot of problems to implement those
things. What i already achieved is to connect to a database with
ActiveRecord like this

:host => “localhost” ,
:adapter => “mysql”,
:database => “test” ,
:username => “user” ,
:password => “password” ,
:socket => “/var/run/mysqld/mysqld.sock”

My question is if somebody kindly provide me with some sort of small
example of how to determine a Database’s description with ActiveRecord.
This would be very nice.

With kind regards,

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs