-- --------------------------------------------------------
-- Host:                         127.0.0.1
-- Server version:               10.4.32-MariaDB - mariadb.org binary distribution
-- Server OS:                    Win64
-- HeidiSQL Version:             12.12.0.7122
-- --------------------------------------------------------

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!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' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;


-- Dumping database structure for webshop
CREATE DATABASE IF NOT EXISTS `webshop` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */;
USE `webshop`;

-- Dumping structure for table webshop.categories
CREATE TABLE IF NOT EXISTS `categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'kategorijas identifikators',
  `name` varchar(100) NOT NULL COMMENT 'kategorijas nosaukums',
  `description` varchar(100) NOT NULL COMMENT 'kategorijas apraksts',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='kategoriju tabula.';

-- Data exporting was unselected.

-- Dumping structure for table webshop.orders
CREATE TABLE IF NOT EXISTS `orders` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'produkta identifikators',
  `user_id` int(11) NOT NULL COMMENT 'ārējā atslēga',
  `status` varchar(50) DEFAULT 'pending' COMMENT 'statuss',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'datums, kad tika veikts pasūtījums',
  PRIMARY KEY (`id`),
  KEY `user_id` (`user_id`),
  CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='pasūtījuma tabula.';

-- Data exporting was unselected.

-- Dumping structure for table webshop.order_items
CREATE TABLE IF NOT EXISTS `order_items` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ieraksta identifikators',
  `order_id` int(11) NOT NULL COMMENT 'ārējā atslēga tabulai orders',
  `product_id` int(11) NOT NULL COMMENT 'ārējā atslēga tabulai products',
  `quantity` int(11) NOT NULL DEFAULT 1 COMMENT 'produkta skaits',
  PRIMARY KEY (`id`),
  KEY `order_id` (`order_id`),
  KEY `product_id` (`product_id`),
  CONSTRAINT `order_items_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE,
  CONSTRAINT `order_items_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='pasūtījumu tabula.';

-- Data exporting was unselected.

-- Dumping structure for table webshop.products
CREATE TABLE IF NOT EXISTS `products` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'produkta identifikators',
  `name` varchar(100) NOT NULL COMMENT 'produkta nosaukums',
  `description` text DEFAULT NULL COMMENT 'produkta apraksts',
  `price` int(11) NOT NULL COMMENT 'produkta cena',
  `category_id` int(11) NOT NULL COMMENT 'kategorijas identfikators',
  `image` varchar(255) DEFAULT NULL COMMENT 'produkta attēls',
  PRIMARY KEY (`id`),
  KEY `category_id` (`category_id`),
  CONSTRAINT `products_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='produktu tabula.';

-- Data exporting was unselected.

-- Dumping structure for table webshop.users
CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'lietotāja identifikators',
  `name` varchar(25) NOT NULL COMMENT 'lietotāja vārds',
  `email` varchar(255) NOT NULL COMMENT 'lietotāja e-pasts',
  `password` varchar(255) NOT NULL COMMENT 'parole',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'datums, kad tika izveidots konts',
  PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='lietotāju tabula.';

-- Data exporting was unselected.

/*!40103 SET TIME_ZONE=IFNULL(@OLD_TIME_ZONE, 'system') */;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;
