How can I create a Postgres user and database whenever I create a new rails app?

夙愿已清 提交于 2019-12-09 06:31:47

问题


I have followed this really helpful tutorial:

http://blog.willj.net/2011/05/31/setting-up-postgresql-for-ruby-on-rails-development-on-os-x/

I would really like to run rails new myapp and have the postgres db set up automatically. Is there any way I can do that using a Rails application template or something similar?


回答1:


On a unix based system:

sudo -u postgres createuser -d -R -P APPNAME
sudo -u postgres createdb -O APPNAME APPNAME

You can create a script and put it somewhere in your $PATH if you can't remember.




回答2:


Actually you don't need to create a new user each time you create a new rails app.

All you have to do is create the new application and change the username in your database.yml

development:
  adapter: postgresql
  encoding: unicode
  database: newapp_development
  pool: 5
  username: #your username
  password:
...

than just:

rake db:create:all


来源:https://stackoverflow.com/questions/11819841/how-can-i-create-a-postgres-user-and-database-whenever-i-create-a-new-rails-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!