DEV Community

jacksonPrimo
jacksonPrimo

Posted on • Edited on

4 1 1 1 1

Inicializando um projeto Ruby on Rails usando PostgreSql rodando em um container Docker

Primeiramente inicializamos o projeto.

$ rails new project_name --database=postgresql
Enter fullscreen mode Exit fullscreen mode

Em seguida configuramos o docker-compose.yml

version: '3.8'
services:
  database:
    container_name: project_name
    image: postgres
    restart: always
    environment:
      POSTGRES_USER: root
      POSTGRES_PASSWORD: root
      POSTGRES_DB: project_name_development
    volumes:
      - ./tmp/db:/var/lib/postgresql/data
    ports:
      - '5432:5432'

  adminer:
    container_name: adminer
    image: adminer
    restart: always
    ports:
      - "8080:8080"

Enter fullscreen mode Exit fullscreen mode

ps: Eu particularmente gosto de usar o adminer para visualizar as tabelas do banco, então essa imagem é opcional, para acessar ele basta entrar no endereço: localhost:8080, e colocar as credenciais:
sistem: PostgreSql
host: database
user: root
password: root

Em seguida configuramos o arquivo de configuração do banco de dados para o ambiente de desenvolvimento.

# config/database.yml
development:
  <<: *default
  host: localhost
  database: project_name_development
  username: root
  password: root
  port: 5432

Enter fullscreen mode Exit fullscreen mode

Para testarmos basta criarmos um novo model e uma migration.

$ rails g model User email: string
Enter fullscreen mode Exit fullscreen mode

E por fim rodar a migration que vai persistir as mudanças no banco.

$ rails db:migrate
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay