Skip to content

Commit

Permalink
Merge pull request #1982 from MushroomObserver/mysql2-to-trilogy
Browse files Browse the repository at this point in the history
Switch db adapter from `mysql2` to `trilogy`
  • Loading branch information
nimmolo committed Mar 1, 2024
2 parents b03354b + 7a0bb27 commit 353d7b4
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 40 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/ci_rails.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ jobs:
- name: Install additional tools
run: sudo apt-get install exiftool

# - name: Install Firefox
# run: sudo apt-get install firefox

- name: Install Chrome/Chromium
run: sudo apt-get install chromium-browser

Expand All @@ -39,15 +36,16 @@ jobs:
- name: Start mySQL
run: sudo systemctl start mysql.service

# https://github.com/trilogy-libraries/activerecord-trilogy-adapter/issues/64
# Issue in the trilogy gem where it cannot support `caching_sha2_password`
# https://github.com/trilogy-libraries/trilogy/issues/26
# For now need to ensure user is IDENTIFIED WITH `mysql_native_password`
# (change is in db/initialize.sql)
- name: Create and configure db
run: |
mysql -u root -proot < db/initialize.sql
cp db/vagrant/database.yml config
- name: Configure gmaps api key
run: |
cp config/gmaps_api_key.yml-template config/gmaps_api_key.yml
- name: Create test image directories
run: |
for dir in images test_images;
Expand Down
9 changes: 3 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,9 @@ gem("loofah")
gem("nokogiri")
gem("rails-html-sanitizer")

# Use mysql2 as db connector
# See https://github.com/brianmario/mysql2
gem("mysql2")

# Use sqlite3 as the database for Active Record
# gem("sqlite3")
# Use trilogy as db connector
# See https://github.com/trilogy-libraries/trilogy/tree/main/contrib/ruby
gem("trilogy")

# Add Arel helpers for more concise query syntax in Arel
# https://github.com/camertron/arel-helpers
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ GEM
minitest (>= 5.0)
ruby-progressbar
mutex_m (0.2.0)
mysql2 (0.5.6)
net-imap (0.4.10)
date
net-protocol
Expand Down Expand Up @@ -304,6 +303,7 @@ GEM
thor (1.3.1)
tilt (2.3.0)
timeout (0.4.1)
trilogy (2.7.0)
turbo-rails (2.0.4)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
Expand Down Expand Up @@ -377,7 +377,6 @@ DEPENDENCIES
minitest
minitest-reporters
mo_acts_as_versioned (>= 0.6.6)!
mysql2
net-imap
net-pop
net-smtp
Expand All @@ -404,6 +403,7 @@ DEPENDENCIES
sprockets-rails
stimulus-rails
terser
trilogy
turbo-rails
web-console
webmock
Expand Down
21 changes: 7 additions & 14 deletions MACOSX_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ mysql -u root
```

5. Inside the MySQL prompt (in the new terminal window), update the root password:
Temporarily use `mysql_native_password` instead of `caching_sha2_password`

```sql
USE mysql;
Expand All @@ -131,7 +132,7 @@ FLUSH PRIVILEGES;
exit;
# Setting it to null above seems necessary. Then:
mysql -u root
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'root';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
```

6. Stop Safe Mode MySQL Server:
Expand Down Expand Up @@ -228,9 +229,9 @@ Then:
Mac users have to uncomment/comment the relevant/irrelevant lines in `config/database.yml`:
```yml
shared:
adapter: mysql2
adapter: trilogy
# Default (works for MacOS X), uncomment this line
socket: /tmp/mysql.sock
socket: /tmp/mysql.sock
# For Ubuntu/Debian, comment out this line
# socket: /var/run/mysqld/mysqld.sock
```
Expand Down Expand Up @@ -326,20 +327,12 @@ else
fi
```

### Install mysql2
### Install trilogy

@mo-nathan needed to run the following to get the `mysql2`` gem to install.
Your mileage may vary...
Currently do this:

```sh
gem install mysql2 -v '0.5.3' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/opt/zstd/lib
bundle config --global build.mysql2 "--with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/opt/zstd/lib"
```

JoeCohen just did:

```sh
gem install mysql2
gem install trilogy
```

### Continue the mo-dev script
Expand Down
2 changes: 1 addition & 1 deletion README_DATABASE_INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ root> service mysql restart
remote> mysqladmin --protocol=tcp -u mo -p'$DB_PASSWORD' --host=$DB_HOST ping
remote> vi /var/web/mo/config/database.yml
production:
adapter: mysql2
adapter: trilogy
database: mo_production
host: $DB_HOST
username: mo
Expand Down
5 changes: 2 additions & 3 deletions README_DEVELOPMENT_INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,13 @@ jason> rehash
jason> cd

# Now we can install ruby gems properly.
jason> sudo gem install rails --version=2.1.1 --verbose --no-rdoc --no-ri
jason> sudo gem install rails --verbose --no-rdoc --no-ri
jason> sudo gem install mysql --verbose --no-rdoc --no-ri
jason> sudo gem install mysql2 --version=0.2.18 --verbose --no-rdoc --no-ri
jason> sudo gem install trilogy --verbose --no-rdoc --no-ri
jason> sudo gem install test-unit --verbose --no-rdoc --no-ri
jason> sudo gem install RedCloth --verbose --no-rdoc --no-ri
jason> sudo gem install sparql --verbose --no-rdoc --no-ri
# (mysql-2.8.1) <-- needed by rake test:db:prepare, see script/run_tests
# (mysql2-0.2.18) <-- important! 0.3.+ doesn't work with < rails 3.1.x!
# (test-unit-2.4.8)
# (RedCloth-4.2.9)
# sparql installs all of these:
Expand Down
2 changes: 1 addition & 1 deletion db/initialize.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ create procedure createUser(username varchar(50), pw varchar(50))
begin
IF (SELECT EXISTS(SELECT 1 FROM `mysql`.`user` WHERE `user` = username)) = 0 THEN
begin
set @sql = CONCAT('CREATE USER ', username, '@\'localhost\' IDENTIFIED BY \'', pw, '\'');
set @sql = CONCAT('CREATE USER ', username, '@\'localhost\' IDENTIFIED WITH mysql_native_password BY \'', pw, '\'');
prepare stmt from @sql;
execute stmt;
deallocate prepare stmt;
Expand Down
7 changes: 3 additions & 4 deletions db/macos/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
# MySQL (default setup). Versions 4.1 and 5.0 are recommended.
#
# Get the fast C bindings:
# gem install mysql2
# gem install trilogy
# (on OS X: gem install mysql -- --include=/usr/local/lib)
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html

shared:
adapter: mysql2
adapter: trilogy
# Default (works for MacOS X)
socket: /tmp/mysql.sock
# For Ubuntu/Debian
Expand All @@ -25,6 +23,7 @@ shared:
# And do not not require ORDER BY to include the DISTINCT column.
variables:
sql_mode: TRADITIONAL
default_authentication_plugin: mysql_native_password

development:
database: mo_development
Expand Down
4 changes: 2 additions & 2 deletions db/vagrant/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# MySQL (default setup). Versions 4.1 and 5.0 are recommended.
#
# Get the fast C bindings:
# gem install mysql2
# gem install trilogy
# (on OS X: gem install mysql -- --include=/usr/local/lib)
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html

shared:
adapter: mysql2
adapter: trilogy
# Default (works for MacOS X)
# socket: /tmp/mysql.sock
# For Ubuntu/Debian
Expand Down

0 comments on commit 353d7b4

Please sign in to comment.