Rails new with postgres

To create a new Rails application with PostgreSQL as the database, you can use the following command:

rails new my_app -d postgresql

This will create a new Rails application called my_app with PostgreSQL as the default database.

If you want to specify a specific PostgreSQL version, you can use the following command:

rails new my_app -d postgresql --postgresql-version=12

This will create a new Rails application called my_app with PostgreSQL version 12 as the default database.

You can also specify the database username and password using the following options:

rails new my_app -d postgresql --postgresql-username=myuser --postgresql-password=mypassword

This will create a new Rails application called my_app with PostgreSQL as the default database, using the specified username and password.

Once the application is created, you can configure the database settings in the config/database.yml file. For example:

default: &default
  adapter: postgresql
  encoding: unicode
  host: localhost
  username: myuser
  password: mypassword
  pool: 5

development:
  <<: *default
  database: my_app_development

test:
  <<: *default
  database: my_app_test

production:
  <<: *default
  database: my_app_production

This configuration sets up the default database settings for the application, including the adapter, encoding, host, username, password, and pool size. The development, test, and production sections specify the database settings for each environment.

You can then run the following command to create the database tables:

rails db:create

This will create the database tables for the application using the specified database settings.