diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..f5c671c --- /dev/null +++ b/.env.sample @@ -0,0 +1,5 @@ +DATABASE_PORT=3306 +DATABASE_USER=root +DATABASE_PASSWORD= +DATABASE_HOST=localhost +DATABASE_SOCKET=/tmp/mysql.sock diff --git a/Gemfile b/Gemfile index 58debcf..4ea6a83 100644 --- a/Gemfile +++ b/Gemfile @@ -34,13 +34,15 @@ gem "jbuilder", "~> 2.5" # gem 'capistrano-rails', group: :development group :development, :test do - # Call 'byebug' anywhere in the code to stop execution and - # get a debugger console - gem "byebug", platforms: %i[mri mingw x64_mingw] - # Adds support for Capybara system testing and selenium driver gem "capybara", "~> 2.13" - gem "onkcop", require: false gem "selenium-webdriver" + + gem "byebug", platforms: %i[mri mingw x64_mingw] + gem "dotenv-rails" + gem "onkcop", require: false + gem "pry-byebug" + gem "pry-doc" + gem "pry-rails" end group :development do @@ -50,6 +52,11 @@ group :development do gem "web-console", ">= 3.3.0" # Spring speeds up development by keeping your application running # in the background. Read more: https://github.com/rails/spring + gem "annotate" + gem "better_errors" + gem "binding_of_caller" + gem "bullet" + gem "rails-erd" gem "rubocop" gem "spring" gem "spring-watcher-listen", "~> 2.0.0" diff --git a/Gemfile.lock b/Gemfile.lock index c3abb74..b39e2f1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,10 +40,22 @@ GEM tzinfo (~> 1.1) addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) + annotate (2.7.2) + activerecord (>= 3.2, < 6.0) + rake (>= 10.4, < 13.0) arel (8.0.0) ast (2.3.0) + better_errors (2.3.0) + coderay (>= 1.0.0) + erubi (>= 1.0.0) + rack (>= 0.9.0) bindex (0.5.0) + binding_of_caller (0.7.2) + debug_inspector (>= 0.0.1) builder (3.2.3) + bullet (5.6.1) + activesupport (>= 3.0.0) + uniform_notifier (~> 1.10.0) byebug (9.0.6) capybara (2.14.4) addressable @@ -54,6 +66,8 @@ GEM xpath (~> 2.0) childprocess (0.7.1) ffi (~> 1.0, >= 1.0.11) + choice (0.2.0) + coderay (1.1.2) coffee-rails (4.2.2) coffee-script (>= 2.2.0) railties (>= 4.0.0) @@ -62,6 +76,11 @@ GEM execjs coffee-script-source (1.12.2) concurrent-ruby (1.0.5) + debug_inspector (0.0.3) + dotenv (2.2.1) + dotenv-rails (2.2.1) + dotenv (= 2.2.1) + railties (>= 3.2, < 5.2) erubi (1.6.1) execjs (2.7.0) ffi (1.9.18) @@ -98,6 +117,18 @@ GEM parser (2.4.0.0) ast (~> 2.2) powerpack (0.1.1) + pry (0.10.4) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) + pry-byebug (3.4.3) + byebug (>= 9.0, < 9.1) + pry (~> 0.10) + pry-doc (0.11.1) + pry (~> 0.9) + yard (~> 0.9) + pry-rails (0.3.6) + pry (>= 0.10.4) public_suffix (2.0.5) puma (3.9.1) rack (2.0.3) @@ -118,6 +149,11 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) + rails-erd (1.5.2) + activerecord (>= 3.2) + activesupport (>= 3.2) + choice (~> 0.2.0) + ruby-graphviz (~> 1.2) rails-html-sanitizer (1.0.3) loofah (~> 2.0) railties (5.1.2) @@ -142,6 +178,7 @@ GEM unicode-display_width (~> 1.0, >= 1.0.1) rubocop-rspec (1.16.0) rubocop (>= 0.49.0) + ruby-graphviz (1.2.3) ruby-progressbar (1.8.1) ruby_dep (1.5.0) rubyzip (1.2.1) @@ -159,6 +196,7 @@ GEM selenium-webdriver (3.4.4) childprocess (~> 0.5) rubyzip (~> 1.0) + slop (3.6.0) spring (2.0.2) activesupport (>= 4.2) spring-watcher-listen (2.0.1) @@ -185,6 +223,7 @@ GEM uglifier (3.2.0) execjs (>= 0.3.0, < 3) unicode-display_width (1.3.0) + uniform_notifier (1.10.0) web-console (3.5.1) actionview (>= 5.0) activemodel (>= 5.0) @@ -195,20 +234,30 @@ GEM websocket-extensions (0.1.2) xpath (2.1.0) nokogiri (~> 1.3) + yard (0.9.9) PLATFORMS ruby DEPENDENCIES + annotate + better_errors + binding_of_caller + bullet byebug capybara (~> 2.13) coffee-rails (~> 4.2) + dotenv-rails jbuilder (~> 2.5) listen (>= 3.0.5, < 3.2) mysql2 (>= 0.3.18, < 0.5) onkcop + pry-byebug + pry-doc + pry-rails puma (~> 3.7) rails (~> 5.1.2) + rails-erd rubocop sass-rails (~> 5.0) selenium-webdriver diff --git a/README.md b/README.md index 65855f8..c711622 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ gem install bundler brew install mysql ``` +### graphviz(ER図自動生成用) +``` +brew install graphviz +``` + ### editorconfig plugin [ここ](http://editorconfig.org/#download)からエディタに合わせたものをインストールすること。 @@ -66,6 +71,11 @@ cd Aktiva-V2-Server bundle install --path=vendor/bundle ``` +3. envファイルをコピーし自分の設定に合わせて変更する +```sh +cp .env.sample .env +``` + 3. MySqlを起動する ```sh mysql.server start diff --git a/app/models/lyric.rb b/app/models/lyric.rb index edcabcd..1f20dd9 100644 --- a/app/models/lyric.rb +++ b/app/models/lyric.rb @@ -1,3 +1,19 @@ +# == Schema Information +# +# Table name: lyrics +# +# id :integer not null, primary key +# song_id :integer not null, indexed +# time :time not null +# text :string(255) not null +# created_at :datetime not null +# updated_at :datetime not null +# +# Foreign Keys +# +# fk_rails_... (song_id => songs.song_id) +# + # 歌詞情報 class Lyric < ApplicationRecord belongs_to :song diff --git a/app/models/person.rb b/app/models/person.rb index 372b315..e8d2dfc 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -1,3 +1,13 @@ +# == Schema Information +# +# Table name: people +# +# id :integer not null, primary key +# name :string(255) not null +# created_at :datetime not null +# updated_at :datetime not null +# + # アーティスト、作詞者、作曲者、振り付け師情報 class Person < ApplicationRecord has_many :artists, class_name: "Song", foreign_key: "artist_id" diff --git a/app/models/play_log.rb b/app/models/play_log.rb index 9362970..48d0379 100644 --- a/app/models/play_log.rb +++ b/app/models/play_log.rb @@ -1,3 +1,18 @@ +# == Schema Information +# +# Table name: play_logs +# +# id :integer not null, primary key +# song_id :integer not null, indexed +# time :datetime not null +# created_at :datetime not null +# updated_at :datetime not null +# +# Foreign Keys +# +# fk_rails_... (song_id => songs.song_id) +# + # 再生ログ class PlayLog < ApplicationRecord belongs_to :song diff --git a/app/models/song.rb b/app/models/song.rb index 3afeecc..c51e4d8 100644 --- a/app/models/song.rb +++ b/app/models/song.rb @@ -1,3 +1,27 @@ +# == Schema Information +# +# Table name: songs +# +# song_id :integer not null, primary key +# title :string(255) not null +# artist_id :integer not null, indexed +# lyricist_id :integer indexed +# composer_id :integer indexed +# choreographer_id :integer indexed +# beginners_badge :boolean default(FALSE) +# person_badge :boolean default(FALSE) +# created_at :datetime not null +# updated_at :datetime not null +# video :string(255) not null +# +# Foreign Keys +# +# fk_rails_... (artist_id => people.id) +# fk_rails_... (choreographer_id => people.id) +# fk_rails_... (composer_id => people.id) +# fk_rails_... (lyricist_id => people.id) +# + # 曲情報 class Song < ApplicationRecord belongs_to :artist, diff --git a/config/database.yml b/config/database.yml index c1388f9..ff17916 100644 --- a/config/database.yml +++ b/config/database.yml @@ -13,9 +13,11 @@ default: &default adapter: mysql2 encoding: utf8 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - username: root - password: - host: localhost + port: <%= ENV['DATABASE_PORT'] || '3306' %> + username: <%= ENV['DATABASE_USER'] || 'root' %> + password: <%= ENV['DATABASE_PASSWORD'] %> + host: <%= ENV['DATABASE_HOST'] || 'localhost' %> + socket: <%= ENV['DATABASE_SOCKET'] || '/tmp/mysql.sock' %> development: <<: *default diff --git a/config/environments/development.rb b/config/environments/development.rb index 6ce10bf..2b9946b 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -52,4 +52,12 @@ # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker + + config.after_initialize do + Bullet.enable = true + Bullet.alert = true + Bullet.bullet_logger = true + Bullet.console = true + Bullet.rails_logger = true + end end diff --git a/erd.pdf b/erd.pdf new file mode 100644 index 0000000..ad0ddef Binary files /dev/null and b/erd.pdf differ diff --git a/lib/tasks/auto_annotate_models.rake b/lib/tasks/auto_annotate_models.rake new file mode 100644 index 0000000..90fb8c6 --- /dev/null +++ b/lib/tasks/auto_annotate_models.rake @@ -0,0 +1,53 @@ +# NOTE: only doing this in development as some production environments (Heroku) +# NOTE: are sensitive to local FS writes, and besides -- it's just not proper +# NOTE: to have a dev-mode tool do its thing in production. +if Rails.env.development? + require "annotate" + task :set_annotation_options do + # You can override any of these by setting an environment variable of the + # same name. + Annotate.set_defaults( + "routes" => "false", + "position_in_routes" => "before", + "position_in_class" => "before", + "position_in_test" => "before", + "position_in_fixture" => "before", + "position_in_factory" => "before", + "position_in_serializer" => "before", + "show_foreign_keys" => "true", + "show_complete_foreign_keys" => "false", + "show_indexes" => "false", + "simple_indexes" => "true", + "model_dir" => "app/models", + "root_dir" => "", + "include_version" => "false", + "require" => "", + "exclude_tests" => "true", + "exclude_fixtures" => "true", + "exclude_factories" => "true", + "exclude_serializers" => "true", + "exclude_scaffolds" => "true", + "exclude_controllers" => "true", + "exclude_helpers" => "true", + "exclude_sti_subclasses" => "false", + "ignore_model_sub_dir" => "false", + "ignore_columns" => nil, + "ignore_routes" => nil, + "ignore_unknown_models" => "false", + "hide_limit_column_types" => "integer,boolean", + "hide_default_column_types" => "json,jsonb,hstore", + "skip_on_db_migrate" => "false", + "format_bare" => "true", + "format_rdoc" => "false", + "format_markdown" => "false", + "sort" => "false", + "force" => "false", + "trace" => "false", + "wrapper_open" => nil, + "wrapper_close" => nil, + "with_comment" => true, + ) + end + + Annotate.load_tasks +end diff --git a/lib/tasks/auto_generate_diagram.rake b/lib/tasks/auto_generate_diagram.rake new file mode 100644 index 0000000..a5728de --- /dev/null +++ b/lib/tasks/auto_generate_diagram.rake @@ -0,0 +1,4 @@ +# NOTE: only doing this in development as some production environments (Heroku) +# NOTE: are sensitive to local FS writes, and besides -- it's just not proper +# NOTE: to have a dev-mode tool do its thing in production. +RailsERD.load_tasks if Rails.env.development?