0

I'm working on a fantasy racing team project. I'm having trouble laying out the schema when it comes to the team table and the trades. I think I have the race, driver, and result tables laid out okay:

Fantasy Racing Team Schema

Each team has to have 10 drivers; two in group one, three in group two, and five in group three.

Each team may have two trades throughout the season. The traded and obtained columns are there so I can calculate who is on a team at a specific race (or point in time). For example, if there were three races and driver_1_1 was traded away after the first race, the team would only get that driver's points for the first race. For the last two races they would get points from the driver that driver_1_1 was traded for.

I have a strong feeling that the team table can be done in a much better way, but I'm having trouble wrapping my head around it, especially because of the trades. Please help me normalize!

If it matters I'm planning on using the latest Django Python and PostgreSQL.

EDIT:

Here's a simplified version of the schema without all of the fluff. I've also gotten rid of the hard coded driver columns and replaced them with a pick table. There's still the matter of the trades, and whether or not this is the right way to go about something something like this. Better?

Is this better?

  • 1
    Almost half of the team table is devoted to trading of some sort. Can you explain what that is about and why there are "hard-coded" driver positions? These columns seem like they should be rows in a new table but I don't understand the domain. – Greg Oct 21 '15 at 20:35
  • The traded and obtained columns are there so I can calculate who is on a team at a specific race (or point in time). For example, if there were three races and driver_1_1 was traded away after the first race, the team would only get that driver's points for the first race. For the last two races they would get points from the driver that driver_1_1 was traded for. – Ty. Oct 21 '15 at 21:02
  • I've also updated my question with a picks table that replaces the hard-coded driver columns. Is this the right way to go about something like this? – Ty. Oct 21 '15 at 21:14
  • 1
    This looks much, much better. The queries might be a bit complex, but that just reflects the complexity of the problems you're trying to solve. – Greg Oct 22 '15 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.