mardi 5 janvier 2016

How to Link Multiple Tables in a Database

I'm trying to create a database that will allow users to create a character. Each character has a race, a class and a background. Depending on the class and background, the character will have different starting equipment. Depending on the race, the character will receive a racial bonus. Lastly, depending on the class, the character will be able to unlock abilities as they level up.

I'm having a hard time grasping how to link these tables together to create a logical database, with the least redundant information. Here is what I have so far:

  1. users

    • id (primary key)
    • username
    • email
    • encrypted_password
    • salt
    • remember_token
    • admin
  2. characters

    • id (primary key)
    • name
    • race (foreign key = race.id)
    • class_ (foreign key = class.id)
    • user_id (foreign key = user.id)
    • experience
    • background (foreign key = background.id)
  3. race

    • id (primary key)
    • name
    • speed
    • racial_bonus
    • language
  4. background

    • id (primary key)
    • name
    • skill_proficiencies
    • tool_proficiencies
    • language
  5. class

    • id (primary key)
    • name
    • hit_dice
    • armor_proficiencies
    • weapon_proficiencies
    • tools
    • saving_throws
    • skill_proficiencies
  6. inventory

    • id
    • character_id (foreign key = character.id)
    • class_equipment
    • background_equipment
    • inventory

I'm creating this database using SQLite with Ruby on Rails, and the user will be prompted for the race, class and background of their character. The main goal is to be able to pull up the info from the other database tables since a lot of the character's stats are based on race and class, and these are constant.

Is this possible and, if so, how would I go about adding entries to the race, background, and class database tables?

Aucun commentaire:

Enregistrer un commentaire