-- --------------------------------------------------------
-- Server OS:                    Win64
-- HeidiSQL Version:             12.12.0.7122
-- --------------------------------------------------------



-- 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.';

-- Dumping data for table webshop.categories: ~3 rows (approximately)
INSERT INTO `categories` (`id`, `name`, `description`) VALUES
	(1, 'Rozes', 'Sarkanas rozes'),
	(2, 'Tulpes', 'Krāsainas tulpes'),
	(3, 'Lilijas', 'Baltas lilijas');

-- 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.';

-- Dumping data for table webshop.orders: ~0 rows (approximately)
INSERT INTO `orders` (`id`, `user_id`, `status`, `created_at`) VALUES
	(1, 1, 'pending', '2025-11-02 16:20:23');

-- 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.';

-- Dumping data for table webshop.order_items: ~0 rows (approximately)
INSERT INTO `order_items` (`id`, `order_id`, `product_id`, `quantity`) VALUES
	(1, 1, 10, 1);

-- 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.';

-- Dumping data for table webshop.products: ~3 rows (approximately)
INSERT INTO `products` (`id`, `name`, `description`, `price`, `category_id`, `image`) VALUES
	(10, 'Rozes', 'Sarkanas rozes, 10 gab.', 5, 1, 'images/rozes.jpg'),
	(11, 'Tulpes', 'Krāsainas tulpes, 15 gab.', 3, 2, 'images/tulpes.jpg'),
	(12, 'Lilijas', 'Baltas lilijas, 8 gab.', 4, 3, 'images/lilijas.jpg');

