<filename>mall.sql
-- MySQL Script generated by MySQL Workbench
-- Thu Jun 13 15:30:20 2019
-- Model: New Model    Version: 1.0
-- MySQL Workbench Forward Engineering

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='';

-- -----------------------------------------------------
-- Schema mall
-- -----------------------------------------------------
DROP SCHEMA IF EXISTS `mall` ;

-- -----------------------------------------------------
-- Schema mall
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `mall` DEFAULT CHARACTER SET utf8mb4 ;
USE `mall` ;

-- -----------------------------------------------------
-- Table `mall`.`m_user`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mall`.`m_user` ;

CREATE TABLE IF NOT EXISTS `mall`.`m_user` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `nickname` VARCHAR(40) NULL COMMENT '昵称',
  `avatar` VARCHAR(255) NULL COMMENT '头像',
  `openid` VARCHAR(40) NOT NULL,
  `created_at` INT NOT NULL,
  `created_ip` VARCHAR(15) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE INDEX `openid_UNIQUE` (`openid` ASC))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mall`.`m_goods`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mall`.`m_goods` ;

CREATE TABLE IF NOT EXISTS `mall`.`m_goods` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `title` VARCHAR(40) NOT NULL COMMENT '商品名称',
  `thumb` VARCHAR(255) NOT NULL COMMENT '商品缩略图',
  `description` VARCHAR(100) NULL COMMENT '商品简介',
  `price` DECIMAL(6,2) UNSIGNED NOT NULL COMMENT '价格',
  `stock` INT NOT NULL COMMENT '库存',
  `status` TINYINT(1) UNSIGNED NOT NULL COMMENT '状态',
  `images` JSON NULL COMMENT '内容图片',
  `content` TEXT NULL COMMENT '商品详情',
  `tags` JSON NULL COMMENT '商品标签',
  `created_at` INT NOT NULL,
  `updated_at` INT NOT NULL,
  PRIMARY KEY (`id`))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mall`.`m_address`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mall`.`m_address` ;

CREATE TABLE IF NOT EXISTS `mall`.`m_address` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `realname` VARCHAR(10) NOT NULL,
  `phone` VARCHAR(11) NOT NULL,
  `address` VARCHAR(100) NOT NULL,
  `default` TINYINT NOT NULL DEFAULT 0,
  `user_id` INT UNSIGNED NOT NULL,
  PRIMARY KEY (`id`),
  INDEX `fk_m_address_m_user_idx` (`user_id` ASC))
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mall`.`m_order`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mall`.`m_order` ;

CREATE TABLE IF NOT EXISTS `mall`.`m_order` (
  `order_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `title` VARCHAR(40) NOT NULL COMMENT '订单名称',
  `price` DECIMAL(6,2) NOT NULL COMMENT '订单价格',
  `status` TINYINT NOT NULL COMMENT '订单状态',
  `realname` VARCHAR(10) NOT NULL COMMENT '收货人名称',
  `phone` VARCHAR(11) NOT NULL COMMENT '收货人手机',
  `address` VARCHAR(100) NOT NULL COMMENT '收货人地址',
  `remark` VARCHAR(100) NULL COMMENT '备注',
  `snapshot` JSON NOT NULL COMMENT '商品快照',
  `created_at` INT NOT NULL,
  `goods_id` INT UNSIGNED NOT NULL,
  `user_id` INT UNSIGNED NOT NULL,
  PRIMARY KEY (`order_id`),
  INDEX `fk_m_order_m_goods1_idx` (`goods_id` ASC),
  INDEX `fk_m_order_m_user1_idx` (`user_id` ASC))
ENGINE = InnoDB;


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
