-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TrackをModelに切り出し、ソートを可能にする #128
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
23c1cda
Add Track model
kinoppyd 0391184
Migrate track_name to track_id
kinoppyd 387a64a
Use schedule.track instead of schedule.track_name
kinoppyd 326dea4
Schedule belogs_to Track, not Event
kinoppyd 63c7a5b
Add Schedule::Table#track_list sort spec
kinoppyd b9be2fa
Obey rubocop
kinoppyd 478a324
Don't auto guess location when Rails.env.test?
kinoppyd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class Schedule < ApplicationRecord | ||
include Events | ||
|
||
has_many :schedule_speakers | ||
has_many :speakers, through: :schedule_speakers | ||
has_many :plan_schedules | ||
|
||
belongs_to :event | ||
belongs_to :track | ||
|
||
enum language: { en: 0, ja: 1, 'en & ja': 2 } | ||
|
||
validates :title, presence: true, length: { in: 1..100 } | ||
validates :description, length: { in: 0..1024 } | ||
validates :track_name, presence: true, length: { in: 1..32 } | ||
validates :language, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class Track < ApplicationRecord | ||
belongs_to :event | ||
has_many :schedules | ||
|
||
validates :name, presence: true | ||
validates :position, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class CreateTracks < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :tracks, id: :uuid, default: -> { 'gen_random_uuid()' } do |t| | ||
t.references :event, type: :uuid, null: false, foreign_key: true | ||
t.string :name, null: false | ||
t.integer :position, null: false, default: 1 | ||
|
||
t.timestamps | ||
end | ||
|
||
add_index :tracks, [:event_id, :name], unique: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class ConvertSchedulesTrack < ActiveRecord::Migration[7.1] | ||
def up | ||
add_column :schedules, :track_id, :uuid | ||
|
||
Schedule.all.each do |schedule| | ||
track = Track.find_or_create_by!(event: schedule.event, name: schedule.track_name) | ||
schedule.track = track | ||
schedule.save! | ||
end | ||
|
||
Event.all.each do |event| | ||
event.tracks.sort_by { _1.name.reverse }.each_with_index do |track, i| | ||
track.position = i + 1 | ||
track.save! | ||
end | ||
end | ||
|
||
remove_column :schedules, :track_name | ||
change_column :schedules, :track_id, :uuid, null: false | ||
add_foreign_key :schedules, :tracks | ||
end | ||
|
||
def down | ||
add_column :schedules, :track_name, :string | ||
|
||
Schedule.all.each do |schedule| | ||
schedule.track_name = schedule.track.name | ||
schedule.save! | ||
end | ||
|
||
change_column :schedules, :track_name, :string, null: false | ||
remove_column :schedules, :track_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class ScheduleBelongsTrack < ActiveRecord::Migration[7.1] | ||
def up | ||
remove_column :schedules, :event_id | ||
end | ||
|
||
def down | ||
add_column :schedules, :event_id, :uuid | ||
|
||
Schedule.all.each do |schedule| | ||
schedule.update!(event: schedule.track.event) | ||
end | ||
|
||
change_column :schedules, :event_id, :uuid, null: false | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このあたりN+1発生するのでは?と思って処理追ってみましたが、
app/controllers/schedules_controller.rb
の@schedules
を使っているので多分大丈夫だな、となりました