/*==============================================================*/
/* Nom de SGBD :  MySQL 5.0                                     */
/* Date de création :  23/11/2020 18:08:41                      */
/*==============================================================*/


/*==============================================================*/
/* 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_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(40) 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_ROOM                                              */
/*==============================================================*/
create table MJ_ROOM
(
   ID_ROOM              int not null auto_increment  comment '',
   ID_USER              int  comment '',
   PRIVATE              bool not null  comment '',
   DATE_BEGIN           datetime not null  comment '',
   DATE_END             datetime  comment '',
   primary key (ID_ROOM),
   constraint FK_MJ_ROOM_MJ_CREATI_MJ_USER foreign key (ID_USER)
      references MJ_USER (ID_USER) on delete restrict on update restrict
);

/*==============================================================*/
/* Table : MJ_GAME                                              */
/*==============================================================*/
create table MJ_GAME
(
   ID_GAME              int not null auto_increment  comment '',
   ID_ROOM              int  comment '',
   DATE_BEGIN           datetime not null  comment '',
   DATE_END             datetime  comment '',
   primary key (ID_GAME),
   constraint FK_MJ_GAME_MJ_HOST_MJ_ROOM foreign key (ID_ROOM)
      references MJ_ROOM (ID_ROOM) on delete restrict on update restrict
);

/*==============================================================*/
/* Table : MJ_PLAY                                              */
/*==============================================================*/
create table MJ_PLAY
(
   ID_GAME              int not null  comment '',
   ID_USER              int not null  comment '',
   WIN                  bool  comment '',
   primary key (ID_GAME, ID_USER),
   constraint FK_MJ_PLAY_PLAY_MJ_GAME foreign key (ID_GAME)
      references MJ_GAME (ID_GAME) on delete restrict on update restrict,
   constraint FK_MJ_PLAY_PLAY2_MJ_USER foreign key (ID_USER)
      references MJ_USER (ID_USER) 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 '',
   WIND                 int not null  comment '',
   SEED                 int not null  comment '',
   DATE_BEGIN           datetime not null  comment '',
   DATE_END             datetime  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
);

