DBをMySQLに変更したのですが、Capistranoでデプロイすると、デフォルトのSQLiteでマイグレーションされてしまいます。
MySQLの方にデーブルが作成されません。
Capistranoの設定が原因だと思うのですが、MySQLを使ってデプロイしている記事をいくつか見ても、
特別設定している様子はなく、本当に設定する必要ないのかと疑問になり質問しました。
MySQL用に設定した記事が1つだけありましたが、この設定があってるのかが疑問です。
【入門】Capistrano3で自動デプロイ
項目の「デプロイ」より上の部分に設定が書いてあります。
どのようにすれば良いか、ご回答よろしくお願います。
/config/database.yml
ruby
1production: 2 adapter: mysql2 3 encoding: utf8 4 database: アプリ名_production 5 pool: 5 6 username: production 7 password: パスワード
/config/deploy.rb
ruby
1lock "~> 3.10.2" 2 3set :application, "アプリ名" 4set :repo_url, "git@github.com:〇〇.git" 5 6set :deploy_to, '/var/www/html' 7 8 set :default_env, { 9 :DEVISE_SECRET_KEY => ENV['DEVISE_SECRET_KEY'] 10} 11set :format_options, truncate: false 12 13append :linked_files, "config/database.yml" 14 15set :linked_files, %w{config/database.yml config/secrets.yml} 16set :linked_files, fetch(:linked_files, []).push('config/secrets.yml') 17set :linked_dirs, %w{bin log tmp/pids tmp/cache sockets bundle public/system public/assets} 18 19set :unicorn_pid, "#{shared_path}/tmp/pids/unicorn.pid" 20 21set :ssh_options, { verify_host_key: :secure, forward_agent: true } 22 set :rbenv_type, :user 23 set :rbenv_ruby, '2.5.1' 24 set :rbenv_custom_path, '/root/.rbenv' 25 set :log_level, :debug 26 27after 'deploy:publishing', 'deploy:restart' 28namespace :deploy do 29 task :restart do 30 on roles(:app) do 31 within current_path do 32 if test("[ -e #{fetch(:unicorn_pid)} ]") 33 execute :kill, "-s QUIT ", pid 34 end 35 secret = capture :bundle, "exec rake secret" 36 execute "echo SECRET_KEY_BASE='#{secret}' > #{current_path}/.env" 37 execute :bundle, "exec unicorn", "-c", fetch(:unicorn_config_path), "-E", fetch(:rails_env), "-D" 38 end 39 end 40 end 41end
/config/deploy/production.rb
ruby
1server "ドメイン名", user: "root", roles: %w{app db web} 2set :unicorn_pid, "#{shared_path}/tmp/pids/unicorn.pid" 3set :ssh_options, { 4 port: 22, 5 keys: %w(~/.ssh/github/github), 6 }
デプロイ先ディレクトリの中身
# ls -l /var/www/html/ 合計 20 lrwxrwxrwx 1 root root 37 6月 26 23:36 current -> /var/www/html/releases/20180626143558 -rw-r--r-- 1 root root 952 5月 22 03:20 index.html drwxr-xr-x 7 root root 4096 6月 26 23:36 releases drwxr-xr-x 7 root root 4096 6月 26 23:35 repo -rw-r--r-- 1 root root 654 6月 26 23:36 revisions.log drwxr-xr-x 9 root root 4096 6月 1 15:34 shared
デプロイ時の実行ログ(関係ありそうなマイグレーション部分を抜粋)
00:06 deploy:symlink:linked_files 01 mkdir -p /var/www/html/releases/20180626143558/config ✔ 01 root@ドメイン名 0.123s 02 rm /var/www/html/releases/20180626143558/config/database.yml ✔ 02 root@ドメイン名 0.095s 03 ln -s /var/www/html/shared/config/database.yml /var/www/html/releases/20180626143558/config/database.yml ✔ 03 root@ドメイン名 0.096s 04 rm /var/www/html/releases/20180626143558/config/secrets.yml ✔ 04 root@ドメイン名 0.093s 05 ln -s /var/www/html/shared/config/secrets.yml /var/www/html/releases/20180626143558/config/secrets.yml ✔ 05 root@ドメイン名 0.094s ** Invoke deploy:symlink:linked_dirs (first_time) ** Execute deploy:symlink:linked_dirs (略) ** Invoke deploy:migrate (first_time) ** Invoke deploy:set_rails_env ** Execute deploy:migrate 00:17 deploy:migrate [deploy:migrate] Run `rake db:migrate` ** Invoke deploy:migrating (first_time) ** Invoke deploy:set_rails_env ** Execute deploy:migrating 00:17 deploy:migrating 00:17 deploy:migrating 01 /root/.rbenv/bin/rbenv exec bundle exec rake db:migrate 01 == 20180615143842 Createテーブル名: migrating ================================== 01 -- create_table(:テーブル名) 01 -> 0.0008s 01 == 20180615143842 Createテーブル名: migrated (0.0009s) ========================= (同様のテーブル生成は略) ✔ 01 root@ドメイン名 2.124s
全体的なデプロイ実行ログ
$ bundle exec cap production deploy --trace 00:00 git:wrapper 00:00 git:check 00:02 deploy:check:directories 00:02 deploy:check:linked_dirs 00:02 deploy:check:make_linked_dirs 00:02 git:clone 00:02 git:update 00:04 git:create_release 00:06 deploy:set_current_revision 00:06 deploy:symlink:linked_files 01 mkdir -p /var/www/html/releases/20180626143558/config ✔ 01 root@ドメイン名 0.123s 02 rm /var/www/html/releases/20180626143558/config/database.yml ✔ 02 root@ドメイン名 0.095s 03 ln -s /var/www/html/shared/config/database.yml /var/www/html/releases/20180626143558/config/database.yml ✔ 03 root@ドメイン名 0.096s 04 rm /var/www/html/releases/20180626143558/config/secrets.yml ✔ 04 root@ドメイン名 0.093s 05 ln -s /var/www/html/shared/config/secrets.yml /var/www/html/releases/20180626143558/config/secrets.yml ✔ 05 root@ドメイン名 0.094s ** Invoke deploy:symlink:linked_dirs (first_time) ** Execute deploy:symlink:linked_dirs 00:07 deploy:symlink:linked_dirs 00:10 bundler:install 00:11 deploy:assets:precompile 00:16 deploy:assets:backup_manifest 00:17 deploy:migrate [deploy:migrate] Run `rake db:migrate` ** Invoke deploy:migrating (first_time) ** Invoke deploy:set_rails_env ** Execute deploy:migrating 00:17 deploy:migrating 00:17 deploy:migrating 01 /root/.rbenv/bin/rbenv exec bundle exec rake db:migrate 01 == 20180615143842 Createテーブル名: migrating ================================== 01 -- create_table(:テーブル名) 01 -> 0.0008s 01 == 20180615143842 Createテーブル名: migrated (0.0009s) ========================= (同様のテーブル生成部分は略) ✔ 01 root@ドメイン名 2.124s ** Invoke deploy:publishing (first_time) ** Execute deploy:publishing ** Invoke deploy:symlink:release (first_time) ** Execute deploy:symlink:release 00:19 deploy:symlink:release 00:21 deploy:restart 00:23 deploy:cleanup 00:25 deploy:log_revision
バージョン
mysql Ver 8.0.11 for Linux on x86_64 (MySQL Community Server - GPL)
Rails 5.0.7
回答1件
あなたの回答
tips
プレビュー