0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

herokuでClearDB MySQLからJawsDB Mariaに置き換え

Posted at

#Clear DBからJAWSDB mariaに置換

Clear DB Mysqlの無料枠が昨年廃止に伴い、JAWS DB Mariaに置き換えしました。

  1. DBのバックアップを取得

https://sequelpro.com/ を使用してDBに接続

heroku config
=== sevens-api Config Vars

DATABASE_URL:             mysql2://user:pass@shichimi.com:3306/db
DB_HOSTNAME:              shichimi.com
DB_NAME:                  db
DB_PASSWORD:              pass
DB_PORT:                  3306
DB_USERNAME:              user
JAWSDB_MARIA_URL:         mysql://user:pass@shichimi.com:3306/db
LANG:                     en_US.UTF-8
RACK_ENV:                 production
RAILS_ENV:                production
RAILS_LOG_TO_STDOUT:      enabled
RAILS_SERVE_STATIC_FILES: enabled
SECRET_KEY_BASE:          hogehogehogehogehogehogehogehogehogehogehogehogehogehogehoge

https://sequelpro.com/ を使用してJawsDB mariaに接続して、バックアップをインポート

database.ymlが下記です。
絵文字対応してます㊗️

default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: 5

development:
  <<: *default
  database: development
  username: root
  password:
  socket: /var/lib/mysql/mysql.sock
  host: <%= ENV.fetch("DB_HOST_NAME") { "localhost" } %>

test:
  <<: *default
  database: test

production:
  <<: *default
  database: <%= ENV['DATABASE_NAME'] %>
  username: <%= ENV['DATABASE_USERNAME'] %>
  password: <%= ENV['DATABASE_PASSWORD'] %>
  host: <%= ENV['DB_HOSTNAME'] %>
  url: <%= ENV['DATABASE_URL'] %>

クライアント側で、各種環境変数を設定

shichimi: [master]$: heroku config:set DB_NAME="db-name"
Setting DB_NAME and restarting ⬢ shichimi-api... done, v68
DB_NAME: db-name
shichimi: [master]$: heroku config:set DB_PASSWORD="pass"
Setting DB_PASSWORD and restarting ⬢ shichimi-api... done, v69
DB_PASSWORD: pass
shichimi: [master]$: heroku config:set DB_HOSTNAME="shichimi.com"
Setting DB_HOSTNAME and restarting ⬢ shichimi-api... done, v70
DB_HOSTNAME: shichimi.com
shichimi: [master]$: heroku config:set DB_USERNAME="user"
Setting DB_USERNAME and restarting ⬢ shichimi-api... done, v71
DB_USERNAME: user
shichimi: [master]$: heroku config:set DATABASE_URL=" mysql2://user:pass@shcihimi.com:3306/db-name"
Setting DATABASE_URL and restarting ⬢ shichimi-api... done, v72
DATABASE_URL:  mysql2://user:pass@shcihimi.com:3306/db-name

database.ymlの設定が不要な場合、環境変数だけ、上記コマンドで、環境変数の設定だけ変更すれば良いです。
database.ymlのファイルを変更する場合は下記でコミットしましょう!

git push heroku main

注意点

余談ですが、私の場合環境変数のURL schemeがmysqlになっており、mysql2にしないと疎通できませんでした😭
各々の環境に合ったURL shcemeにしましょう

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?