-- MySQL Script generated by MySQL Workbench
-- Mon Mar 30 22:13:37 2026
-- 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='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema FSST
-- -----------------------------------------------------

-- -----------------------------------------------------
-- Schema FSST
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `FSST` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci ;
USE `FSST` ;

-- -----------------------------------------------------
-- Table `FSST`.`attributes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `FSST`.`attributes` (
  `attributeID` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(255) NOT NULL,
  `unit` VARCHAR(50) NULL DEFAULT NULL,
  `dataType` VARCHAR(20) NULL DEFAULT NULL,
  PRIMARY KEY (`attributeID`))
ENGINE = InnoDB
AUTO_INCREMENT = 70
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;


-- -----------------------------------------------------
-- Table `FSST`.`brands`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `FSST`.`brands` (
  `brandID` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(255) NOT NULL,
  PRIMARY KEY (`brandID`))
ENGINE = InnoDB
AUTO_INCREMENT = 8
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;


-- -----------------------------------------------------
-- Table `FSST`.`categories`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `FSST`.`categories` (
  `categoryID` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(255) NOT NULL,
  `parentCategoryID` INT NULL DEFAULT NULL,
  PRIMARY KEY (`categoryID`),
  INDEX `categories_ibfk_1` (`parentCategoryID` ASC) VISIBLE,
  CONSTRAINT `categories_ibfk_1`
    FOREIGN KEY (`parentCategoryID`)
    REFERENCES `FSST`.`categories` (`categoryID`)
    ON DELETE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 26
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;


-- -----------------------------------------------------
-- Table `FSST`.`categoryAttributes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `FSST`.`categoryAttributes` (
  `categoryID` INT NOT NULL,
  `attributeID` INT NOT NULL,
  PRIMARY KEY (`categoryID`, `attributeID`),
  INDEX `attributeID` (`attributeID` ASC) VISIBLE,
  CONSTRAINT `categoryAttributes_ibfk_1`
    FOREIGN KEY (`categoryID`)
    REFERENCES `FSST`.`categories` (`categoryID`),
  CONSTRAINT `categoryAttributes_ibfk_2`
    FOREIGN KEY (`attributeID`)
    REFERENCES `FSST`.`attributes` (`attributeID`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;


-- -----------------------------------------------------
-- Table `FSST`.`users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `FSST`.`users` (
  `userID` INT NOT NULL AUTO_INCREMENT,
  `email` VARCHAR(255) NOT NULL,
  `passwordHash` VARCHAR(255) NOT NULL,
  `displayName` VARCHAR(255) NULL DEFAULT NULL,
  `isActive` TINYINT(1) NOT NULL DEFAULT '1',
  `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `profilePicture` VARCHAR(255) NULL DEFAULT NULL,
  PRIMARY KEY (`userID`),
  UNIQUE INDEX `email` (`email` ASC) VISIBLE)
ENGINE = InnoDB
AUTO_INCREMENT = 45
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;


-- -----------------------------------------------------
-- Table `FSST`.`notifications`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `FSST`.`notifications` (
  `notificationID` INT NOT NULL AUTO_INCREMENT,
  `userID` INT NOT NULL,
  `title` VARCHAR(255) NOT NULL,
  `message` TEXT NOT NULL,
  `isRead` TINYINT(1) NOT NULL DEFAULT '0',
  `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`notificationID`),
  INDEX `fk_notifications_user` (`userID` ASC) VISIBLE,
  CONSTRAINT `fk_notifications_user`
    FOREIGN KEY (`userID`)
    REFERENCES `FSST`.`users` (`userID`)
    ON DELETE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 4
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;


-- -----------------------------------------------------
-- Table `FSST`.`products`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `FSST`.`products` (
  `productID` INT NOT NULL AUTO_INCREMENT,
  `categoryID` INT NOT NULL,
  `brandID` INT NOT NULL,
  `model` VARCHAR(255) NOT NULL,
  `description` TEXT NULL DEFAULT NULL,
  `imagePath` VARCHAR(255) NULL DEFAULT NULL,
  PRIMARY KEY (`productID`),
  INDEX `categoryID` (`categoryID` ASC) VISIBLE,
  INDEX `brandID` (`brandID` ASC) VISIBLE,
  CONSTRAINT `products_ibfk_1`
    FOREIGN KEY (`categoryID`)
    REFERENCES `FSST`.`categories` (`categoryID`),
  CONSTRAINT `products_ibfk_2`
    FOREIGN KEY (`brandID`)
    REFERENCES `FSST`.`brands` (`brandID`))
ENGINE = InnoDB
AUTO_INCREMENT = 1347
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;


-- -----------------------------------------------------
-- Table `FSST`.`shops`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `FSST`.`shops` (
  `shopID` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(255) NOT NULL,
  `website` VARCHAR(255) NULL DEFAULT NULL,
  `logoPath` VARCHAR(255) NULL DEFAULT NULL,
  `shippingTime` VARCHAR(255) NULL DEFAULT NULL,
  PRIMARY KEY (`shopID`))
ENGINE = InnoDB
AUTO_INCREMENT = 7
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;


-- -----------------------------------------------------
-- Table `FSST`.`offers`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `FSST`.`offers` (
  `offerID` INT NOT NULL AUTO_INCREMENT,
  `productID` INT NOT NULL,
  `shopID` INT NOT NULL,
  `price` DECIMAL(10,2) NOT NULL,
  `shippingCost` DECIMAL(10,2) NULL DEFAULT NULL,
  `inStock` TINYINT(1) NULL DEFAULT NULL,
  `offerURL` VARCHAR(255) NULL DEFAULT NULL,
  PRIMARY KEY (`offerID`),
  INDEX `productID` (`productID` ASC) VISIBLE,
  INDEX `shopID` (`shopID` ASC) VISIBLE,
  CONSTRAINT `offers_ibfk_1`
    FOREIGN KEY (`productID`)
    REFERENCES `FSST`.`products` (`productID`),
  CONSTRAINT `offers_ibfk_2`
    FOREIGN KEY (`shopID`)
    REFERENCES `FSST`.`shops` (`shopID`))
ENGINE = InnoDB
AUTO_INCREMENT = 10
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;


-- -----------------------------------------------------
-- Table `FSST`.`priceAlerts`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `FSST`.`priceAlerts` (
  `alertID` INT NOT NULL AUTO_INCREMENT,
  `userID` INT NOT NULL,
  `productID` INT NOT NULL,
  `targetPrice` DECIMAL(10,2) NOT NULL,
  `isActive` TINYINT(1) NOT NULL DEFAULT '1',
  `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`alertID`),
  INDEX `fk_pricealerts_user` (`userID` ASC) VISIBLE,
  INDEX `fk_pricealerts_product` (`productID` ASC) VISIBLE,
  CONSTRAINT `fk_pricealerts_product`
    FOREIGN KEY (`productID`)
    REFERENCES `FSST`.`products` (`productID`)
    ON DELETE CASCADE,
  CONSTRAINT `fk_pricealerts_user`
    FOREIGN KEY (`userID`)
    REFERENCES `FSST`.`users` (`userID`)
    ON DELETE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 4
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;


-- -----------------------------------------------------
-- Table `FSST`.`productAttributes`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `FSST`.`productAttributes` (
  `productID` INT NOT NULL,
  `attributeID` INT NOT NULL,
  `valueString` VARCHAR(255) NULL DEFAULT NULL,
  `valueNumber` DECIMAL(10,2) NULL DEFAULT NULL,
  `valueBool` TINYINT(1) NULL DEFAULT NULL,
  PRIMARY KEY (`productID`, `attributeID`),
  INDEX `attributeID` (`attributeID` ASC) VISIBLE,
  CONSTRAINT `productAttributes_ibfk_1`
    FOREIGN KEY (`productID`)
    REFERENCES `FSST`.`products` (`productID`),
  CONSTRAINT `productAttributes_ibfk_2`
    FOREIGN KEY (`attributeID`)
    REFERENCES `FSST`.`attributes` (`attributeID`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;


-- -----------------------------------------------------
-- Table `FSST`.`reviews`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `FSST`.`reviews` (
  `reviewID` INT NOT NULL AUTO_INCREMENT,
  `userID` INT NOT NULL,
  `productID` INT NOT NULL,
  `rating` INT NOT NULL,
  `comment` TEXT NULL DEFAULT NULL,
  `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`reviewID`),
  INDEX `fk_reviews_user` (`userID` ASC) VISIBLE,
  INDEX `fk_reviews_product` (`productID` ASC) VISIBLE,
  CONSTRAINT `fk_reviews_product`
    FOREIGN KEY (`productID`)
    REFERENCES `FSST`.`products` (`productID`)
    ON DELETE CASCADE,
  CONSTRAINT `fk_reviews_user`
    FOREIGN KEY (`userID`)
    REFERENCES `FSST`.`users` (`userID`)
    ON DELETE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 42
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;


-- -----------------------------------------------------
-- Table `FSST`.`roles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `FSST`.`roles` (
  `roleID` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(50) NOT NULL,
  PRIMARY KEY (`roleID`),
  UNIQUE INDEX `name` (`name` ASC) VISIBLE)
ENGINE = InnoDB
AUTO_INCREMENT = 4
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;


-- -----------------------------------------------------
-- Table `FSST`.`userFavorites`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `FSST`.`userFavorites` (
  `userID` INT NOT NULL,
  `productID` INT NOT NULL,
  `createdAt` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`userID`, `productID`),
  INDEX `fk_favorites_product` (`productID` ASC) VISIBLE,
  CONSTRAINT `fk_favorites_product`
    FOREIGN KEY (`productID`)
    REFERENCES `FSST`.`products` (`productID`)
    ON DELETE CASCADE,
  CONSTRAINT `fk_favorites_user`
    FOREIGN KEY (`userID`)
    REFERENCES `FSST`.`users` (`userID`)
    ON DELETE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;


-- -----------------------------------------------------
-- Table `FSST`.`userRoles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `FSST`.`userRoles` (
  `userID` INT NOT NULL,
  `roleID` INT NOT NULL,
  PRIMARY KEY (`userID`, `roleID`),
  INDEX `fk_userroles_role` (`roleID` ASC) VISIBLE,
  CONSTRAINT `fk_userroles_role`
    FOREIGN KEY (`roleID`)
REFERENCES `FSST`.`roles` (`roleID`)
    ON DELETE CASCADE,
  CONSTRAINT `fk_userroles_user`
    FOREIGN KEY (`userID`)
    REFERENCES `FSST`.`users` (`userID`)
    ON DELETE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;


-- -----------------------------------------------------
-- Table `FSST`.`userSessions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `FSST`.`userSessions` (
  `sessionID` VARCHAR(128) NOT NULL,
  `userID` INT NOT NULL,
  `expiresAt` TIMESTAMP NOT NULL,
  PRIMARY KEY (`sessionID`),
  INDEX `fk_sessions_user` (`userID` ASC) VISIBLE,
  CONSTRAINT `fk_sessions_user`
    FOREIGN KEY (`userID`)
    REFERENCES `FSST`.`users` (`userID`)
    ON DELETE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;


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