Переглянути джерело

add postgresql to rails (#5020)

* add postgresql to rails

* remove redundant test from config
Gregory Ostermayr 6 роки тому
батько
коміт
4cbd3b765a

+ 8 - 1
frameworks/Ruby/rails/Gemfile

@@ -1,6 +1,5 @@
 source 'http://rubygems.org'
 
-gem 'mysql2', '0.5.2'
 gem 'unicorn', '5.4.1'
 gem 'puma', '3.12.0'
 gem 'activerecord-import', '0.27.0'
@@ -8,3 +7,11 @@ gem 'activerecord', '5.2.2', :require => 'active_record'
 gem 'rails', '5.2.2'
 gem 'tzinfo-data', '1.2018.7'
 gem 'oj', '3.7.9'
+
+group :mysql do
+  gem 'mysql2', '0.5.2'
+end
+
+group :postgresql do
+  gem 'pg', '1.1.4'
+end

+ 1 - 0
frameworks/Ruby/rails/README.md

@@ -17,6 +17,7 @@ The tests were run with:
 - [Unicorn 5.4.1](http://unicorn.bogomips.org/)
 - [Puma 3.12](http://puma.io/)
 - [MySQL 5.5](https://dev.mysql.com/)
+- [PostgreSQL 11](https://www.postgresql.org/)
 
 ## Paths & Source for Tests
 

+ 3 - 0
frameworks/Ruby/rails/app/models/world.rb

@@ -1,3 +1,6 @@
 class World < ApplicationRecord
   self.table_name = "World"
+
+  alias_attribute(:randomNumber, :randomnumber) \
+    if connection.adapter_name.downcase.start_with?('postgres')
 end

+ 20 - 0
frameworks/Ruby/rails/benchmark_config.json

@@ -23,6 +23,26 @@
       "notes": "",
       "versus": "rack-puma-mri"
     },
+    "postgresql": {
+      "db_url": "/hello_world/db",
+      "query_url": "/hello_world/query?queries=",
+      "fortune_url": "/fortune",
+      "update_url": "/update?queries=",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Fullstack",
+      "database": "Postgres",
+      "framework": "rails",
+      "language": "Ruby",
+      "orm": "Full",
+      "platform": "Rack",
+      "webserver": "Puma",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "rails-postgresql",
+      "notes": "",
+      "versus": ""
+    },
     "unicorn": {
       "json_url": "/hello_world/json",
       "db_url": "/hello_world/db",

+ 7 - 2
frameworks/Ruby/rails/config/database.yml

@@ -1,6 +1,5 @@
 ---
 _: &common
-  adapter: mysql2
   database: hello_world
   username: benchmarkdbuser
   password: benchmarkdbpass
@@ -15,6 +14,12 @@ test:
   <<: *common
   pool: 64
 
-production:
+production_mysql:
+  <<: *common
+  adapter: mysql2
+  pool: 256
+
+production_postgresql:
   <<: *common
+  adapter: postgresql
   pool: 256

+ 2 - 0
frameworks/Ruby/rails/config/environments/production_mysql.rb

@@ -0,0 +1,2 @@
+# builds on production's configuration.
+require Rails.root.join('config', 'environments', 'production')

+ 2 - 0
frameworks/Ruby/rails/config/environments/production_postgresql.rb

@@ -0,0 +1,2 @@
+# builds on production's configuration.
+require Rails.root.join('config', 'environments', 'production')

+ 10 - 0
frameworks/Ruby/rails/rails-postgresql.dockerfile

@@ -0,0 +1,10 @@
+FROM ruby:2.6
+
+ADD ./ /rails
+
+WORKDIR /rails
+
+RUN bundle install --jobs=4 --gemfile=/rails/Gemfile --path=/rails/rails/bundle --without mysql
+
+ENV DBTYPE=postgresql
+CMD DB_HOST=tfb-database bundle exec puma -C config/mri_puma.rb -b tcp://0.0.0.0:8080 -e production_postgresql

+ 2 - 2
frameworks/Ruby/rails/rails-unicorn.dockerfile

@@ -6,7 +6,7 @@ ADD ./ /rails
 
 WORKDIR /rails
 
-RUN bundle install --jobs=4 --gemfile=/rails/Gemfile --path=/rails/rails/bundle
+RUN bundle install --jobs=4 --gemfile=/rails/Gemfile --path=/rails/rails/bundle --without=postgresql
 
 CMD nginx -c /rails/config/nginx.conf && \
-  DB_HOST=tfb-database bundle exec unicorn_rails -E production -c config/unicorn.rb
+  DB_HOST=tfb-database bundle exec unicorn_rails -E production_mysql -c config/unicorn.rb

+ 2 - 2
frameworks/Ruby/rails/rails.dockerfile

@@ -4,6 +4,6 @@ ADD ./ /rails
 
 WORKDIR /rails
 
-RUN bundle install --jobs=4 --gemfile=/rails/Gemfile --path=/rails/rails/bundle
+RUN bundle install --jobs=4 --gemfile=/rails/Gemfile --path=/rails/rails/bundle --without postgresql
 
-CMD DB_HOST=tfb-database bundle exec puma -C config/mri_puma.rb -b tcp://0.0.0.0:8080 -e production
+CMD DB_HOST=tfb-database bundle exec puma -C config/mri_puma.rb -b tcp://0.0.0.0:8080 -e production_mysql