From 105a603cc1d3e47ee27c9ccb6c705e4b56c229ff Mon Sep 17 00:00:00 2001 From: zarina86 Date: Thu, 14 Sep 2023 22:41:29 +0600 Subject: [PATCH 1/2] from sqlite3 to postgresql --- Gemfile | 3 +- Gemfile.lock | 4 +- config/credentials.yml.enc | 2 +- config/database.yml | 79 +++++++++++++++++++++++++++++++++----- db/schema.rb | 3 ++ 5 files changed, 77 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index 3dd3ebd..91ca471 100644 --- a/Gemfile +++ b/Gemfile @@ -8,11 +8,12 @@ gem "devise", "~> 4.9", ">= 4.9.2" gem "devise-i18n" gem "importmap-rails" gem "jbuilder" +gem "pg", "~> 1.1" gem "puma", "~> 5.0" gem "rails", "~> 7.0.7", ">= 7.0.7.2" gem "redis", "~> 4.0" gem "sprockets-rails" -gem "sqlite3", "~> 1.4" +gem "pg", "~> 1.1" gem "stimulus-rails" gem "turbo-rails" gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby] diff --git a/Gemfile.lock b/Gemfile.lock index 2b039d4..4eed72c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -150,6 +150,7 @@ GEM parser (3.2.2.3) ast (~> 2.4.1) racc + pg (1.5.4) psych (5.1.0) stringio public_suffix (5.0.3) @@ -259,7 +260,6 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.6.4-x86_64-linux) stimulus-rails (1.2.2) railties (>= 6.0.0) stringio (3.0.8) @@ -303,6 +303,7 @@ DEPENDENCIES devise-i18n importmap-rails jbuilder + pg (~> 1.1) puma (~> 5.0) rails (~> 7.0.7, >= 7.0.7.2) redis (~> 4.0) @@ -313,7 +314,6 @@ DEPENDENCIES rubocop-rspec (~> 2.24) selenium-webdriver sprockets-rails - sqlite3 (~> 1.4) stimulus-rails turbo-rails tzinfo-data diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc index 4a4024e..c5a6d08 100644 --- a/config/credentials.yml.enc +++ b/config/credentials.yml.enc @@ -1 +1 @@ -HPAwZXT39f4XrnRalzTfdjlQo+OLwHr4/7QbKF8R0vqJz0I4nwTivuPRNMGf9BS7nK8bL0iefNMBY1QZrJSjzCSwm/fdszvlvcvMMbA/zGF3s7f3Iw8y+fwHo90qVFArzBnE/CUHU8P8XK4RNNEcOzyneKIgrvXbIC+b21jKwuOKYe9G08ty5tL/gM1R4O3b5jYPu++JiZexQuCx+HwrupzjE+KnzF8AeohgBQ93+ivVu96wI721+irQpnQZO0kQjao2MrSoFWRDSXIpeq0hkJWQH31/cu7wdCVI7BS9opSeQxVxYD94bV/k0RmL/0scI5g1zlpU5Kkfd/P2Kyur09UbqzyEKMErPO+0BERLYopEn0f00KzvRF8lqCtNCu5YTng38HYHhtzl74k5ikTKsMaEb5lAVTHB7a9d--WOnNmGfC0deK80mj--KHXTFZkunk1OQJ3DnDTK4g== \ No newline at end of file +7zkgc6PhroDULvqDC3/yzoh/8/I52AfKfg/fjfK5H5vEJBNGfCdrFq6v9GVe7EWiS4QrsXzwTa59Axd2IaWRUsjqW4wJ+Zph3C2DsJpbT6Z83Fb5d81q67qebFUzLpb++a2O7NtqpfPUQ8wGOBmHD1tEpkqcDp+umI22RoPrBU6HQbdv9rQO9C3gt79f8AWqK+Y/7KFetCGRLylMhGPVIe8o+EOM8m19m2oLc/ckbZwcTqHRDBoivUjOir+92l+6zmw6gGLi2sxpCNu9yQxotYQfLlqQkq/4ZNUejlGCb7Kh8CCGiQivIWzVqo6MLQhfNmvp8nsgtu1xaQVl60ai9Jixcia48WTijPU0YAGR5umh4xo3kEpnET2VIxMDEdxcFVtfh46B9/Vp3j9lQMfMfXmRnz6pOQ/KQz8O0WSXODg0hLzLEUqgSroUu7DtKmiku1pCRAKJqA==--bxJSeX/lO/xbvbr6--qffAjFt7o/6VD9DaNcIVhA== \ No newline at end of file diff --git a/config/database.yml b/config/database.yml index fcba57f..1ad7f48 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,25 +1,84 @@ -# SQLite. Versions 3.8.0 and up are supported. -# gem install sqlite3 +# PostgreSQL. Versions 9.3 and up are supported. # -# Ensure the SQLite 3 gem is defined in your Gemfile -# gem "sqlite3" +# 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: sqlite3 - pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - timeout: 5000 + adapter: postgresql + encoding: unicode + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> development: <<: *default - database: db/development.sqlite3 + database: ruby_work_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 running Rails. + #username: ruby_work + + # 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: db/test.sqlite3 + database: ruby_work_test +# 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 or a full connection URL as an environment +# variable when you boot the app. For example: +# +# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" +# +# If the connection URL is provided in the special DATABASE_URL environment +# variable, Rails will automatically merge its configuration values on top of +# the values provided in this file. Alternatively, you can specify a connection +# URL environment variable explicitly: +# +# production: +# url: <%= ENV["MY_APP_DATABASE_URL"] %> +# +# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database +# for a full overview on how database connection configuration can be specified. +# production: <<: *default - database: db/production.sqlite3 + database: ruby_work_production + username: ruby_work + password: <%= ENV["RUBY_WORK_DATABASE_PASSWORD"] %> diff --git a/db/schema.rb b/db/schema.rb index f1d4a0b..066a0ef 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,6 +11,9 @@ # It's strongly recommended that you check this file into your version control system. ActiveRecord::Schema[7.0].define(version: 2023_09_12_153423) do + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + create_table "users", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false From bf72261951f42f6eb95de60089119843d4130060 Mon Sep 17 00:00:00 2001 From: zarina86 Date: Thu, 14 Sep 2023 23:36:19 +0600 Subject: [PATCH 2/2] pg user and password are added to db.yml --- Gemfile | 1 - config/database.yml | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 91ca471..62b4941 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,6 @@ gem "puma", "~> 5.0" gem "rails", "~> 7.0.7", ">= 7.0.7.2" gem "redis", "~> 4.0" gem "sprockets-rails" -gem "pg", "~> 1.1" gem "stimulus-rails" gem "turbo-rails" gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby] diff --git a/config/database.yml b/config/database.yml index 1ad7f48..f7b7950 100644 --- a/config/database.yml +++ b/config/database.yml @@ -17,7 +17,11 @@ default: &default adapter: postgresql encoding: unicode - pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + port: 5432 + host: localhost + user: postgres + password: postgres development: <<: *default