DROP TABLE IF EXISTS shoppingmall.tw_product;
CREATE TABLE shoppingmall.tw_product (
    uid varchar(36) NOT NULL,
    category_uid int(10) UNSIGNED NOT NULL COMMENT '상품분류',
    user_uid varchar(36) NULL COMMENT '생산자 정보',
    name varchar(255) NOT NULL COMMENT '상품명',
    photo varchar(50) NULL COMMENT '이미지',
    cost int(10) UNSIGNED NOT NULL COMMENT '원가',
    price int(10) UNSIGNED NOT NULL COMMENT '판매가',
    sale int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '할인가',
    stock int(5) UNSIGNED DEFAULT 1 NULL COMMENT '재고수량',
    view_cnt int(4) UNSIGNED DEFAULT 1 NOT NULL DEFAULT 0 COMMENT '조회수',
    content text NOT NULL COMMENT '상품정보',
    status varchar(10) NOT NULL DEFAULT 'use' COMMENT 'use: 판매, unuse: 판매않함, standby: 판매준비, hold: 판매중지 soldout: 상품부족 등등',
    updated_at timestamp NULL DEFAULT NULL,
    created_at timestamp NOT NULL DEFAULT current_timestamp(),
    deleted_at timestamp NULL DEFAULT NULL,
    PRIMARY KEY (uid),
    CONSTRAINT FOREIGN KEY (category_uid) REFERENCES tw_category (uid),
    CONSTRAINT FOREIGN KEY (user_uid) REFERENCES tw_user (uid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT ='상품 정보';

DROP TABLE IF EXISTS shoppingmall.tw_order;
CREATE TABLE shoppingmall.tw_order (
    uid varchar(36) NOT NULL,
    product_uid varchar(36) NULL COMMENT '상품 정보',
    user_uid varchar(36) NULL COMMENT '사용자 정보',
    name varchar(255) NOT NULL COMMENT '상품명',
    quantity varchar(255) NOT NULL COMMENT '수량',
    price int(10) UNSIGNED NOT NULL COMMENT '구매가',
    status varchar(10) NOT NULL DEFAULT 'use' COMMENT 'use: 주문대기, unuse: 사용않함 등등',
    updated_at timestamp NULL DEFAULT NULL,
    created_at timestamp NOT NULL DEFAULT current_timestamp(),
    deleted_at timestamp NULL DEFAULT NULL,
    PRIMARY KEY (uid),
    CONSTRAINT FOREIGN KEY (product_uid) REFERENCES tw_product (uid),
    CONSTRAINT FOREIGN KEY (user_uid) REFERENCES tw_user (uid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT ='Order 정보';

DROP TABLE IF EXISTS shoppingmall.tw_order_history;

CREATE TABLE shoppingmall.tw_order_history (
    uid int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    user_uid varchar(36) NULL COMMENT '작성자 정보',
    reason varchar(255) NULL COMMENT '사유',
    status varchar(10) NOT NULL DEFAULT 'use' COMMENT 'use: 배송중, unuse:반송중, exchange:교환처리, refund,환불처리, confirm: 확인완료 등등',
    updated_at timestamp NULL DEFAULT NULL,
    created_at timestamp NOT NULL DEFAULT current_timestamp(),
    PRIMARY KEY (uid),
    CONSTRAINT FOREIGN KEY (user_uid) REFERENCES tw_user (uid),
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT ='배송 History정보';