/*==============================================================*/
/* Nom de SGBD :  MySQL 5.0                                     */
/* Date de cr�ation :  24/11/2020 16:14:35                      */
/*==============================================================*/


/*==============================================================*/
/* Table : MJ_BLACKLIST_IP                                      */
/*==============================================================*/
create table MJ_BLACKLIST_IP
(
   ID_BLACKLIST         int not null auto_increment  comment '',
   IP                   varchar(15) not null  comment '',
   DATE_BAN             datetime not null  comment '',
   primary key (ID_BLACKLIST)
);

/*==============================================================*/
/* Table : MJ_GAME                                              */
/*==============================================================*/
create table MJ_GAME
(
   ID_GAME              int not null auto_increment  comment '',
   PRIVATE              bool not null  comment '',
   CREATION_TIME        timestamp not null  comment '',
   primary key (ID_GAME)
);

/*==============================================================*/
/* Table : MJ_ROLE                                              */
/*==============================================================*/
create table MJ_ROLE
(
   ID_ROLE              int not null auto_increment  comment '',
   NAME                 varchar(15) not null  comment '',
   primary key (ID_ROLE)
);

/*==============================================================*/
/* Table : MJ_USER                                              */
/*==============================================================*/
create table MJ_USER
(
   ID_USER              int not null auto_increment  comment '',
   ID_ROLE              int  comment '',
   LOGIN                varchar(16) not null  comment '',
   PASWORD              char(80) not null  comment '',
   AVATAR               char(255)  comment '',
   LASTNAME             char(55)  comment '',
   FIRSTNAME            char(55)  comment '',
   MAIL                 char(64) not null  comment '',
   BAN_ACCOUNT          bool  comment '',
   LAST_IP              varchar(15)  comment '',
   primary key (ID_USER),
   constraint FK_MJ_USER_MJ_HAS_MJ_ROLE foreign key (ID_ROLE)
      references MJ_ROLE (ID_ROLE) on delete restrict on update restrict
);

/*==============================================================*/
/* Table : MJ_ROUND                                             */
/*==============================================================*/
create table MJ_ROUND
(
   ID_ROUND             int not null auto_increment  comment '',
   ID_GAME              int  comment '',
   PREVAILING_WIND      int not null  comment '',
   SEED                 int not null  comment '',
   BEGINING             timestamp  comment '',
   ENDING               timestamp  comment '',
   ACTIONS              text  comment '',
   primary key (ID_ROUND),
   constraint FK_MJ_ROUND_MJ_COMPOS_MJ_GAME foreign key (ID_GAME)
      references MJ_GAME (ID_GAME) on delete restrict on update restrict
);

/*==============================================================*/
/* Table : MJ_PLAY                                              */
/*==============================================================*/
create table MJ_PLAY
(
   ID_USER              int not null  comment '',
   ID_ROUND             int not null  comment '',
   WIN                  bool  comment '',
   SCORE                int  comment '',
   HOST                 bool  comment '',
   WIND                 int  comment '',
   primary key (ID_USER, ID_ROUND),
   constraint FK_MJ_PLAY_PLAY2_MJ_USER foreign key (ID_USER)
      references MJ_USER (ID_USER) on delete restrict on update cascade,
   constraint FK_MJ_PLAY_MJ_PLAY_MJ_ROUND foreign key (ID_ROUND)
      references MJ_ROUND (ID_ROUND) on delete restrict on update cascade
);

