Forum: Ruby on Rails SQLite database filename?

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.
Xavier N. (Guest)
on 2006-02-28 23:11
(Received via mailing list)
I'd need to be able to figure out the filename of the SQLite backend
of this application (for backups).

Does Rails provide API to access the database configuration? Or do I
need to load db/database.yml and check for ENV["RAILS_ENV"]? A simple
inspection of the ActiveRecord::Base.connection object sheds no
light, the @filename attribute is there but instance_methods returns
no reader that seems relevant.

-- fxn
Jeremy K. (Guest)
on 2006-02-28 23:35
(Received via mailing list)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Feb 28, 2006, at 1:10 PM, Xavier N. wrote:
> I'd need to be able to figure out the filename of the SQLite
> backend of this application (for backups).
>
> Does Rails provide API to access the database configuration? Or do
> I need to load db/database.yml and check for ENV["RAILS_ENV"]? A
> simple inspection of the ActiveRecord::Base.connection object sheds
> no light, the @filename attribute is there but instance_methods
> returns no reader that seems relevant.

class ActiveRecord::Base
   def self.connection_specification
     @@defined_connections[name].config rescue nil
   end
end

ActiveRecord::Base.connection_specification[:database]

This may break between Rails releases since the connection
specification code has been in flux.  Preferably, we'd be able to say
Foo.connection.spec or similar.  Please create an enhancement request
(or a patch!) at http://dev.rubyonrails.org if you'd like to pursue a
better API.

Best,
jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFEBMISAQHALep9HFYRArX1AJsEl+S++79WdToNMb5Ys1FRIqP+UQCggVqx
nbHeZ7WByJgxVPAoKbccqe4=
=ATZo
-----END PGP SIGNATURE-----
This topic is locked and can not be replied to.