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?

Community
  • 1
  • 1
gabrielhilal
  • 10,660
  • 6
  • 54
  • 81

3 Answers3

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.

Tair
  • 3,779
  • 2
  • 20
  • 33
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.

BGuimberteau
  • 249
  • 1
  • 8
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
gabrielhilal
  • 10,660
  • 6
  • 54
  • 81