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

/*!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 monsteragro
CREATE DATABASE IF NOT EXISTS `monsteragro` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci */;
USE `monsteragro`;

-- Dumping structure for table monsteragro.crop_breed
CREATE TABLE IF NOT EXISTS `crop_breed` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Kultūrauga šķirnes identifikators',
  `name` varchar(50) NOT NULL COMMENT 'Kultūrauga šķirnes nosaukums',
  `species_id` int(11) NOT NULL DEFAULT 0 COMMENT 'Kultūrauga sugas identifikators',
  `active` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Vai šķirne ir aktīva (1) vai deaktivizēta (0)',
  PRIMARY KEY (`id`),
  KEY `FK_crop_breed_crop_species` (`species_id`),
  CONSTRAINT `FK_crop_breed_crop_species` FOREIGN KEY (`species_id`) REFERENCES `crop_species` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Saglabā visas sistēmā ievadītās kultūraugu šķirnes';

-- Dumping data for table monsteragro.crop_breed: ~0 rows (approximately)

-- Dumping structure for table monsteragro.crop_species
CREATE TABLE IF NOT EXISTS `crop_species` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Kultūrauga sugas identifikators',
  `name` varchar(50) NOT NULL COMMENT 'Kultūrauga sugas nosaukums',
  `active` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Vai suga ir aktīva (1) vai deaktivizēta (0)',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Saglabā visas sistēmā ievadītās kultūraugu sugas';

-- Dumping data for table monsteragro.crop_species: ~0 rows (approximately)

-- Dumping structure for table monsteragro.equipment
CREATE TABLE IF NOT EXISTS `equipment` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Lauksaimniecības tehnikas identifikators',
  `name` varchar(100) NOT NULL COMMENT 'Lauksaimniecības tehnikas nosaukums',
  `fuel_tank` int(11) NOT NULL COMMENT 'Lauksaimniecības tehnikas degvielas tvertnes ietilpība',
  `farm_id` int(11) NOT NULL COMMENT 'Lauksaimniecības identifikators',
  `active` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Vai tehnika ir aktīva (1) vai deaktivizēta (0)',
  PRIMARY KEY (`id`),
  KEY `FK_equipment_farms` (`farm_id`),
  CONSTRAINT `FK_equipment_farms` FOREIGN KEY (`farm_id`) REFERENCES `farms` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Saglabā katras lauksaimniecības tehniku, domāts saglabāt tieši tehniku, kurai var iepildīt degvielu';

-- Dumping data for table monsteragro.equipment: ~0 rows (approximately)

-- Dumping structure for table monsteragro.farms
CREATE TABLE IF NOT EXISTS `farms` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Lauksaimniecības identifikators',
  `name` varchar(100) NOT NULL COMMENT 'Lauksaimniecības nosaukums',
  `active` tinyint(1) NOT NULL COMMENT 'Vai saumniecība ir aktīva vai nav',
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Saglabā visas sistēmā piereģistrētās lauksaimniecības';

-- Dumping data for table monsteragro.farms: ~1 rows (approximately)
INSERT IGNORE INTO `farms` (`id`, `name`, `active`) VALUES
	(1, 'admin', 1);

-- Dumping structure for table monsteragro.fields
CREATE TABLE IF NOT EXISTS `fields` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Lauksaimniecības lauka identifikators',
  `name` varchar(100) NOT NULL COMMENT 'Lauka nosaukums',
  `area` double NOT NULL COMMENT 'Lauka platība hektāros',
  `breed_id` int(11) NOT NULL COMMENT 'Saglabā, kura kultūrauga šķirne ir iesēta laukā',
  `farm_id` int(11) NOT NULL COMMENT 'Saglabā kurai lauksaimniecībai pieder lauks',
  PRIMARY KEY (`id`),
  KEY `FK_fields_crop_breed` (`breed_id`),
  KEY `FK_fields_farms` (`farm_id`),
  CONSTRAINT `FK_fields_crop_breed` FOREIGN KEY (`breed_id`) REFERENCES `crop_breed` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `FK_fields_farms` FOREIGN KEY (`farm_id`) REFERENCES `farms` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Saglabā katras lauksaimniecības laukus';

-- Dumping data for table monsteragro.fields: ~0 rows (approximately)

-- Dumping structure for table monsteragro.fuel_accounting
CREATE TABLE IF NOT EXISTS `fuel_accounting` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Degvielas uzpildes identifikators',
  `time` datetime NOT NULL COMMENT 'Laiks, kurā tika veikta degvielas uzpilde',
  `equipment_id` int(11) DEFAULT NULL,
  `litres` int(11) NOT NULL COMMENT 'Ielietās degvielas daudzums litros',
  `user_id` int(11) DEFAULT NULL COMMENT 'Lietotāja identifikators',
  PRIMARY KEY (`id`),
  KEY `FK_fuel_accounting_equipment` (`equipment_id`),
  KEY `FK_fuel_accounting_users` (`user_id`),
  CONSTRAINT `FK_fuel_accounting_equipment` FOREIGN KEY (`equipment_id`) REFERENCES `equipment` (`id`) ON DELETE SET NULL ON UPDATE NO ACTION,
  CONSTRAINT `FK_fuel_accounting_users` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Saglabā katras lauksaimniecības katru degvielas uzpildes reizi';

-- Dumping data for table monsteragro.fuel_accounting: ~0 rows (approximately)

-- Dumping structure for table monsteragro.harvest_record
CREATE TABLE IF NOT EXISTS `harvest_record` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Kravas ievešanas reizes identifikators',
  `time` datetime NOT NULL COMMENT 'Laiks, kad tiek ievesta krava',
  `field_id` int(11) NOT NULL COMMENT 'Lauka identifikators',
  `breed_id` int(11) NOT NULL COMMENT 'Šķirnes identifikators',
  `weight` int(11) NOT NULL COMMENT 'Kravas svars kilogramos',
  `moisture` double NOT NULL DEFAULT 0 COMMENT 'Ražas mitrums',
  `user_id` int(11) DEFAULT NULL COMMENT 'Lietotāja identofokators',
  PRIMARY KEY (`id`),
  KEY `FK_harvest_record_fields` (`field_id`),
  KEY `FK_harvest_record_crop_breed` (`breed_id`),
  KEY `FK_harvest_record_users` (`user_id`),
  CONSTRAINT `FK_harvest_record_crop_breed` FOREIGN KEY (`breed_id`) REFERENCES `crop_breed` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `FK_harvest_record_fields` FOREIGN KEY (`field_id`) REFERENCES `fields` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `FK_harvest_record_users` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Saglabā ražas ievākšanas datus';

-- Dumping data for table monsteragro.harvest_record: ~0 rows (approximately)

-- Dumping structure for table monsteragro.users
CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Lietotāja profila identifikators',
  `email` varchar(50) NOT NULL COMMENT 'Lietotāja e-pasta adrese',
  `password` varchar(255) NOT NULL COMMENT 'Lietotāja profila parole (jaucēta ar bcrypt)',
  `status` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Lietotāja profila statuss 1-darbinieks; 2-darba devējs; 3-administrators',
  `session` datetime NOT NULL COMMENT 'Sesijas sākums',
  `name` varchar(50) NOT NULL COMMENT 'Lietotāja vārds',
  `fname` varchar(50) NOT NULL COMMENT 'Lietotāja uzvārds',
  `farm_id` int(11) NOT NULL COMMENT 'Lauksaimniecības identifikators',
  `active` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Saglabā vai profils ir aktīvs. 0-neaktīvs, 1-aktīvs',
  PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`),
  KEY `FK_users_farms` (`farm_id`),
  CONSTRAINT `FK_users_farms` FOREIGN KEY (`farm_id`) REFERENCES `farms` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Saglabā lietotāja profilu informāciju';

-- Dumping data for table monsteragro.users: ~1 rows (approximately)
INSERT IGNORE INTO `users` (`id`, `email`, `password`, `status`, `session`, `name`, `fname`, `farm_id`, `active`) VALUES
	(1, 'dunavskisedijs@gmail.com', '$2b$12$iTrsJl7lWMm.HHdsBDwBSOrXUx5Dw4HXuLuGzBUzgGu9QN8cwayDa', 3, '2026-06-04 21:38:10', 'Edijs', 'Dunavskis', 5, 1);

/*!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) */;
