-- phpMyAdmin SQL Dump
-- version 4.5.4.1deb2ubuntu2
-- http://www.phpmyadmin.net
--
-- Gostitelj: localhost
-- Čas nastanka: 12. avg 2017 ob 12.57
-- Različica strežnika: 5.7.19-0ubuntu0.16.04.1
-- Različica PHP: 7.0.22-0ubuntu0.16.04.1

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Zbirka podatkov: `digital_atlas`
--
CREATE DATABASE IF NOT EXISTS `digital_atlas` DEFAULT CHARACTER SET utf8 COLLATE utf8_slovenian_ci;
USE `digital_atlas`;

-- --------------------------------------------------------

--
-- Struktura tabele `dialects`
--

CREATE TABLE `dialects` (
  `id` int(11) NOT NULL,
  `name` varchar(255) COLLATE utf8_slovenian_ci NOT NULL,
  `type` tinyint(4) NOT NULL COMMENT '/1-skupina, 2-narecje, 3-podnarecje',
  `id_parent` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_slovenian_ci;

--
-- Odloži podatke za tabelo `dialects`
--

INSERT INTO `dialects` (`id`, `name`, `type`, `id_parent`) VALUES
(1, 'gorenjska narečna skupina', 1, NULL),
(2, 'gorenjsko narečje', 2, 1),
(3, 'vzhodnogorenjsko podnarečje', 3, 2),
(4, 'selško narečje', 2, 1),
(5, 'dolenjska narečna skupina', 1, NULL),
(6, 'dolenjsko narečje', 2, 5),
(7, 'vzhodnodolenjsko podnarečje', 3, 6),
(8, 'severnobelokranjsko narečje', 2, 5),
(9, 'južnobelokranjsko narečje', 2, 5),
(10, 'kostelsko narečje', 2, 5),
(11, 'mešani kočevski govori', 2, 5),
(12, 'štajerska narečna skupina', 1, NULL),
(13, 'srednjesavinjsko narečje', 2, 12),
(14, 'zgornjesavinjsko narečje', 2, 12),
(15, 'solčavsko podnarečje', 3, 14),
(16, 'srednještajersko narečje', 2, 12),
(17, 'južnopohorsko narečje', 2, 12),
(18, 'kozjaško podnarečje', 3, 17),
(19, 'kozjansko-bizeljsko narečje', 2, 12),
(20, 'posavsko narečje', 2, 12),
(21, 'zagorsko-trboveljsko podnarečje', 3, 20),
(22, 'laško podnarečje ', 3, 20),
(23, 'sevniško-krško podnarečje', 3, 20),
(24, 'panonska narečna skupina', 1, NULL),
(25, 'prekmursko narečje ', 2, 24),
(26, 'slovenskogoriško narečje', 2, 24),
(27, 'prleško narečje ', 2, 24),
(28, 'haloško narečje', 2, 24),
(29, 'koroška narečna skupina', 1, NULL),
(30, 'severnopohorsko-remšniško narečje', 2, 29),
(31, 'mežiško narečje', 2, 29),
(32, 'podjunsko narečje', 2, 29),
(33, 'rožansko narečje', 2, 29),
(34, 'obirsko narečje', 2, 29),
(35, 'ziljsko narečje', 2, 29),
(36, 'kranjskogorsko podnarečje', 3, 35),
(37, 'primorska narečna skupina', 1, NULL),
(38, 'rezijansko narečje', 2, 37),
(39, 'obsoško narečje', 2, 37),
(40, 'tersko narečje', 2, 37),
(41, 'nadiško narečje', 2, 37),
(42, 'briško narečje', 2, 37),
(43, 'kraško narečje', 2, 37),
(44, 'banjško podnarečje', 3, 43),
(45, 'istrsko narečje', 2, 37),
(46, 'rižansko podnarečje', 3, 45),
(47, 'šavrinsko podnarečje', 3, 45),
(48, 'notranjsko narečje', 2, 37),
(49, 'čiško narečje', 2, 37),
(50, 'rovtarska narečna skupina', 1, NULL),
(51, 'tolminsko narečje', 2, 50),
(52, 'baško podnarečje', 3, 51),
(53, 'cerkljansko narečje', 2, 50),
(54, 'poljansko narečje', 2, 50),
(55, 'škofjeloško narečje', 2, 50),
(56, 'črnovrško narečje', 2, 50),
(57, 'horjulsko narečje', 2, 50);

-- --------------------------------------------------------

--
-- Struktura tabele `lexems`
--

CREATE TABLE `lexems` (
  `id` int(11) NOT NULL,
  `title` varchar(255) COLLATE utf8_slovenian_ci NOT NULL,
  `icon` varchar(500) COLLATE utf8_slovenian_ci NOT NULL,
  `id_word` int(11) NOT NULL,
  `icon_color` varchar(255) COLLATE utf8_slovenian_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_slovenian_ci;

-- --------------------------------------------------------

--
-- Struktura tabele `locations`
--

CREATE TABLE `locations` (
  `id` int(11) NOT NULL,
  `name` varchar(255) COLLATE utf8_slovenian_ci NOT NULL DEFAULT '',
  `short_name` varchar(50) COLLATE utf8_slovenian_ci NOT NULL DEFAULT '',
  `lat` decimal(10,6) NOT NULL,
  `long` decimal(10,6) NOT NULL,
  `id_dialect` int(11) NOT NULL,
  `id_subdialect` int(11) NOT NULL,
  `id_subsubdialect` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_slovenian_ci;

-- --------------------------------------------------------

--
-- Struktura tabele `subjects`
--

CREATE TABLE `subjects` (
  `id` int(1) NOT NULL,
  `title` varchar(255) COLLATE utf8_slovenian_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_slovenian_ci;

-- --------------------------------------------------------

--
-- Struktura tabele `subject_locations`
--

CREATE TABLE `subject_locations` (
  `id` int(11) NOT NULL,
  `id_subject` int(11) DEFAULT NULL,
  `id_location` int(11) NOT NULL,
  `checked` tinyint(4) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_slovenian_ci;

-- --------------------------------------------------------

--
-- Struktura tabele `transcriptions`
--

CREATE TABLE `transcriptions` (
  `id` int(11) NOT NULL,
  `phonetic_writing` varchar(255) COLLATE utf8_slovenian_ci NOT NULL DEFAULT '',
  `audio` varchar(255) COLLATE utf8_slovenian_ci NOT NULL DEFAULT '',
  `id_lexem` int(1) NOT NULL,
  `id_location` int(11) NOT NULL,
  `trans_text` text COLLATE utf8_slovenian_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_slovenian_ci;

-- --------------------------------------------------------

--
-- Struktura tabele `users`
--

CREATE TABLE `users` (
  `id` int(1) NOT NULL,
  `username` varchar(255) COLLATE utf8_slovenian_ci NOT NULL,
  `name` varchar(255) COLLATE utf8_slovenian_ci NOT NULL,
  `lastname` varchar(255) COLLATE utf8_slovenian_ci NOT NULL,
  `password_hash` varchar(255) COLLATE utf8_slovenian_ci NOT NULL,
  `sess_expiration` int(60) NOT NULL DEFAULT '60'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_slovenian_ci;

--
-- Odloži podatke za tabelo `users`
--

INSERT INTO `users` (`id`, `username`, `name`, `lastname`, `password_hash`, `sess_expiration`) VALUES
(1, 'admin', 'Admin', '', '$2y$10$bvfsnL9h3A5Dt6IaRT.m7eh/4GXmSgA/5s6wBUHJYrGgBtjDVoxYq', 60);

-- --------------------------------------------------------

--
-- Struktura tabele `words`
--

CREATE TABLE `words` (
  `id` int(11) NOT NULL,
  `title` varchar(255) COLLATE utf8_slovenian_ci NOT NULL DEFAULT '',
  `image` varchar(255) COLLATE utf8_slovenian_ci NOT NULL DEFAULT '',
  `comment` varchar(255) COLLATE utf8_slovenian_ci NOT NULL DEFAULT '',
  `id_subject` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_slovenian_ci;

--
-- Indeksi zavrženih tabel
--

--
-- Indeksi tabele `dialects`
--
ALTER TABLE `dialects`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_dialects_dialects` (`id_parent`);

--
-- Indeksi tabele `lexems`
--
ALTER TABLE `lexems`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_leksems_words` (`id_word`);

--
-- Indeksi tabele `locations`
--
ALTER TABLE `locations`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_locations_dialects` (`id_dialect`),
  ADD KEY `FK_locations_dialects_2` (`id_subdialect`),
  ADD KEY `FK_locations_dialects_3` (`id_subsubdialect`);

--
-- Indeksi tabele `subjects`
--
ALTER TABLE `subjects`
  ADD PRIMARY KEY (`id`);

--
-- Indeksi tabele `subject_locations`
--
ALTER TABLE `subject_locations`
  ADD PRIMARY KEY (`id`),
  ADD KEY `FK_subject_locations_locations` (`id_location`),
  ADD KEY `FK_subject_locations_subjects` (`id_subject`);

--
-- Indeksi tabele `transcriptions`
--
ALTER TABLE `transcriptions`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `id_location_uniq` (`id_location`,`id_lexem`),
  ADD KEY `id_word` (`id_lexem`),
  ADD KEY `id_location` (`id_location`);

--
-- Indeksi tabele `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`);

--
-- Indeksi tabele `words`
--
ALTER TABLE `words`
  ADD PRIMARY KEY (`id`),
  ADD KEY `id_subject` (`id_subject`);

--
-- AUTO_INCREMENT zavrženih tabel
--

--
-- AUTO_INCREMENT tabele `dialects`
--
ALTER TABLE `dialects`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=58;
--
-- AUTO_INCREMENT tabele `lexems`
--
ALTER TABLE `lexems`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;
--
-- AUTO_INCREMENT tabele `locations`
--
ALTER TABLE `locations`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;
--
-- AUTO_INCREMENT tabele `subjects`
--
ALTER TABLE `subjects`
  MODIFY `id` int(1) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;
--
-- AUTO_INCREMENT tabele `subject_locations`
--
ALTER TABLE `subject_locations`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;
--
-- AUTO_INCREMENT tabele `transcriptions`
--
ALTER TABLE `transcriptions`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;
--
-- AUTO_INCREMENT tabele `users`
--
ALTER TABLE `users`
  MODIFY `id` int(1) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT tabele `words`
--
ALTER TABLE `words`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;
--
-- Omejitve tabel za povzetek stanja
--

--
-- Omejitve za tabelo `dialects`
--
ALTER TABLE `dialects`
  ADD CONSTRAINT `FK_dialects_dialects` FOREIGN KEY (`id_parent`) REFERENCES `dialects` (`id`);

--
-- Omejitve za tabelo `lexems`
--
ALTER TABLE `lexems`
  ADD CONSTRAINT `FK_leksems_words` FOREIGN KEY (`id_word`) REFERENCES `words` (`id`);

--
-- Omejitve za tabelo `locations`
--
ALTER TABLE `locations`
  ADD CONSTRAINT `FK_locations_dialects` FOREIGN KEY (`id_dialect`) REFERENCES `dialects` (`id`),
  ADD CONSTRAINT `FK_locations_dialects_2` FOREIGN KEY (`id_subdialect`) REFERENCES `dialects` (`id`),
  ADD CONSTRAINT `FK_locations_dialects_3` FOREIGN KEY (`id_subsubdialect`) REFERENCES `dialects` (`id`);

--
-- Omejitve za tabelo `subject_locations`
--
ALTER TABLE `subject_locations`
  ADD CONSTRAINT `FK_subject_locations_locations` FOREIGN KEY (`id_location`) REFERENCES `locations` (`id`),
  ADD CONSTRAINT `FK_subject_locations_subjects` FOREIGN KEY (`id_subject`) REFERENCES `subjects` (`id`) ON DELETE SET NULL ON UPDATE SET NULL;

--
-- Omejitve za tabelo `transcriptions`
--
ALTER TABLE `transcriptions`
  ADD CONSTRAINT `FK_transcriptions_leksems` FOREIGN KEY (`id_lexem`) REFERENCES `lexems` (`id`),
  ADD CONSTRAINT `FK_transcriptions_locations` FOREIGN KEY (`id_location`) REFERENCES `locations` (`id`);

--
-- Omejitve za tabelo `words`
--
ALTER TABLE `words`
  ADD CONSTRAINT `FK_words_subjects` FOREIGN KEY (`id_subject`) REFERENCES `subjects` (`id`);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
