How to check if the database exists or not in rails before doing a rake db:setup

后端 未结 7 1274
你的背包
你的背包 2020-12-05 23:58

How to check if the database exists or not in rails before doing a rake db:setup?

I would like to check if a database already exists before a db:create is being done

相关标签:
7条回答
  • 2020-12-06 00:26

    You can also count on the fact that rake db:migrate returns an error if the database does not yet exist.

    I used something like this in my scripts:

    rake db:migrate 2>/dev/null || rake db:setup
    

    (Inspired by penguincoder)

    0 讨论(0)
提交回复
热议问题