0

I used to develop on SQLite3 and deploy on PostgreSQL. However, after this question I realised the importance of having the same database for development and production.

After many problems, I finally managed to install the PostgreSQL on my Mac OS X Lion 10.7.4. However, I am still facing some problems:

  • Using SQLite3 the databases' path is defined on the database.yml, which rails automatically creates within each new project.
  • Using PostgreSQL the database name is defined on the database.yml, which rails doesn't create automatically.

My question:

Shall I create a new database for each new project or shall I change the database.yml to include the same database for all projects?

I saw people saying that each user in a computer should have one database, when using PostgreSQL. Well, if the best practice is to create one database for each project (which I hope so)...

There is any way to configure rails to create the new database automatically within each new project?

3 Answers 3

1

Creating a DB is mostly one-time operation, so it's not a big deal to create it once for a project. A casual Postgresql admin can use pgAdmin graphical tool.

2
  • so, for each new project I must create 3 databases manually? database_development, database_test and database_production Jul 8, 2012 at 17:21
  • I thought should have an easy way, like using rake db:create, but it doesn't work... Jul 8, 2012 at 17:23
0

If you use Postgresql for development, you need to create database by your self.

But you can initialize you project for Postgresql.

rails new my_project -d postgresql

Have a good day.

Benjamin.

1
  • thanks for that, but I thought there was an easier way, like using rake db:create... Jul 8, 2012 at 17:24
0

Problem solved:

I have followed this tutorial and I could finally solve the problem.

I have created a new user for my postgreSQL called user1 without any password, so each time I create a new project I just need to change the database.yml for the below:

development:
  adapter: postgresql
  encoding: unicode
  database: newproject_development
  pool: 5
  username: user1 #I am changing this line
  password:

test:
  adapter: postgresql
  encoding: unicode
  database: newproject_test
  pool: 5
  username: user1 #I am changing this line
  password:

production:
  adapter: postgresql
  encoding: unicode
  database: newproject_production
  pool: 5
  username: user1 #I am changing this line
  password:

As the the user1 doen't have any password, now I can just create the tables using the Rails rake.

rake db:create:all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.