Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions app/models/card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ class Card < ApplicationRecord
belongs_to :side
belongs_to :faction
belongs_to :card_type
has_and_belongs_to_many :subtype_relations, class_name: 'Subtype'
has_many :card_subtypes
has_many :subtypes, :through => :card_subtypes
has_many :printings
has_many :legality

validates :code, uniqueness: true
validates :name, uniqueness: true

def versions
printings.includes(nr_set: :nr_cycle).order(date_release: :desc)
printings.includes(card_set: :cycle).order(date_release: :desc)
end

def strength_selector
Expand Down
6 changes: 6 additions & 0 deletions app/models/card_cycle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

class CardCycle < ApplicationRecord
has_many :card_sets
# TODO(plural): Add association path for cycles -> printings
end
6 changes: 6 additions & 0 deletions app/models/card_set.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

class CardSet < ApplicationRecord
belongs_to :card_cycle
belongs_to :card_set_type
end
5 changes: 5 additions & 0 deletions app/models/card_set_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class CardSetType < ApplicationRecord
has_many :card_sets
end
12 changes: 12 additions & 0 deletions app/models/card_subtype.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class CardSubtype < ApplicationRecord
self.table_name = "cards_subtypes"

belongs_to :card,
:primary_key => :id,
:foreign_key => :card_id
belongs_to :subtype,
:primary_key => :id,
:foreign_key => :subtype_id
end
6 changes: 0 additions & 6 deletions app/models/card_subtypes.rb

This file was deleted.

1 change: 1 addition & 0 deletions app/models/faction.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

# TODO(plural): add a side code to faction.
class Faction < ApplicationRecord
has_many :cards
end
7 changes: 0 additions & 7 deletions app/models/legality.rb

This file was deleted.

5 changes: 0 additions & 5 deletions app/models/legality_type.rb

This file was deleted.

5 changes: 0 additions & 5 deletions app/models/nr_cycle.rb

This file was deleted.

6 changes: 0 additions & 6 deletions app/models/nr_set.rb

This file was deleted.

5 changes: 0 additions & 5 deletions app/models/nr_set_type.rb

This file was deleted.

3 changes: 2 additions & 1 deletion app/models/printing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

class Printing < ApplicationRecord
belongs_to :card
belongs_to :nr_set
belongs_to :card_set
# TODO(plural): Add an association to cycle.

def format_flavor
t = flavor || ''
Expand Down
1 change: 1 addition & 0 deletions app/models/side.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

class Side < ApplicationRecord
# TODO(plural): Add an association for factions.
has_many :cards
end
3 changes: 2 additions & 1 deletion app/models/subtype.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

class Subtype < ApplicationRecord
has_and_belongs_to_many :cards
has_many :card_subtypes
has_many :cards, :through => :card_subtypes
end
Empty file added db/migrate/.keep
Empty file.
136 changes: 46 additions & 90 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,158 +10,114 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20220114191001) do
ActiveRecord::Schema.define(version: 2022_02_13_014409) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "card_types", force: :cascade do |t|
t.text "code", null: false
create_table "card_set_types", id: :string, force: :cascade do |t|
t.text "name", null: false
t.text "description"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "card_sets", id: :string, force: :cascade do |t|
t.text "name", null: false
t.date "date_release"
t.integer "size"
t.text "card_cycle_id"
t.text "card_set_type_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end

create_table "card_types", id: :string, force: :cascade do |t|
t.text "name", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["code"], name: "index_card_types_on_code", unique: true
end

create_table "cards", force: :cascade do |t|
create_table "cards", id: :string, force: :cascade do |t|
t.text "name", null: false
t.text "card_type_id", null: false
t.text "side_id", null: false
t.text "faction_id", null: false
t.integer "advancement_requirement"
t.integer "agenda_points"
t.integer "base_link"
t.text "code", null: false
t.integer "cost"
t.integer "deck_limit"
t.integer "faction_id"
t.integer "influence_cost"
t.integer "influence_limit"
t.integer "memory_cost"
t.integer "minimum_deck_size"
t.text "name", null: false
t.integer "side_id"
t.integer "strength"
t.text "subtypes"
t.text "text"
t.integer "trash_cost"
t.integer "card_type_id"
t.boolean "uniqueness"
t.text "keywords"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["card_type_id"], name: "index_cards_on_card_type_id"
t.index ["code"], name: "index_cards_on_code", unique: true
t.index ["faction_id"], name: "index_cards_on_faction_id"
t.index ["side_id"], name: "index_cards_on_side_id"
t.index ["name"], name: "index_cards_unique_name", unique: true
end

create_table "cards_subtypes", id: false, force: :cascade do |t|
t.integer "card_id", null: false
t.integer "subtype_id", null: false
t.index ["subtype_id"], name: "index_cards_subtypes_on_subtype_id"
end

create_table "factions", force: :cascade do |t|
t.text "code", null: false
t.boolean "is_mini", null: false
t.text "name", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["code"], name: "index_factions_on_code", unique: true
end

create_table "legality_types", force: :cascade do |t|
t.text "name", null: false
t.text "code", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["code"], name: "index_legality_types_on_code", unique: true
end

create_table "nr_cycles", force: :cascade do |t|
t.text "code", null: false
t.text "name", null: false
t.text "description"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["code"], name: "index_nr_cycles_on_code", unique: true
t.text "card_id", null: false
t.text "subtype_id", null: false
t.index ["card_id", "subtype_id"], name: "index_cards_subtypes_on_card_id_and_subtype_id"
end

create_table "nr_set_types", force: :cascade do |t|
t.text "code", null: false
create_table "card_cycles", id: :string, force: :cascade do |t|
t.text "name", null: false
t.text "description"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["code"], name: "index_nr_set_types_on_code", unique: true
end

create_table "nr_sets", force: :cascade do |t|
t.text "code", null: false
create_table "factions", id: :string, force: :cascade do |t|
t.boolean "is_mini", null: false
t.text "name", null: false
t.date "date_release"
t.integer "size"
t.integer "nr_cycle_id"
t.integer "nr_set_type_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["code"], name: "index_nr_sets_on_code", unique: true
t.index ["nr_cycle_id"], name: "index_nr_sets_on_nr_cycle_id"
t.index ["nr_set_type_id"], name: "index_nr_sets_on_nr_set_type_id"
end

create_table "printings", force: :cascade do |t|
create_table "printings", id: :string, force: :cascade do |t|
t.text "card_id"
t.text "card_set_id"
t.text "printed_text"
t.boolean "printed_uniqueness"
t.text "code"
t.text "flavor"
t.text "illustrator"
t.integer "position"
t.integer "quantity"
t.date "date_release"
t.integer "card_id"
t.integer "nr_set_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["card_id"], name: "index_printings_on_card_id"
t.index ["code"], name: "index_printings_on_code", unique: true
t.index ["nr_set_id"], name: "index_printings_on_nr_set_id"
end

create_table "sides", force: :cascade do |t|
t.text "code", null: false
create_table "sides", id: :string, force: :cascade do |t|
t.text "name", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["code"], name: "index_sides_on_code", unique: true
end

create_table "subtypes", force: :cascade do |t|
t.text "code", null: false
create_table "subtypes", id: :string, force: :cascade do |t|
t.text "name", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["code"], name: "index_subtypes_on_code", unique: true
end

# create_table "users", force: :cascade do |t|
# t.string "email", default: "", null: false
# t.string "encrypted_password", default: "", null: false
# t.string "reset_password_token"
# t.datetime "reset_password_sent_at", precision: 6
# t.datetime "remember_created_at", precision: 6
# t.datetime "created_at", precision: 6, null: false
# t.datetime "updated_at", precision: 6, null: false
# t.string "name", null: false
# t.string "confirmation_token"
# t.datetime "confirmed_at", precision: 6
# t.datetime "confirmation_sent_at", precision: 6
# t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
# t.index ["email"], name: "index_users_on_email", unique: true
# t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
# end

add_foreign_key "cards", "card_types"
add_foreign_key "cards", "factions"
add_foreign_key "cards", "sides"
add_foreign_key "nr_sets", "nr_cycles"
add_foreign_key "nr_sets", "nr_set_types"
add_foreign_key "printings", "cards"
add_foreign_key "printings", "nr_sets"
add_foreign_key "card_sets", "card_cycles", column: "card_cycle_id", primary_key: "id"
add_foreign_key "card_sets", "card_set_types", column: "card_set_type_id", primary_key: "id"
add_foreign_key "cards_subtypes", "cards", column: "card_id", primary_key: "id"
add_foreign_key "cards_subtypes", "subtypes", column: "subtype_id", primary_key: "id"
add_foreign_key "cards", "card_types", column: "card_type_id", primary_key: "id"
add_foreign_key "cards", "factions", column: "faction_id", primary_key: "id"
add_foreign_key "cards", "sides", column: "side_id", primary_key: "id"
add_foreign_key "printings", "cards", column: "card_id", primary_key: "id"
add_foreign_key "printings", "card_sets", column: "card_set_id", primary_key: "id"
end
Loading