Railsの勉強にRedmineを使ってみようと思い構築してみました。
Ruby、Railsの設定は行われている前提で進めています。
MySQLのインストール
brew install mysql
インストール完了後に確認のため以下のコマンド
mysql.server start
Starting MySQL
. SUCCESS!
MySQLの起動はOK、次に接続してみる
mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.19 Homebrew
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
確認完了、止めるときは
mysql.server stop
Shutting down MySQL
.. SUCCESS!
初期設定に関しては以下の投稿に詳しく書かれていましたので参考にさせていただきました。
【MySQL, 開発環境】MySQLのインストールと初期設定2
MySQLのデータベース作成
MySQLにRedmine用のデータベースを作成する。
以下の投稿を参考にさせていただきました。
まずMySQLに接続
mysql -uroot -p
でパスワードが聞かれるので設定したものを入力。
接続できたら以下でデータベースを作成。
CREATE DATABASE redmine_development CHARACTER SET UTF8;
CREATE USER 'redmine_development'@'localhost' IDENTIFIED BY 'password for redmine';
GRANT ALL PRIVILEGES ON redmine_development.* TO 'redmine_development'@'localhost';
FLUSH PRIVILEGES;
実行できたら、以下で確認
show databases;
結果の中に「redmine_development」がいればOK。
テーブルを確認してみる。
USE redmine_development;
show tables;
Empty set (0.00 sec)
もちろんなんもないです。
とりあえずMySQLはこれでOK。
Redmineのインストール
Redmineのインストールを行います。
Githubから落としてきます。基本的な手順は以下に書かれているようです。
インストール手順
Redmineのダウンロード
まずはRedmineのClone or download
ボタンよりURLをコピーして落としたいディレクトリで実行。
git clone 対象のURL
Cloning into 'redmine'...
remote: Counting objects: 144205, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 144205 (delta 0), reused 0 (delta 0), pack-reused 144202
Receiving objects: 100% (144205/144205), 50.83 MiB | 705.00 KiB/s, done.
Resolving deltas: 100% (111228/111228), done.
bundle installの実行
次にバンドルを実行
bundle install
諸々インストール...
An error occurred while installing rmagick (2.16.0), and Bundler cannot
continue.
Make sure that `gem install rmagick -v '2.16.0'` succeeds before bundling.
とrmagick
入れてねと言われたので素直に入れる。
(githubのインストール手順は外すしてもいいよ的なことが書かれていましたが一応入れておきます、まだ何に使うのかよくわかっていないのですが)
4.Install the required gems by running:
bundle install --without development testIf ImageMagick is not installed on your system, you >should skip the
installation of the rmagick gem using:
bundle install --without development test rmagick
gem install rmagick -v '2.16.0'
なんやかんや書かれて失敗
調べるとImageMagick
なるものが必要なので入れる
(またこれもよくわかっていない、あとで諸々調べます)
brew install imagemagick
なんやかんやインストール...完了
再度、rmagick
を入れようとするがまたもエラー、ImageMagick
のバージョンが6でないとダメ的なものをちらっと見た気がしたのでやってみる。
以下を参考にさせていただきました
bundle install "rmagick" でインストールができない
brew install imagemagick@6
なんやかんやインストール...完了
ただこのままでは使えないよと言われてしまうので以下を実行
(詳しくは上記の投稿を参照)
brew link --force imagemagick@6
Linking /usr/local/Cellar/imagemagick@6/6.9.9-8... 75 symlinks created
If you need to have this software first in your PATH instead consider running:
echo 'export PATH="/usr/local/opt/imagemagick@6/bin:$PATH"' >> ~/.bash_profile
長かかった、再度rmagick
インストールしてみる
gem install rmagick -v '2.16.0'
Building native extensions. This could take a while...
Successfully installed rmagick-2.16.0
Parsing documentation for rmagick-2.16.0
Installing ri documentation for rmagick-2.16.0
Done installing documentation for rmagick after 1 seconds
1 gem installed
おお、できたできた、おめでとうございます。
したらバンドルをやってみましょう。
bundle install
なんやかんやインストール...
Bundle complete! 27 Gemfile dependencies, 56 gems now installed.
Gems in the groups development and test were not installed.
Bundled gems are installed into ./gems.
おお、できたっぽい。
テーブル作成
secret_tokenを作成。
bundle exec rake generate_secret_token
(in /XXX/redmine)
テーブル作成
bundle exec rake db:migrate
なんやかんや作成...
-- create_table(:email_addresses, {:id=>:integer})
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
Mysql2::Error: Invalid default value for 'updated_on': CREATE TABLE `email_addresses` (`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY, `user_id` int NOT NULL, `address` varchar(255) NOT NULL, `is_default` tinyint(1) DEFAULT 0 NOT NULL, `notify` tinyint(1) DEFAULT 1 NOT NULL, `created_on` timestamp NOT NULL, `updated_on` timestamp NOT NULL) ENGINE=InnoDB
なんかエラーになってる。
email_addressテーブルの更新日項目のデフォルトが無効ですよって言われているっぽいが、なぜそうなる。軽く調べても出てこない。
できている他のテーブルを見てみると:datetime
が設定されていたので
db/migrate/20150113194759_create_email_addresses.rbのデフォルトを変更してみる。
なんか色々間違っているので無視してください
他の対応方法を下に追記しました。(まだ適切でないと思いますが・・・)
再度実行
bundle exec rake db:migrate
なんやかんや作成...
== 20170723112801 RenameCommentsToContent: migrating ==========================
-- rename_column(:comments, :comments, :content)
-> 0.0119s
== 20170723112801 RenameCommentsToContent: migrated (0.0119s) =================
おお、いった...なんか持ってくるファイル間違ったのかよくわからないエラーだったけどとりあえず進めよう。
テーブルができているか確認する。
mysql -uroot -p
USE redmine_develop
show tables;
+-------------------------------------+
| Tables_in_redmine_development |
+-------------------------------------+
| ar_internal_metadata |
| attachments |
| auth_sources |
| boards |
| changes |
| changeset_parents |
| changesets |
| changesets_issues |
| comments |
| custom_field_enumerations |
| custom_fields |
| custom_fields_projects |
| custom_fields_roles |
| custom_fields_trackers |
| custom_values |
| documents |
| email_addresses |
| enabled_modules |
| enumerations |
| groups_users |
| import_items |
| imports |
| issue_categories |
| issue_relations |
| issue_statuses |
| issues |
| journal_details |
| journals |
| member_roles |
| members |
| messages |
| news |
| open_id_authentication_associations |
| open_id_authentication_nonces |
| projects |
| projects_trackers |
| queries |
| queries_roles |
| repositories |
| roles |
| roles_managed_roles |
| schema_migrations |
| settings |
| time_entries |
| tokens |
| trackers |
| user_preferences |
| users |
| versions |
| watchers |
| wiki_content_versions |
| wiki_contents |
| wiki_pages |
| wiki_redirects |
| wikis |
| workflows |
+-------------------------------------+
56 rows in set (0.00 sec)
おお、作成されとる、立ち上げてみよう。。。
サーバー起動
Redmineを落としたディレクトリに移動して以下を実行
bin/rails s
=> Booting WEBrick
=> Rails 5.1.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
[2017-08-20 20:57:45] INFO WEBrick 1.3.1
[2017-08-20 20:57:45] INFO ruby 2.4.1 (2017-03-22) [x86_64-darwin16]
[2017-08-20 20:57:45] INFO WEBrick::HTTPServer#start: pid=52457 port=3000
とりあえず立ち上がった、アクセスできてくれ、そろそろ晩御飯食べたい
にアクセス。。。
行った行った行きましたよ。
ログインして管理者のパスワードを変更します。
初期設定は以下を参照。
http://redmine.jp/tech_note/first-step/admin/
入れたので一旦サーバー落とします、開発環境なのでデバッグモードでできるかまで確認する。
RubyMineからデバッグモードで立ち上げる。
app/controllers/issues_controller.rb
にブレイクを置いてみる
http://localhost:3000/issues
にアクセスする
とまたとまたよー。
ただデバッグで立ち上げた時にすごいMacがウーン言いだしました、大丈夫だろうか。。。
思ったより時間がかかってしまいました、今日はここまで、とりあえずご飯を食べよう。
追記
テーブル作成のところでエラーの対処がおかしいので追記。
ただまだ適切な対処がよくわかっていませんが上のよりはましだと思います。
NULLを許可にする
db/migrate/20150113194759_create_email_addresses.rb
の:created_on
と:updated_on
のnullを許可すると作成可能。
テーブル確認すると
desc email_addresses;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| user_id | int(11) | NO | MUL | NULL | |
| address | varchar(255) | NO | | NULL | |
| is_default | tinyint(1) | NO | | 0 | |
| notify | tinyint(1) | NO | | 1 | |
| created_on | timestamp | YES | | NULL | |
| updated_on | timestamp | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
デフォルトを設定する
db/migrate/20150113194759_create_email_addresses.rb
の:created_on
と:updated_on
に, default: -> { 'NOW()' }
を追加すると作成可能。
テーブル確認すると
desc email_addresses;
+------------+--------------+------+-----+-------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+-------------------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| user_id | int(11) | NO | MUL | NULL | |
| address | varchar(255) | NO | | NULL | |
| is_default | tinyint(1) | NO | | 0 | |
| notify | tinyint(1) | NO | | 1 | |
| created_on | timestamp | NO | | CURRENT_TIMESTAMP | |
| updated_on | timestamp | NO | | CURRENT_TIMESTAMP | |
+------------+--------------+------+-----+-------------------+----------------+
ただどちらにせよテーブル定義を変更するのはないと思うので何か設定か手順が間違っているはず。
また調べてわかったら追記します。