-- --------------------------------------------------------
-- Server OS:                    Win64
-- HeidiSQL Version:             12.13.0.7147
-- --------------------------------------------------------



-- 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',
  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=12 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: ~9 rows (approximately)
INSERT INTO `crop_breed` (`id`, `name`, `species_id`) VALUES
	(1, 'Winter Wheat Skagen', 1),
	(2, 'Spring Wheat Zebra', 1),
	(3, 'Winter Barley KWS Meridian', 2),
	(4, 'Spring Barley RGT Planet', 2),
	(5, 'Oats Belinda', 3),
	(6, 'Oats Symphony', 3),
	(7, 'Winter Rye Brasetto', 4),
	(8, 'Corn Pioneer P9911', 5),
	(9, 'Corn DKC4590', 5);

-- 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',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 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: ~5 rows (approximately)
INSERT INTO `crop_species` (`id`, `name`) VALUES
	(1, 'Wheat'),
	(2, 'Barley'),
	(3, 'Oats'),
	(4, 'Rye'),
	(5, 'Corn');

-- 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',
  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=9 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: ~5 rows (approximately)
INSERT INTO `equipment` (`id`, `name`, `fuel_tank`, `farm_id`) VALUES
	(1, 'John Deere 6120M', 200, 1),
	(2, 'Case IH Magnum 340', 450, 1),
	(3, 'New Holland T7.315', 380, 2),
	(4, 'Massey Ferguson 8S.265', 420, 3),
	(5, 'Fendt 724 Vario', 310, 2);

-- 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`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Saglabā visas sistēmā piereģistrētās lauksaimniecības';

-- Dumping data for table monsteragro.farms: ~5 rows (approximately)
INSERT INTO `farms` (`id`, `name`, `active`) VALUES
	(1, 'Green Valley Farm', 1),
	(2, 'Sunrise Agriculture', 1),
	(3, 'Golden Harvest Farm', 1),
	(4, 'Meadow Brook Farm', 1),
	(5, '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=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Saglabā katras lauksaimniecības laukus';

-- Dumping data for table monsteragro.fields: ~10 rows (approximately)
INSERT INTO `fields` (`id`, `name`, `area`, `breed_id`, `farm_id`) VALUES
	(1, 'North Field', 25.5, 1, 1),
	(2, 'South Field', 30, 8, 1),
	(3, 'East Field', 32, 5, 1),
	(4, 'West Field', 22.7, 8, 2),
	(5, 'Upper Field', 28.4, 2, 2),
	(6, 'Lower Field', 19.8, 4, 2),
	(7, 'Hill Field', 35.2, 7, 3),
	(8, 'Valley Field', 27.6, 9, 3),
	(9, 'River Field', 21.5, 1, 4),
	(10, 'Lake Field', 24.8, 6, 4);

-- 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=33 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Saglabā katras lauksaimniecības katru degvielas uzpildes reizi';

-- Dumping data for table monsteragro.fuel_accounting: ~18 rows (approximately)
INSERT INTO `fuel_accounting` (`id`, `time`, `equipment_id`, `litres`, `user_id`) VALUES
	(1, '2024-11-08 08:15:00', 1, 46, 1),
	(2, '2024-11-08 14:30:00', 2, 38, 2),
	(5, '2024-11-06 07:30:00', 4, 65, 2),
	(7, '2024-11-05 10:00:00', 5, 28, 4),
	(9, '2024-11-04 08:30:00', 3, 55, 2),
	(12, '2024-11-03 16:30:00', 1, 40, 2),
	(13, '2024-11-02 07:45:00', 5, 31, 4),
	(16, '2024-10-31 08:00:00', 1, 50, 1),
	(17, '2024-10-30 14:15:00', 4, 69, 2),
	(18, '2024-10-29 09:30:00', 2, 37, 1),
	(19, '2024-10-28 15:00:00', 3, 54, 3),
	(20, '2024-10-27 07:15:00', 5, 30, 4),
	(21, '2024-10-26 12:45:00', 1, 46, 1),
	(22, '2024-10-25 08:30:00', 2, 41, 2),
	(24, '2024-10-23 10:15:00', 3, 51, 3),
	(25, '2024-10-22 16:00:00', 1, 44, 1),
	(26, '2025-11-24 15:54:00', 1, 200, 1),
	(28, '2026-01-06 07:34:00', 2, 53, 1);

-- 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=29 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Saglabā ražas ievākšanas datus';

-- Dumping data for table monsteragro.harvest_record: ~28 rows (approximately)
INSERT INTO `harvest_record` (`id`, `time`, `field_id`, `breed_id`, `weight`, `moisture`, `user_id`) VALUES
	(1, '2024-09-15 10:30:00', 1, 1, 127500, 14, 1),
	(2, '2024-09-16 14:20:00', 1, 1, 128200, 13, 1),
	(3, '2024-09-17 09:15:00', 1, 1, 126800, 15, 1),
	(4, '2024-08-20 11:45:00', 2, 3, 91500, 12, 2),
	(5, '2024-08-21 13:30:00', 2, 3, 92300, 13, 2),
	(6, '2024-08-05 10:00:00', 3, 5, 96000, 11, 1),
	(7, '2024-08-06 15:45:00', 3, 5, 95200, 12, 1),
	(8, '2024-10-10 09:30:00', 4, 8, 204300, 18, 3),
	(9, '2024-10-11 14:15:00', 4, 8, 203800, 19, 3),
	(10, '2024-10-12 10:45:00', 4, 8, 205100, 17, 3),
	(11, '2024-09-05 11:20:00', 5, 2, 142000, 13, 3),
	(12, '2024-09-06 13:40:00', 5, 2, 141500, 14, 3),
	(13, '2024-08-15 10:30:00', 6, 4, 98900, 12, 4),
	(14, '2024-08-16 14:50:00', 6, 4, 99200, 13, 4),
	(15, '2024-09-20 09:00:00', 7, 7, 176000, 14, 1),
	(16, '2024-09-21 13:15:00', 7, 7, 175500, 15, 1),
	(17, '2024-10-15 10:20:00', 8, 9, 248400, 19, 1),
	(18, '2024-10-16 14:30:00', 8, 9, 249100, 18, 1),
	(19, '2024-09-10 11:00:00', 9, 1, 107500, 14, 1),
	(20, '2024-09-11 15:20:00', 9, 1, 108200, 13, 1),
	(21, '2024-08-10 10:15:00', 10, 6, 74400, 11, 1),
	(22, '2024-08-11 14:40:00', 10, 6, 74800, 12, 1),
	(23, '2025-11-24 16:46:34', 1, 1, 15136, 13, 2),
	(24, '2025-11-25 08:31:30', 3, 5, 28202, 13, 1),
	(25, '2025-12-03 17:37:04', 3, 5, 4354, 13, 2),
	(26, '2026-01-27 20:54:38', 5, 2, 12000, 12, NULL),
	(27, '2026-01-27 20:56:24', 6, 4, 12000, 12, NULL),
	(28, '2026-01-28 15:13:18', 3, 5, 12600, 21, 1);

