From b2f07967994cb5fb9f7a11e5d62772b40816c9a6 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Thu, 6 Jun 2024 17:16:02 +0200 Subject: [PATCH] Drop mysql2 support, settle on postgresql It's enough work to support one database, let's settle on the defacto Rails default. --- .dockerignore | 1 - .github/workflows/next-rails.yml | 14 +++++++++++++- .github/workflows/spec.yml | 14 +++++++++++++- .gitignore | 2 -- .rubocop_todo.yml | 9 ++++++++- Gemfile | 3 +-- Gemfile.lock | 2 -- config/database.yml | 15 ++------------- docker-compose.yml | 2 +- dotenv.example | 3 --- lib/tasks/dump_db.rake | 13 ------------- 11 files changed, 38 insertions(+), 40 deletions(-) delete mode 100644 lib/tasks/dump_db.rake diff --git a/.dockerignore b/.dockerignore index 7e7192a0..add2862b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,6 @@ .bundle/cache .git/ coverage/ -db/*.sqlite3 Dockerfile docker-compose.* log/ diff --git a/.github/workflows/next-rails.yml b/.github/workflows/next-rails.yml index fe0c0d34..e7934eef 100644 --- a/.github/workflows/next-rails.yml +++ b/.github/workflows/next-rails.yml @@ -12,6 +12,7 @@ jobs: runs-on: ubuntu-latest name: next-rails env: + OSEM_DB_HOST: localhost RAILS_ENV: test strategy: matrix: @@ -29,7 +30,6 @@ jobs: bundler-cache: true - name: Prepare spec run: | - rm -f osem_test osem_development bundle exec rake db:setup --trace bundle exec bin/rails webdrivers:chromedriver:update - name: spec/${{ matrix.suite }} @@ -40,3 +40,15 @@ jobs: with: project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} coverage-reports: coverage/coverage.xml + services: + postgres: + image: postgres:16-alpine + env: + POSTGRES_PASSWORD: mysecretpassword + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 diff --git a/.github/workflows/spec.yml b/.github/workflows/spec.yml index 2513417e..413c8fc2 100644 --- a/.github/workflows/spec.yml +++ b/.github/workflows/spec.yml @@ -25,6 +25,7 @@ jobs: runs-on: ubuntu-latest name: spec env: + OSEM_DB_HOST: localhost RAILS_ENV: test strategy: matrix: @@ -37,7 +38,6 @@ jobs: bundler-cache: true - name: Prepare spec run: | - rm -f osem_test osem_development bundle exec rake db:setup --trace bundle exec bin/rails webdrivers:chromedriver:update bundle exec rake factory_bot:lint RAILS_ENV=test @@ -49,3 +49,15 @@ jobs: with: project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} coverage-reports: coverage/coverage.xml + services: + postgres: + image: postgres:16-alpine + env: + POSTGRES_PASSWORD: mysecretpassword + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 diff --git a/.gitignore b/.gitignore index 3d1ffb4d..122965d6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -/db/test.sqlite3-journal config/application.rb config/config.yml config/secrets.yml @@ -18,7 +17,6 @@ capybara-*.html /vendor/bundle /log/* /tmp/* -/db/*.sqlite3 /public/system/* /coverage/ /spec/tmp/* diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d95059f1..7521eabc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-06-06 14:55:31 UTC using RuboCop version 1.63.5. +# on 2024-06-06 15:22:39 UTC using RuboCop version 1.63.5. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -1156,6 +1156,13 @@ Rails/Blank: - 'app/models/user.rb' - 'spec/factories/event_schedule.rb' +# Offense count: 68 +# Configuration parameters: Database, Include. +# SupportedDatabases: mysql, postgresql +# Include: db/**/*.rb +Rails/BulkChangeTable: + Enabled: false + # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). Rails/CompactBlank: diff --git a/Gemfile b/Gemfile index f76234ed..765a33d2 100644 --- a/Gemfile +++ b/Gemfile @@ -22,8 +22,7 @@ gem 'puma' # http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#responders gem 'responders', '~> 3.0' -# as supported databases -gem 'mysql2' +# as database gem 'pg' # for tracking data changes diff --git a/Gemfile.lock b/Gemfile.lock index 21ee3f5e..79b9982c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -307,7 +307,6 @@ GEM multi_xml (0.7.1) bigdecimal (~> 3.1) multipart-post (2.4.1) - mysql2 (0.5.6) net-http (0.4.1) uri net-imap (0.4.11) @@ -663,7 +662,6 @@ DEPENDENCIES mina mini_magick money-rails - mysql2 next_rails omniauth omniauth-facebook diff --git a/config/database.yml b/config/database.yml index 96ef1936..c12abd29 100644 --- a/config/database.yml +++ b/config/database.yml @@ -1,14 +1,6 @@ -<% - encoding = 'unicode' - if ENV.fetch('OSEM_DB_ADAPTER', nil) == 'mysql2' - encoding = 'utf8' - end -%> - - default: &default - adapter: <%= ENV.fetch('OSEM_DB_ADAPTER', 'postgresql') %> - encoding: <%= encoding %> + adapter: 'postgresql' + encoding: 'unicode' host: <%= ENV.fetch('OSEM_DB_HOST', 'database') %> port: <%= ENV.fetch('OSEM_DB_PORT', '5432') %> username: <%= ENV.fetch('OSEM_DB_USER', 'postgres') %> @@ -21,9 +13,6 @@ development: <<: *default database: osem_development -# Warning: The database defined as "test" will be erased and -# re-generated when you run "rake". -# Do not set this db to the same as development or production. test: <<: *default database: osem_test diff --git a/docker-compose.yml b/docker-compose.yml index d7744077..82587a20 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: "2.4" services: database: - image: postgres:12-alpine + image: postgres:16-alpine environment: PGDATA: /var/lib/postgresql/data/pgdata POSTGRES_PASSWORD: mysecretpassword diff --git a/dotenv.example b/dotenv.example index b6ca7a36..76c82648 100644 --- a/dotenv.example +++ b/dotenv.example @@ -9,9 +9,6 @@ # bundle exec rake secret # SECRET_KEY_BASE=12345 -# The type of database to use (postgresql, mysql2, sqlite3) -# OSEM_DB_ADAPTER=mysql2 - # The name of the host the database runs on # OSEM_DB_HOST=database diff --git a/lib/tasks/dump_db.rake b/lib/tasks/dump_db.rake deleted file mode 100644 index fff08335..00000000 --- a/lib/tasks/dump_db.rake +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -require 'yaml' -task :dump_db do - yaml = YAML.load_file("config/database.yml") - conf = yaml["production"] - filename = "#{conf["database"]}-#{Time.now.strftime("%Y-%m-%d-%H:%M:%S:%L")}.sql" - if conf["adapter"] == 'mysql2' - system "mysqldump -u #{conf["username"]} --password=#{conf["password"]} -h #{conf["host"]} #{conf["database"]} > ~/#{filename}" - else - puts "Error: This rake task only works for MYSQL" - end -end