-- Adminer 3.7.1 MySQL dump

SET NAMES utf8;
SET foreign_key_checks = 0;
SET time_zone = '+01:00';
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';

DROP TABLE IF EXISTS `objects`;
CREATE TABLE `objects` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `mainphoto` int(11) DEFAULT NULL,
  `floorsphoto` int(11) DEFAULT NULL,
  `address` varchar(255) NOT NULL,
  `gm_zoom` tinyint(7) DEFAULT NULL,
  `gm_lng` varchar(40) DEFAULT NULL,
  `gm_lat` varchar(40) DEFAULT NULL,
  `width` tinyint(4) NOT NULL DEFAULT '2',
  `height` tinyint(4) NOT NULL DEFAULT '1',
  `show` tinyint(1) NOT NULL,
  `order` smallint(6) NOT NULL,
  `updated` timestamp NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `mainphoto` (`mainphoto`),
  KEY `floorsphoto` (`floorsphoto`),
  CONSTRAINT `objects_ibfk_5` FOREIGN KEY (`floorsphoto`) REFERENCES `photos` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `objects_ibfk_6` FOREIGN KEY (`mainphoto`) REFERENCES `photos` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


DROP TABLE IF EXISTS `objects_descriptions`;
CREATE TABLE `objects_descriptions` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `object` int(11) NOT NULL,
  `language` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `description` text,
  PRIMARY KEY (`id`),
  UNIQUE KEY `object_language` (`object`,`language`),
  KEY `language` (`language`),
  CONSTRAINT `objects_descriptions_ibfk_1` FOREIGN KEY (`object`) REFERENCES `objects` (`id`) ON DELETE CASCADE,
  CONSTRAINT `objects_descriptions_ibfk_2` FOREIGN KEY (`language`) REFERENCES `languages` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


DROP TABLE IF EXISTS `objects_floors`;
CREATE TABLE `objects_floors` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `object` int(11) NOT NULL,
  `order` smallint(6) NOT NULL,
  `hotspot` text,
  `hotspot_color` varchar(7) DEFAULT NULL,
  `mainphoto` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `object` (`object`),
  KEY `mainphoto` (`mainphoto`),
  CONSTRAINT `objects_floors_ibfk_3` FOREIGN KEY (`object`) REFERENCES `objects` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `objects_floors_ibfk_5` FOREIGN KEY (`mainphoto`) REFERENCES `photos` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


DROP TABLE IF EXISTS `objects_floors_descriptions`;
CREATE TABLE `objects_floors_descriptions` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `floor` int(11) NOT NULL,
  `language` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `floor_language` (`floor`,`language`),
  KEY `language` (`language`),
  CONSTRAINT `objects_floors_descriptions_ibfk_1` FOREIGN KEY (`floor`) REFERENCES `objects_floors` (`id`) ON DELETE CASCADE,
  CONSTRAINT `objects_floors_descriptions_ibfk_2` FOREIGN KEY (`language`) REFERENCES `languages` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


DROP TABLE IF EXISTS `objects_photos`;
CREATE TABLE `objects_photos` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `object` int(11) NOT NULL,
  `photo` int(11) NOT NULL,
  `order` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `object_photo` (`object`,`photo`),
  KEY `photo` (`photo`),
  CONSTRAINT `objects_photos_ibfk_1` FOREIGN KEY (`object`) REFERENCES `objects` (`id`) ON DELETE CASCADE,
  CONSTRAINT `objects_photos_ibfk_2` FOREIGN KEY (`photo`) REFERENCES `photos` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


DROP TABLE IF EXISTS `objects_spaces`;
CREATE TABLE `objects_spaces` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `object` int(11) NOT NULL,
  `type` int(11) NOT NULL,
  `rooms` tinyint(8) NOT NULL,
  `mainphoto` int(11) DEFAULT NULL,
  `order` int(11) NOT NULL,
  `show` tinyint(1) NOT NULL,
  `floor` int(11) NOT NULL,
  `area` smallint(6) NOT NULL,
  `drawing` int(11) DEFAULT NULL,
  `hotspot` text,
  `hotspot_color` varchar(7) DEFAULT NULL,
  `lodger` int(11) DEFAULT NULL,
  `show_lodger` tinyint(1) NOT NULL DEFAULT '1',
  `updated` timestamp NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `type` (`type`),
  KEY `object` (`object`),
  KEY `mainphoto` (`mainphoto`),
  KEY `drawing` (`drawing`),
  KEY `floor` (`floor`),
  KEY `lodger` (`lodger`),
  CONSTRAINT `objects_spaces_ibfk_12` FOREIGN KEY (`mainphoto`) REFERENCES `photos` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `objects_spaces_ibfk_13` FOREIGN KEY (`drawing`) REFERENCES `photos` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `objects_spaces_ibfk_14` FOREIGN KEY (`floor`) REFERENCES `objects_floors` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `objects_spaces_ibfk_15` FOREIGN KEY (`lodger`) REFERENCES `users` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  CONSTRAINT `objects_spaces_ibfk_16` FOREIGN KEY (`type`) REFERENCES `objects_spaces_types` (`id`) ON UPDATE CASCADE,
  CONSTRAINT `objects_spaces_ibfk_7` FOREIGN KEY (`object`) REFERENCES `objects` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


DROP TABLE IF EXISTS `objects_spaces_descriptions`;
CREATE TABLE `objects_spaces_descriptions` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `space` int(11) NOT NULL,
  `language` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `equipment` text,
  `description` text,
  PRIMARY KEY (`id`),
  UNIQUE KEY `room_language` (`space`,`language`),
  KEY `language` (`language`),
  CONSTRAINT `objects_spaces_descriptions_ibfk_4` FOREIGN KEY (`language`) REFERENCES `languages` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `objects_spaces_descriptions_ibfk_5` FOREIGN KEY (`space`) REFERENCES `objects_spaces` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


DROP TABLE IF EXISTS `objects_spaces_photos`;
CREATE TABLE `objects_spaces_photos` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `space` int(11) NOT NULL,
  `photo` int(11) NOT NULL,
  `order` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `room` (`space`),
  KEY `photo` (`photo`),
  CONSTRAINT `objects_spaces_photos_ibfk_4` FOREIGN KEY (`photo`) REFERENCES `photos` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `objects_spaces_photos_ibfk_5` FOREIGN KEY (`space`) REFERENCES `objects_spaces` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


DROP TABLE IF EXISTS `objects_spaces_types`;
CREATE TABLE `objects_spaces_types` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `objects_spaces_types` (`id`) VALUES
(1),
(2),
(3),
(4);

DROP TABLE IF EXISTS `objects_spaces_types_names`;
CREATE TABLE `objects_spaces_types_names` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `type` int(11) NOT NULL,
  `language` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `type_language` (`type`,`language`),
  KEY `language` (`language`),
  CONSTRAINT `objects_spaces_types_names_ibfk_3` FOREIGN KEY (`type`) REFERENCES `objects_spaces_types` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `objects_spaces_types_names_ibfk_4` FOREIGN KEY (`language`) REFERENCES `languages` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `objects_spaces_types_names` (`id`, `type`, `language`, `name`) VALUES
(1,	1,	1,	'Obchodné priestory'),
(2,	1,	2,	'Commercial spaces'),
(3,	2,	1,	'Kancelárske priestory'),
(4,	2,	2,	'Office spaces'),
(5,	3,	1,	'Skladovacie priestory'),
(6,	3,	2,	'Storage areas'),
(7,	4,	1,	'Byt'),
(8,	4,	2,	'Flat');

-- 2013-12-05 10:52:07
