text: /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
  /*!40101 SET NAMES utf8 */;
  /*!50503 SET NAMES utf8mb4 */;
  /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
  /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
  
  DROP DATABASE IF EXISTS `aplikacija`;
  CREATE DATABASE IF NOT EXISTS `aplikacija` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci */ /*!80016 DEFAULT ENCRYPTION='N' */;
  USE `aplikacija`;
  
  DROP TABLE IF EXISTS `administrator`;
  CREATE TABLE IF NOT EXISTS `administrator` (
    `administrator_id` int unsigned NOT NULL AUTO_INCREMENT,
    `username` varchar(32) NOT NULL DEFAULT '0',
    `password_hash` varchar(128) NOT NULL DEFAULT '0',
    PRIMARY KEY (`administrator_id`),
    UNIQUE KEY `uq_administrator_username` (`username`)
  ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  
  DROP TABLE IF EXISTS `administrator_token`;
  CREATE TABLE IF NOT EXISTS `administrator_token` (
    `administrator_token_id` int unsigned NOT NULL AUTO_INCREMENT,
    `administrator_id` int unsigned NOT NULL,
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `token` text NOT NULL,
    `expires_at` datetime NOT NULL,
    `is_valid` tinyint unsigned NOT NULL DEFAULT '1',
    PRIMARY KEY (`administrator_token_id`),
    KEY `fk_administrator_token_administrator_id` (`administrator_id`),
    CONSTRAINT `fk_administrator_token_administrator_id` FOREIGN KEY (`administrator_id`) REFERENCES `administrator` (`administrator_id`) ON UPDATE CASCADE
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  
  DROP TABLE IF EXISTS `article`;
  CREATE TABLE IF NOT EXISTS `article` (
    `article_id` int unsigned NOT NULL AUTO_INCREMENT,
    `name` varchar(128) NOT NULL DEFAULT '0',
    `category_id` int unsigned NOT NULL DEFAULT '0',
    `excerpt` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '0',
    `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
    `status` enum('available','visible','hidden') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT 'available',
    `is_promoted` tinyint unsigned NOT NULL DEFAULT '0',
    `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`article_id`),
    KEY `fk_article_category_id` (`category_id`),
    CONSTRAINT `fk_article_category_id` FOREIGN KEY (`category_id`) REFERENCES `category` (`category_id`) ON UPDATE CASCADE
  ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  
  DROP TABLE IF EXISTS `article_feature`;
  CREATE TABLE IF NOT EXISTS `article_feature` (
    `article_feature_id` int unsigned NOT NULL AUTO_INCREMENT,
    `article_id` int unsigned NOT NULL DEFAULT '0',
    `feature_id` int unsigned NOT NULL DEFAULT '0',
    `value` varchar(255) NOT NULL DEFAULT '0',
    PRIMARY KEY (`article_feature_id`),
    UNIQUE KEY `uq_article_feature_article_id_feature_id` (`article_id`,`feature_id`),
    KEY `fk_article_feature_feature_id` (`feature_id`),
    CONSTRAINT `fk_article_feature_article_id` FOREIGN KEY (`article_id`) REFERENCES `article` (`article_id`) ON DELETE RESTRICT ON UPDATE CASCADE,
    CONSTRAINT `fk_article_feature_feature_id` FOREIGN KEY (`feature_id`) REFERENCES `feature` (`feature_id`) ON DELETE RESTRICT ON UPDATE CASCADE
  ) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  
  DROP TABLE IF EXISTS `article_price`;
  CREATE TABLE IF NOT EXISTS `article_price` (
    `article_price_id` int unsigned NOT NULL AUTO_INCREMENT,
    `article_id` int unsigned NOT NULL,
    `price` decimal(10,2) unsigned NOT NULL DEFAULT '0.00',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`article_price_id`),
    KEY `fk_article_price_article_id` (`article_id`),
    CONSTRAINT `fk_article_price_article_id` FOREIGN KEY (`article_id`) REFERENCES `article` (`article_id`) ON UPDATE CASCADE
  ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  
  DROP TABLE IF EXISTS `cart`;
  CREATE TABLE IF NOT EXISTS `cart` (
    `cart_id` int unsigned NOT NULL AUTO_INCREMENT,
    `user_id` int unsigned NOT NULL DEFAULT '0',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`cart_id`),
    KEY `fk_cart_user_id` (`user_id`),
    CONSTRAINT `fk_cart_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON UPDATE CASCADE
  ) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  
  DROP TABLE IF EXISTS `cart_article`;
  CREATE TABLE IF NOT EXISTS `cart_article` (
    `cart_article_id` int unsigned NOT NULL AUTO_INCREMENT,
    `cart_id` int unsigned NOT NULL DEFAULT '0',
    `article_id` int unsigned NOT NULL DEFAULT '0',
    `quantity` int unsigned NOT NULL DEFAULT '0',
    PRIMARY KEY (`cart_article_id`),
    UNIQUE KEY `uq_fk_cart_article_cart_id_cart_id_article_id` (`cart_id`,`article_id`),
    KEY `fk_cart_article_article_id` (`article_id`),
    CONSTRAINT `fk_cart_article_article_id` FOREIGN KEY (`article_id`) REFERENCES `article` (`article_id`) ON UPDATE CASCADE,
    CONSTRAINT `fk_cart_article_cart_id` FOREIGN KEY (`cart_id`) REFERENCES `cart` (`cart_id`) ON UPDATE CASCADE
  ) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  
  DROP TABLE IF EXISTS `category`;
  CREATE TABLE IF NOT EXISTS `category` (
    `category_id` int unsigned NOT NULL AUTO_INCREMENT,
    `name` varchar(50) NOT NULL,
    `image_path` varchar(50) NOT NULL,
    `parent__category_id` int unsigned DEFAULT NULL,
    PRIMARY KEY (`category_id`),
    UNIQUE KEY `uq_category_name` (`name`),
    UNIQUE KEY `uq_category_image_path` (`image_path`),
    KEY `fk_category_parent__category_id_idx` (`parent__category_id`),
    CONSTRAINT `fk_category_parent__category_id` FOREIGN KEY (`parent__category_id`) REFERENCES `category` (`category_id`) ON DELETE RESTRICT ON UPDATE CASCADE
  ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  
  DROP TABLE IF EXISTS `feature`;
  CREATE TABLE IF NOT EXISTS `feature` (
    `feature_id` int unsigned NOT NULL AUTO_INCREMENT,
    `name` varchar(32) NOT NULL DEFAULT '0',
    `category_id` int unsigned NOT NULL DEFAULT '0',
    PRIMARY KEY (`feature_id`),
    UNIQUE KEY `uq_feature_name_category_id` (`name`,`category_id`),
    KEY `fk_feature_category_id` (`category_id`),
    CONSTRAINT `fk_feature_category_id` FOREIGN KEY (`category_id`) REFERENCES `category` (`category_id`) ON UPDATE CASCADE
  ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  
  DROP TABLE IF EXISTS `order`;
  CREATE TABLE IF NOT EXISTS `order` (
    `order_id` int unsigned NOT NULL AUTO_INCREMENT,
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `cart_id` int unsigned NOT NULL DEFAULT '0',
    `status` enum('rejected','accepted','shipped','pending') DEFAULT 'pending',
    PRIMARY KEY (`order_id`),
    UNIQUE KEY `uq_order_cart_id` (`cart_id`),
    CONSTRAINT `fk_order_cart_id` FOREIGN KEY (`cart_id`) REFERENCES `cart` (`cart_id`) ON UPDATE CASCADE
  ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  
  DROP TABLE IF EXISTS `photo`;
  CREATE TABLE IF NOT EXISTS `photo` (
    `photo_id` int unsigned NOT NULL AUTO_INCREMENT,
    `article_id` int unsigned NOT NULL DEFAULT '0',
    `image_path` varchar(128) NOT NULL DEFAULT '0',
    PRIMARY KEY (`photo_id`),
    UNIQUE KEY `uq_photo_image_path` (`image_path`),
    KEY `fk_photo_article_id` (`article_id`),
    CONSTRAINT `fk_photo_article_id` FOREIGN KEY (`article_id`) REFERENCES `article` (`article_id`) ON UPDATE CASCADE
  ) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  
  DROP TABLE IF EXISTS `user`;
  CREATE TABLE IF NOT EXISTS `user` (
    `user_id` int unsigned NOT NULL AUTO_INCREMENT,
    `email` varchar(255) NOT NULL DEFAULT '0',
    `password_hash` varchar(128) NOT NULL DEFAULT '0',
    `firstname` varchar(64) NOT NULL DEFAULT '0',
    `lastname` varchar(64) NOT NULL DEFAULT '0',
    `phone_number` varchar(24) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL DEFAULT '0',
    `postal_address` text NOT NULL,
    PRIMARY KEY (`user_id`),
    UNIQUE KEY `uq_user_email` (`email`),
    UNIQUE KEY `uq_user_phone_number` (`phone_number`)
  ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  
  DROP TABLE IF EXISTS `user_token`;
  CREATE TABLE IF NOT EXISTS `user_token` (
    `user_token_id` int unsigned NOT NULL AUTO_INCREMENT,
    `user_id` int unsigned NOT NULL DEFAULT '0',
    `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `token` text NOT NULL,
    `expires_at` datetime NOT NULL,
    `is_valid` tinyint unsigned NOT NULL DEFAULT '1',
    PRIMARY KEY (`user_token_id`),
    KEY `fk_user_token_user_id` (`user_id`),
    CONSTRAINT `fk_user_token_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON UPDATE CASCADE
  ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  
  /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
  /*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */;
  /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
  