From fc381e59fa0508398a152a7df0f842297018ec5c Mon Sep 17 00:00:00 2001 From: leenday Date: Sat, 12 Sep 2020 00:06:05 +0300 Subject: [PATCH] added db --- config/database.yml | 84 ++++++--------------------------------------- db/schema.rb | 18 ++++++++++ docker-compose.yml | 38 ++++++++++++++++++++ 3 files changed, 67 insertions(+), 73 deletions(-) create mode 100644 db/schema.rb create mode 100644 docker-compose.yml diff --git a/config/database.yml b/config/database.yml index 8a10295..f2890bd 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,85 +1,23 @@ -# PostgreSQL. Versions 9.3 and up are supported. -# -# Install the pg driver: -# gem install pg -# On macOS with Homebrew: -# gem install pg -- --with-pg-config=/usr/local/bin/pg_config -# On macOS with MacPorts: -# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config -# On Windows: -# gem install pg -# Choose the win32 build. -# Install PostgreSQL and put its /bin directory on your path. -# -# Configure Using Gemfile -# gem 'pg' -# default: &default adapter: postgresql + host: <%= ENV['DATABASE_HOST'] || 'localhost' %> + username: <%= ENV['DATABASE_USERNAME'] || nil %> + password: <%= ENV['DATABASE_PASSWORD'] %> encoding: unicode - # For details on connection pooling, see Rails configuration guide - # https://guides.rubyonrails.org/configuring.html#database-pooling - pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> development: <<: *default - database: app_development + database: <%= ENV['DATABASE_NAME'] || 'task_manager_development' %> - # The specified database role being used to connect to postgres. - # To create additional roles in postgres see `$ createuser --help`. - # When left blank, postgres will use the default role. This is - # the same name as the operating system user that initialized the database. - #username: app - - # The password associated with the postgres role (username). - #password: - - # Connect on a TCP socket. Omitted by default since the client uses a - # domain socket that doesn't need configuration. Windows does not have - # domain sockets, so uncomment these lines. - #host: localhost - - # The TCP port the server listens on. Defaults to 5432. - # If your server runs on a different port number, change accordingly. - #port: 5432 - - # Schema search path. The server defaults to $user,public - #schema_search_path: myapp,sharedapp,public - - # Minimum log levels, in increasing order: - # debug5, debug4, debug3, debug2, debug1, - # log, notice, warning, error, fatal, and panic - # Defaults to warning. - #min_messages: notice - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. test: <<: *default - database: app_test + database: task_manager_test + port: <% (ENV['CI_NAME'] == 'codeship') ? 5433 : 5432 %> -# As with config/credentials.yml, you never want to store sensitive information, -# like your database password, in your source code. If your source code is -# ever seen by anyone, they now have access to your database. -# -# Instead, provide the password as a unix environment variable when you boot -# the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database -# for a full rundown on how to provide these environment variables in a -# production deployment. -# -# On Heroku and other platform providers, you may have a full connection URL -# available as an environment variable. For example: -# -# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" -# -# You can use this database configuration with: -# -# production: -# url: <%= ENV['DATABASE_URL'] %> -# production: <<: *default - database: app_production - username: app - password: <%= ENV['APP_DATABASE_PASSWORD'] %> + database: <%= ENV['DATABASE_NAME'] %> + username: <%= ENV['DATABASE_USERNAME'] %> + password: <%= ENV['DATABASE_PASSWORD'] %> + host: <%= ENV['DATABASE_HOST'] %> + port: <%= ENV['DATABASE_PORT'] %> diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..b10373b --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,18 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `rails +# db:schema:load`. When creating a new database, `rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 0) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + +end diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..afbe56d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3.7' + +services: + web: + build: . + volumes: &web-volumes + - &app-volume .:/app:cached + - ~/.ssh:/root/.ssh + - ~/.bash_history:/root/.bash_history + - &bundle-cache-volume bundle_cache:/bundle_cache + ports: + - 3000:3000 + - 3001:3001 + - 3002:3002 + depends_on: + - db + environment: &web-environment + BUNDLE_PATH: /bundle_cache + GEM_HOME: /bundle_cache + GEM_PATH: /bundle_cache + RAILS_PORT: 3000 + RUBYOPT: -W:no-deprecated -W:no-experimental + DATABASE_HOST: db + DATABASE_USERNAME: postgres + DATABASE_PASSWORD: postgres + + command: bundle exec rails s -b '0.0.0.0' -p 3000 + + db: + image: postgres:11.4 + ports: + - 5432:5432 + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + +volumes: + bundle_cache: