在数据库中与多个用户一起设置rails的postgresql开发?

时间:2021-03-21 23:24:36

I am in the process of migrating my SQL to Postgresql because I want to develop in the same environment as my production.

我正在将SQL迁移到Postgresql,因为我希望在与产品相同的环境中进行开发。

I installed Postgres and was able to set my database yml file such that rake db:create:all worked with no problems.

我安装了Postgres,并能够设置我的数据库yml文件,如rake db:create:所有工作都没有问题。

However before I pushed, I realized that the username and password of the postgresql database is only available on my computer. I.e. I created the login role on my computer. When my friend who is also developing on the application, pulls the code, he won't have the username and password created by me on my computer.

但是在我按下之前,我意识到postgresql数据库的用户名和密码只能在我的计算机上使用。例如,我在我的计算机上创建了登录角色。当我的朋友也在开发应用程序时,他会拉代码,他不会有我在电脑上创建的用户名和密码。

Is he supposed to also create the same login role? Or is there a way to leave username / password blank so that everyone who develops can access the application? More importantly, what is the best practice for a situation like this?

他也应该创建相同的登录角色吗?或者是否有一种方法可以将用户名/密码留空,以便开发人员能够访问应用程序?更重要的是,在这种情况下,最好的做法是什么?

I am developing on windows and he is on mac.

我在windows上开发,他在mac上。

My database.yml: username and password left out.

我的数据库。yml:省略了用户名和密码。

development:
  adapter: postgresql
  encoding: unicode
  database: volatility_development
  pool: 5
  timeout: 5000
  host: localhost

test:
  adapter: postgresql
  encoding: unicode
  database: volatility_test
  pool: 5
  timeout: 5000
  host: localhost

production:
  adapter: postgresql
  encoding: unicode
  database: volatility_production
  pool: 5
  timeout: 5000

1 个解决方案

#1


2  

one possibility would be to use a combination of erb and environment variables, for example:

一种可能是结合使用erb和环境变量,例如:

development:
  username: <%= ENV['USERNAME'] %>
  password: <%= ENV['PASSWORD'] %>
  adapter: postgresql
  encoding: unicode
  database: volatility_development
  pool: 5
  timeout: 5000
  host: localhost

then you could do either of the following:

然后你可以做以下任何一种:

  1. start your server like so: USERNAME=bob PASSWORD=secret rails s
  2. 这样启动服务器:USERNAME=bob PASSWORD=secret rails s
  3. add the following to your .bashrc

    向.bashrc添加以下内容

    export USERNAME=bob
    export PASSWORD=secret
    

#1


2  

one possibility would be to use a combination of erb and environment variables, for example:

一种可能是结合使用erb和环境变量,例如:

development:
  username: <%= ENV['USERNAME'] %>
  password: <%= ENV['PASSWORD'] %>
  adapter: postgresql
  encoding: unicode
  database: volatility_development
  pool: 5
  timeout: 5000
  host: localhost

then you could do either of the following:

然后你可以做以下任何一种:

  1. start your server like so: USERNAME=bob PASSWORD=secret rails s
  2. 这样启动服务器:USERNAME=bob PASSWORD=secret rails s
  3. add the following to your .bashrc

    向.bashrc添加以下内容

    export USERNAME=bob
    export PASSWORD=secret