/*==============================================================*/
/* DBMS name:      MySQL 5.0                                    */
/* Created on:     2018/5/29 23:27:02                           */
/*==============================================================*/


drop table if exists cleaner_district;

drop table if exists merchant_auth_area;

drop table if exists rel_cleaner_district_auth_area;

/*==============================================================*/
/* Table: cleaner_district                                      */
/*==============================================================*/
create table cleaner_district
(
   id                   int not null auto_increment,
   merchant_id          bigint not null comment '商户主键ID',
   merchant_no          varchar(32) comment '商户编号',
   province_id          int comment '省ID',
   province_name        varchar(20) comment '省名称',
   city_id              int comment '市ID',
   city_name            varchar(20) comment '市名称',
   district_id          int comment '区/县ID',
   district_name        varchar(255) comment '区/县名称',
   del_flag             tinyint comment '删除标志',
   primary key (id)
);

/*==============================================================*/
/* Table: merchant_auth_area                                    */
/*==============================================================*/
create table merchant_auth_area
(
   id                   int not null auto_increment,
   merchant_id          bigint not null comment '商户主键ID',
   merchant_no          varchar(32) comment '商户编号',
   province_id          int comment '省ID',
   province_name        varchar(20) comment '省名称',
   city_id              int comment '市ID',
   city_name            varchar(20) comment '市名称',
   district_id          int comment '区/县ID',
   district_name        varchar(255) comment '区/县名称',
   is_open              tinyint comment '是否开放：0-不开放，1-开放',
   is_auth              tinyint comment '是否授权：0-未授权，1-已授权',
   created_at           bigint comment '创建时间',
   created_by           varchar(32) comment '创建人',
   updated_at           bigint comment '更新时间',
   updated_by           varchar(32) comment '更新人',
   del_flag             tinyint comment '删除标志',
   primary key (id)
);

/*==============================================================*/
/* Table: rel_cleaner_district_auth_area                        */
/*==============================================================*/
create table rel_cleaner_district_auth_area
(
   merchant_auth_area_id int not null comment '商户授权表主键ID',
   cleaner_district_id  int not null comment '归属区/县主键ID',
   primary key (merchant_auth_area_id, cleaner_district_id)
);


alter table cleaner_info add cleaner_district_id VARCHAR(32) COMMENT '归属区/县ID';

