/*==============================================================*/
/* DBMS name:      MySQL 5.0                                    */
/* Created on:     2023/6/8 10:59:13                            */
/*==============================================================*/


drop table if exists company;

drop table if exists orders;

drop table if exists photo;

drop table if exists product;

drop table if exists worker;

/*==============================================================*/
/* Table: company                                               */
/*==============================================================*/
create table company
(
   com_id               bigint not null comment '影楼编号',
   user_id              bigint,
   com_name             varchar(128) comment '影楼名称',
   com_img              bigint comment '影楼图片',
   com_img_list         varchar(512) comment '影楼图片列表',
   com_address          varchar(256) comment '影楼地点',
   com_tel              varchar(64) comment '影楼联系电话',
   com_desc             varchar(2000) comment '影楼简介',
   com_json             varchar(2000) comment '影楼JSON',
   com_score            int comment '影楼评分',
   primary key (com_id)
);

alter table company comment '影楼';

/*==============================================================*/
/* Table: orders                                                */
/*==============================================================*/
create table orders
(
   order_id             bigint not null comment '编号',
   user_id              bigint comment '用户编号',
   worker_user_id       bigint comment '摄影师用户编号',
   product_id           bigint comment '摄影套餐编号',
   order_price          int comment '实际价格',
   order_create_time    datetime comment '创建时间',
   order_sub_time       datetime comment '预约时间',
   order_exec_time      datetime comment '执行时间',
   order_desc           varchar(256) comment '客户说明',
   order_status         int comment '订单状态',
   primary key (order_id)
);

alter table orders comment '摄影订单';

/*==============================================================*/
/* Table: photo                                                 */
/*==============================================================*/
create table photo
(
   photo_id             bigint not null comment '编号',
   order_id             bigint comment '编号',
   photo_src            bigint comment '原图编号',
   photo_big            bigint comment '大图编号',
   photo_small          bigint comment '小图编号',
   photo_selected       bool comment '已选',
   photo_time           datetime comment '上传时间',
   primary key (photo_id)
);

alter table photo comment '照片信息';

/*==============================================================*/
/* Table: product                                               */
/*==============================================================*/
create table product
(
   product_id           bigint not null comment '摄影套餐编号',
   com_id               bigint comment '影楼编号',
   product_name         varchar(128) comment '摄影套餐名称',
   product_photo_num    int comment '摄影套餐照片数量',
   product_clothing_num int comment '摄影套餐服装套数',
   product_scene_num    int comment '摄影套餐场景数',
   product_price        int comment '摄影套餐价格',
   product_desc         varchar(2000) comment '摄影套餐简介',
   product_time         datetime comment '摄影套餐创建时间',
   product_putaway      bool comment '摄影套餐是否上架',
   primary key (product_id)
);

alter table product comment '摄影套餐';

/*==============================================================*/
/* Table: worker                                                */
/*==============================================================*/
create table worker
(
   user_id              bigint not null,
   com_id               bigint comment '影楼编号',
   worker_json          varchar(2000) comment '摄影师JSON',
   worker_desc          varchar(2000) comment '摄影师简介',
   primary key (user_id)
);

alter table worker comment '摄影师';

alter table orders add constraint fk_r_6 foreign key (product_id)
      references product (product_id) on delete restrict on update restrict;

alter table photo add constraint fk_r_9 foreign key (order_id)
      references orders (order_id) on delete restrict on update restrict;

alter table product add constraint fk_r_5 foreign key (com_id)
      references company (com_id) on delete restrict on update restrict;

alter table worker add constraint fk_r_2 foreign key (com_id)
      references company (com_id) on delete restrict on update restrict;

