/*
 * μlogger
 *
 * Copyright(C) 2020 Bartek Fabiszewski (www.fabiszewski.net)
 *
 * This is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

--
-- Database schema for μlogger 0.6
--

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

--
-- Drop tables if exist
--

DROP TABLE IF EXISTS `positions`;
DROP TABLE IF EXISTS `tracks`;
DROP TABLE IF EXISTS `users`;
DROP TABLE IF EXISTS `config`;
DROP TABLE IF EXISTS `ol_layers`;

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

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
    `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `login` varchar(15) CHARACTER SET latin1 NOT NULL UNIQUE,
    `password` varchar(255) CHARACTER SET latin1 NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

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

--
-- Table structure for table `tracks`
--

CREATE TABLE `tracks` (
    `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `user_id` int(11) NOT NULL,
    `name` varchar(255) DEFAULT NULL,
    `comment` varchar(1024) DEFAULT NULL,
    INDEX `idx_user_id` (`user_id`),
    FOREIGN KEY(`user_id`) REFERENCES `users`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

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

--
-- Table structure for table `positions`
--

CREATE TABLE `positions` (
    `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `user_id` int(11) NOT NULL,
    `track_id` int(11) NOT NULL,
    `latitude` double NOT NULL,
    `longitude` double NOT NULL,
    `altitude` double DEFAULT NULL,
    `speed` double DEFAULT NULL,
    `bearing` double DEFAULT NULL,
    `accuracy` int(11) DEFAULT NULL,
    `provider` varchar(100) DEFAULT NULL,
    `comment` varchar(255) DEFAULT NULL,
    `image_id` int(11) DEFAULT NULL,
    INDEX `idx_ptrack_id` (`track_id`),
    INDEX `index_puser_id` (`user_id`),
    FOREIGN KEY(`user_id`) REFERENCES `users`(`id`),
    FOREIGN KEY(`track_id`) REFERENCES `tracks`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
