-- --------------------------------------------------------
-- 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.';

-- 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');

-- 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.';

-- Dumping data for table webshop.users: ~0 rows (approximately)
INSERT INTO `users` (`id`, `name`, `email`, `password`, `created_at`) VALUES
	(1, 'GG', '123@123.com', '$2y$10$ArjfJS/87fR5PgDqpQh9rOd8Js3h6A.8GJHImIyhbZibCyT1dY7.u', '2025-10-21 10:12:55');

/*!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) */;
