Add raid groups table

This commit is contained in:
Justin Edmund 2023-06-04 22:55:24 -07:00
parent 0b3b777021
commit 09b5d17470
7 changed files with 67 additions and 2 deletions

View file

@ -0,0 +1,18 @@
# frozen_string_literal: true
module Api
module V1
class RaidGroupBlueprint < ApiBlueprint
field :name do |group|
{
en: group.name_en,
ja: group.name_jp
}
end
fields :difficulty, :order, :section, :extra, :hl
association :raids, blueprint: RaidBlueprint, view: :nested
end
end
end

9
app/models/raid_group.rb Normal file
View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
class RaidGroup < ApplicationRecord
has_many :raids, class_name: 'Raid', foreign_key: :group_id
def blueprint
RaidGroupBlueprint
end
end

View file

@ -0,0 +1,10 @@
class AddRaidGroupsTable < ActiveRecord::Migration[7.0]
create_table :raid_groups, id: :uuid, default: -> { "gen_random_uuid()" } do |t|
t.string :name_en, null: false
t.string :name_jp, null: false
t.integer :difficulty
t.integer :order, null: false
t.integer :section, default: 1, null: false
t.boolean :extra, default: false, null: false
end
end

View file

@ -0,0 +1,6 @@
class AddRaidGroupToRaids < ActiveRecord::Migration[7.0]
def change
add_reference :raids, :group, null: true, to_table: 'raid_groups', type: :uuid
add_foreign_key :raids, :raid_groups, column: :group_id
end
end

View file

@ -0,0 +1,5 @@
class AddHlToRaidGroups < ActiveRecord::Migration[7.0]
def change
add_column :raid_groups, :hl, :boolean, default: true, null: false
end
end

View file

@ -0,0 +1,5 @@
class RemoveGroupIntegerFromRaids < ActiveRecord::Migration[7.0]
def change
remove_column :raids, :group, :integer
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_05_03_224353) do
ActiveRecord::Schema[7.0].define(version: 2023_05_31_115422) do
# These are extensions that must be enabled in order to support this database
enable_extension "btree_gin"
enable_extension "pg_trgm"
@ -345,13 +345,24 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_03_224353) do
t.index ["user_id"], name: "index_parties_on_user_id"
end
create_table "raid_groups", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "name_en", null: false
t.string "name_jp", null: false
t.integer "difficulty"
t.integer "order", null: false
t.integer "section", default: 1, null: false
t.boolean "extra", default: false, null: false
t.boolean "hl", default: true, null: false
end
create_table "raids", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "name_en"
t.string "name_jp"
t.integer "level"
t.integer "group"
t.integer "element"
t.string "slug"
t.uuid "group_id"
t.index ["group_id"], name: "index_raids_on_group_id"
end
create_table "sparks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
@ -479,4 +490,5 @@ ActiveRecord::Schema[7.0].define(version: 2023_05_03_224353) do
add_foreign_key "parties", "parties", column: "source_party_id"
add_foreign_key "parties", "raids"
add_foreign_key "parties", "users"
add_foreign_key "raids", "raid_groups", column: "group_id"
end