Matches - non-sono-bello-ma-patcho/BD_LAB GitHub Wiki

Matches is another pivotale table: a premium user can arrange an event (a match), each match has an univocal identifier, an execution date, a state field(open, closed), belong to one of the categories managed by the platform and takes place within a Genoa CUS's building.

matchER

As the matches entity have a bunch of associations I preferred to just the few which appear in the sql translation as buildings and categories. Actually, as I already discussed on Categories's page category column won't directly reference categories table but will use sport datatype:

create table Matches (
  id bigserial primary key,
  building varchar(64) references Buildings on update cascade on delete cascade,
  category sport,
  organizedOn date not null,
  insertedOn date not null,
  tournament varchar(64) references Tournaments on update cascade on delete cascade,
  mstate state default 'open',
  admin varchar(64) references Users on update cascade on delete cascade
);

One thing you can notice is that the association one to one between Tournaments and this table had been translated as an additional column for the matches table, due to the fact that tournaments'name is primary key and so can't be repeated more than once.