bin/setupの処理内容について

【結論】

・bin/setupでは、下記の処理を行っている。

・gemの依存関係のチェック、インストール 
・データベースの再構築
・古いログと一時ファイルの削除
・サーバーを再起動

【目次】

【本題】

bin/setupの処理内容

コマンド一つで開発環境を整えるbin/setupコマンドですが
実際にその処理内容がどういったものか気になったので、
確認して見ました。

実行結果

ターミナル上では、コマンドを実行すると下記の様に表示が出ます。
ここから読み解いて行きます。

$bin/setup
== Installing dependencies ==
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
The Gemfile's dependencies are satisfied

== Preparing database ==
Database 'good_erorrs_development' already exists
Database 'good_erorrs_test' already exists
-- create_table("post_comments", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8", :force=>:cascade})
   -> 0.0740s
-- create_table("posts", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8", :force=>:cascade})
   -> 0.0201s
-- create_table("users", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8", :force=>:cascade})
   -> 0.0197s
-- add_foreign_key("post_comments", "posts")
   -> 0.0181s
-- add_foreign_key("post_comments", "users")
   -> 0.0167s
-- add_foreign_key("posts", "users")
   -> 0.0160s
-- create_table("post_comments", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8", :force=>:cascade})
   -> 0.0462s
-- create_table("posts", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8", :force=>:cascade})
   -> 0.0236s
-- create_table("users", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8", :force=>:cascade})
   -> 0.0185s
-- add_foreign_key("post_comments", "posts")
   -> 0.0171s
-- add_foreign_key("post_comments", "users")
   -> 0.0165s
-- add_foreign_key("posts", "users")
   -> 0.0162s

== Removing old logs and tempfiles ==

== Restarting application server ==

Installing dependencies

== Installing dependencies ==
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
The Gemfile's dependencies are satisfied

必要なGemパッケージがインストールされているか調べています。
ここでは、The Gemfile's dependencies are satisfiedと表示されているので、
必要なGemは全てインストールされていることを表しています。

Preparing database

ここではデータベースの構築を行っています。
まず大元のデータベース(開発環境とテスト環境)の作成を行います。
ここでは既に作成済みの為、already existsと表示されています。

次に各テーブルを作成しています。
なお、seedファイルがあれば、この段階で初期データの投入も行われます。

== Preparing database ==
Database 'good_erorrs_development' already exists
Database 'good_erorrs_test' already exists
-- create_table("post_comments", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8", :force=>:cascade})
   -> 0.0740s
-- create_table("posts", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8", :force=>:cascade})
   -> 0.0201s
-- create_table("users", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8", :force=>:cascade})
   -> 0.0197s
-- add_foreign_key("post_comments", "posts")
   -> 0.0181s
-- add_foreign_key("post_comments", "users")
   -> 0.0167s
-- add_foreign_key("posts", "users")
   -> 0.0160s
-- create_table("post_comments", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8", :force=>:cascade})
   -> 0.0462s
-- create_table("posts", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8", :force=>:cascade})
   -> 0.0236s
-- create_table("users", {:options=>"ENGINE=InnoDB DEFAULT CHARSET=utf8", :force=>:cascade})
   -> 0.0185s
-- add_foreign_key("post_comments", "posts")
   -> 0.0171s
-- add_foreign_key("post_comments", "users")
   -> 0.0165s
-- add_foreign_key("posts", "users")
   -> 0.0162s

Removing old logs and tempfiles

ここでは、古いログと一時ファイルの削除を行っています。

Restarting application server

ここでは、上記の処理を適用させる為に
サーバーを再起動させています。

カスタマイズも可能

なお、これらrails newした際の標準の動作で、
もし処理を追加したい場合は、bin/setupファイルの
コードに手を加える事でカスタマイズが可能です。