Drop mysql2 support, settle on postgresql

It's enough work to support one database, let's settle on
the defacto Rails default.
This commit is contained in:
Henne Vogelsang 2024-06-06 17:16:02 +02:00
parent f51db484ab
commit b2f0796799
No known key found for this signature in database
GPG key ID: 97DDB66BDAF8D4D6
11 changed files with 38 additions and 40 deletions

View file

@ -1,7 +1,6 @@
.bundle/cache .bundle/cache
.git/ .git/
coverage/ coverage/
db/*.sqlite3
Dockerfile Dockerfile
docker-compose.* docker-compose.*
log/ log/

View file

@ -12,6 +12,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: next-rails name: next-rails
env: env:
OSEM_DB_HOST: localhost
RAILS_ENV: test RAILS_ENV: test
strategy: strategy:
matrix: matrix:
@ -29,7 +30,6 @@ jobs:
bundler-cache: true bundler-cache: true
- name: Prepare spec - name: Prepare spec
run: | run: |
rm -f osem_test osem_development
bundle exec rake db:setup --trace bundle exec rake db:setup --trace
bundle exec bin/rails webdrivers:chromedriver:update bundle exec bin/rails webdrivers:chromedriver:update
- name: spec/${{ matrix.suite }} - name: spec/${{ matrix.suite }}
@ -40,3 +40,15 @@ jobs:
with: with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: coverage/coverage.xml 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

View file

@ -25,6 +25,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
name: spec name: spec
env: env:
OSEM_DB_HOST: localhost
RAILS_ENV: test RAILS_ENV: test
strategy: strategy:
matrix: matrix:
@ -37,7 +38,6 @@ jobs:
bundler-cache: true bundler-cache: true
- name: Prepare spec - name: Prepare spec
run: | run: |
rm -f osem_test osem_development
bundle exec rake db:setup --trace bundle exec rake db:setup --trace
bundle exec bin/rails webdrivers:chromedriver:update bundle exec bin/rails webdrivers:chromedriver:update
bundle exec rake factory_bot:lint RAILS_ENV=test bundle exec rake factory_bot:lint RAILS_ENV=test
@ -49,3 +49,15 @@ jobs:
with: with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: coverage/coverage.xml 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

2
.gitignore vendored
View file

@ -1,4 +1,3 @@
/db/test.sqlite3-journal
config/application.rb config/application.rb
config/config.yml config/config.yml
config/secrets.yml config/secrets.yml
@ -18,7 +17,6 @@ capybara-*.html
/vendor/bundle /vendor/bundle
/log/* /log/*
/tmp/* /tmp/*
/db/*.sqlite3
/public/system/* /public/system/*
/coverage/ /coverage/
/spec/tmp/* /spec/tmp/*

View file

@ -1,6 +1,6 @@
# This configuration was generated by # This configuration was generated by
# `rubocop --auto-gen-config` # `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 # The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base. # one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new # Note that changes in the inspected code, or installation of new
@ -1156,6 +1156,13 @@ Rails/Blank:
- 'app/models/user.rb' - 'app/models/user.rb'
- 'spec/factories/event_schedule.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 # Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all). # This cop supports unsafe autocorrection (--autocorrect-all).
Rails/CompactBlank: Rails/CompactBlank:

View file

@ -22,8 +22,7 @@ gem 'puma'
# http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#responders # http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#responders
gem 'responders', '~> 3.0' gem 'responders', '~> 3.0'
# as supported databases # as database
gem 'mysql2'
gem 'pg' gem 'pg'
# for tracking data changes # for tracking data changes

View file

@ -307,7 +307,6 @@ GEM
multi_xml (0.7.1) multi_xml (0.7.1)
bigdecimal (~> 3.1) bigdecimal (~> 3.1)
multipart-post (2.4.1) multipart-post (2.4.1)
mysql2 (0.5.6)
net-http (0.4.1) net-http (0.4.1)
uri uri
net-imap (0.4.11) net-imap (0.4.11)
@ -663,7 +662,6 @@ DEPENDENCIES
mina mina
mini_magick mini_magick
money-rails money-rails
mysql2
next_rails next_rails
omniauth omniauth
omniauth-facebook omniauth-facebook

View file

@ -1,14 +1,6 @@
<%
encoding = 'unicode'
if ENV.fetch('OSEM_DB_ADAPTER', nil) == 'mysql2'
encoding = 'utf8'
end
%>
default: &default default: &default
adapter: <%= ENV.fetch('OSEM_DB_ADAPTER', 'postgresql') %> adapter: 'postgresql'
encoding: <%= encoding %> encoding: 'unicode'
host: <%= ENV.fetch('OSEM_DB_HOST', 'database') %> host: <%= ENV.fetch('OSEM_DB_HOST', 'database') %>
port: <%= ENV.fetch('OSEM_DB_PORT', '5432') %> port: <%= ENV.fetch('OSEM_DB_PORT', '5432') %>
username: <%= ENV.fetch('OSEM_DB_USER', 'postgres') %> username: <%= ENV.fetch('OSEM_DB_USER', 'postgres') %>
@ -21,9 +13,6 @@ development:
<<: *default <<: *default
database: osem_development 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: test:
<<: *default <<: *default
database: osem_test database: osem_test

View file

@ -2,7 +2,7 @@ version: "2.4"
services: services:
database: database:
image: postgres:12-alpine image: postgres:16-alpine
environment: environment:
PGDATA: /var/lib/postgresql/data/pgdata PGDATA: /var/lib/postgresql/data/pgdata
POSTGRES_PASSWORD: mysecretpassword POSTGRES_PASSWORD: mysecretpassword

View file

@ -9,9 +9,6 @@
# bundle exec rake secret # bundle exec rake secret
# SECRET_KEY_BASE=12345 # 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 # The name of the host the database runs on
# OSEM_DB_HOST=database # OSEM_DB_HOST=database

View file

@ -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