4

I have an account model which creates one database for each account. Before creating it, i need to validate if there isn't another database with the same name.

How can i do such validation? I can't find any method in ActiveRecord::Base.connection.

Thanks.

Fernando
  • 4,459
  • 4
  • 26
  • 39
  • Are you using a plugin to help with this? If not it's pretty easy to make a little mistake that can lead to information leakage. – tadman May 24 '12 at 14:29
  • No, which kind of plugin should i be using? – Fernando May 24 '12 at 16:08
  • There are several that do this kind of sharding or partitioning for you, so it's worth posting a question directed specifically at that. I'm not sure which work with Rails 3 best. – tadman May 24 '12 at 22:06
  • @tadman i don't see why any of these plugins would work for men. I need to create a database for another application which is written in PHP. I just want to know if ActiveRecord has a standard way of checking for database existence or if i need to write raw SQL. – Fernando May 25 '12 at 16:28
  • I don't think there's a standard way to do it other than to look through the results of `SHOW DATABASES` or equivalent and test if your target is there. – tadman May 25 '12 at 19:21
  • Possible duplicate of [How to check if the database exists or not in rails before doing a rake db:setup](https://stackoverflow.com/questions/17150064/how-to-check-if-the-database-exists-or-not-in-rails-before-doing-a-rake-dbsetup) – Matthias Michael Engh Oct 03 '17 at 20:11

0 Answers0