
# This is a fix for InnoDB in MySQL >= 4.1.x
# It "suspends judgement" for fkey relationships until are tables are set.
SET FOREIGN_KEY_CHECKS = 0;

#-----------------------------------------------------------------------------
#-- sf_guard_group
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `sf_guard_group`;


CREATE TABLE `sf_guard_group`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`name` VARCHAR(255)  NOT NULL,
	`description` TEXT,
	PRIMARY KEY (`id`),
	UNIQUE KEY `sf_guard_group_U_1` (`name`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- sf_guard_group_permission
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `sf_guard_group_permission`;


CREATE TABLE `sf_guard_group_permission`
(
	`group_id` INTEGER  NOT NULL,
	`permission_id` INTEGER  NOT NULL,
	PRIMARY KEY (`group_id`,`permission_id`),
	CONSTRAINT `sf_guard_group_permission_FK_1`
		FOREIGN KEY (`group_id`)
		REFERENCES `sf_guard_group` (`id`)
		ON DELETE CASCADE,
	INDEX `sf_guard_group_permission_FI_2` (`permission_id`),
	CONSTRAINT `sf_guard_group_permission_FK_2`
		FOREIGN KEY (`permission_id`)
		REFERENCES `sf_guard_permission` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- sf_guard_permission
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `sf_guard_permission`;


CREATE TABLE `sf_guard_permission`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`name` VARCHAR(255)  NOT NULL,
	`description` TEXT,
	`value` VARCHAR(10) default '0' NOT NULL,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- sf_guard_remember_key
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `sf_guard_remember_key`;


CREATE TABLE `sf_guard_remember_key`
(
	`user_id` INTEGER  NOT NULL,
	`remember_key` VARCHAR(32),
	`ip_address` VARCHAR(50)  NOT NULL,
	`created_at` DATETIME,
	PRIMARY KEY (`user_id`,`ip_address`),
	CONSTRAINT `sf_guard_remember_key_FK_1`
		FOREIGN KEY (`user_id`)
		REFERENCES `sf_guard_user` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- sf_guard_user
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `sf_guard_user`;


CREATE TABLE `sf_guard_user`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`username` VARCHAR(128)  NOT NULL,
	`algorithm` VARCHAR(128) default 'sha1' NOT NULL,
	`salt` VARCHAR(128)  NOT NULL,
	`password` VARCHAR(128)  NOT NULL,
	`created_at` DATETIME,
	`last_login` DATETIME,
	`is_active` TINYINT default 1 NOT NULL,
	`is_super_admin` TINYINT default 0 NOT NULL,
	`czas_blokady` INTEGER(11) default 0 NOT NULL,
	`nieudane_logowania` SMALLINT(6) default 0 NOT NULL,
	`czas_wygasniecia` DATETIME default '0000-00-00' NOT NULL,
	`edycja_hasla` TINYINT(1) default 0 NOT NULL,
	`ip_addr` VARCHAR(256),
	PRIMARY KEY (`id`),
	UNIQUE KEY `sf_guard_user_U_1` (`username`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- sf_guard_user_group
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `sf_guard_user_group`;


CREATE TABLE `sf_guard_user_group`
(
	`user_id` INTEGER  NOT NULL,
	`group_id` INTEGER  NOT NULL,
	PRIMARY KEY (`user_id`,`group_id`),
	CONSTRAINT `sf_guard_user_group_FK_1`
		FOREIGN KEY (`user_id`)
		REFERENCES `sf_guard_user` (`id`)
		ON DELETE CASCADE,
	INDEX `sf_guard_user_group_FI_2` (`group_id`),
	CONSTRAINT `sf_guard_user_group_FK_2`
		FOREIGN KEY (`group_id`)
		REFERENCES `sf_guard_group` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- sf_guard_user_permission
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `sf_guard_user_permission`;


CREATE TABLE `sf_guard_user_permission`
(
	`user_id` INTEGER  NOT NULL,
	`permission_id` INTEGER  NOT NULL,
	PRIMARY KEY (`user_id`,`permission_id`),
	CONSTRAINT `sf_guard_user_permission_FK_1`
		FOREIGN KEY (`user_id`)
		REFERENCES `sf_guard_user` (`id`)
		ON DELETE CASCADE,
	INDEX `sf_guard_user_permission_FI_2` (`permission_id`),
	CONSTRAINT `sf_guard_user_permission_FK_2`
		FOREIGN KEY (`permission_id`)
		REFERENCES `sf_guard_permission` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- aktualnosc
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `aktualnosc`;


CREATE TABLE `aktualnosc`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`newsletter` TINYINT(1) default 1 NOT NULL,
	`komentarz` TINYINT(1) default 1 NOT NULL,
	`uzytkownik_id` INTEGER(11) default 0 NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`tytul` VARCHAR(255)  NOT NULL,
	`zajawka` TEXT,
	`tekst` LONGTEXT,
	`grafika_zajawki` VARCHAR(255),
	`opis_grafiki_zajawki` TEXT,
	`meta_kluczowe` VARCHAR(255),
	`meta_tytul` VARCHAR(255),
	`meta_description` VARCHAR(255),
	`publikacja_od` DATETIME,
	`publikacja_do` DATETIME,
	`menu` TINYINT(1) default 1 NOT NULL,
	`ukryta` TINYINT(1) default 0 NOT NULL,
	`promowana` TINYINT(1) default 0 NOT NULL,
	`promowana_kolejnosc` INTEGER(5),
	`przekierowanie` VARCHAR(255),
	`uwagi` TEXT,
	`opis_zmian` TEXT,
	`link_target` VARCHAR(100) default '_self' NOT NULL,
	`link_bezposredni` TEXT,
	`dodatkowa_stopka` TEXT,
	`zatwierdzona` TINYINT(1) default 0,
	`ilosc_odwiedzin` INTEGER(10),
	`culture` VARCHAR(5) default 'pl' NOT NULL,
	PRIMARY KEY (`id`),
	KEY `uzytkownik_id`(`uzytkownik_id`),
	KEY `status`(`status`),
	CONSTRAINT `aktualnosc_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`),
	CONSTRAINT `aktualnosc_FK_2`
		FOREIGN KEY (`status`)
		REFERENCES `aktualnosc_status` (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- aktualnosc_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `aktualnosc_pub`;


CREATE TABLE `aktualnosc_pub`
(
	`id` INTEGER(11)  NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`newsletter` TINYINT(1) default 1 NOT NULL,
	`komentarz` TINYINT(1) default 1 NOT NULL,
	`uzytkownik_id` INTEGER(11) default 0 NOT NULL,
	`status` INTEGER(11) default 0 NOT NULL,
	`tytul` VARCHAR(255)  NOT NULL,
	`zajawka` TEXT,
	`tekst` LONGTEXT,
	`grafika_zajawki` VARCHAR(255),
	`opis_grafiki_zajawki` TEXT,
	`meta_kluczowe` VARCHAR(255),
	`meta_tytul` VARCHAR(255),
	`meta_description` VARCHAR(255),
	`publikacja_od` DATETIME,
	`publikacja_do` DATETIME,
	`menu` TINYINT(1) default 1 NOT NULL,
	`ukryta` TINYINT(1) default 0 NOT NULL,
	`promowana` TINYINT(1) default 0 NOT NULL,
	`promowana_kolejnosc` INTEGER(5),
	`przekierowanie` VARCHAR(255),
	`uwagi` TEXT,
	`opis_zmian` TEXT,
	`link_target` VARCHAR(100) default '_self' NOT NULL,
	`link_bezposredni` TEXT,
	`dodatkowa_stopka` TEXT,
	`zatwierdzona` TINYINT(1) default 0,
	`ilosc_odwiedzin` INTEGER(10),
	`culture` VARCHAR(5) default 'pl' NOT NULL,
	PRIMARY KEY (`id`),
	KEY `uzytkownik_id`(`uzytkownik_id`),
	KEY `status`(`status`),
	CONSTRAINT `aktualnosc_pub_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`),
	CONSTRAINT `aktualnosc_pub_FK_2`
		FOREIGN KEY (`status`)
		REFERENCES `aktualnosc_status` (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- aktualnosc_kategoria
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `aktualnosc_kategoria`;


CREATE TABLE `aktualnosc_kategoria`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`nazwa` VARCHAR(150)  NOT NULL,
	`jezyk_id` INTEGER(11) default 0 NOT NULL,
	`aktywna` TINYINT(1) default 1 NOT NULL,
	`domyslna` TINYINT(1),
	`kolejnosc` INTEGER(11),
	PRIMARY KEY (`id`),
	KEY `jezyk_id`(`jezyk_id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- aktualnosc_status
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `aktualnosc_status`;


CREATE TABLE `aktualnosc_status`
(
	`id` INTEGER(11)  NOT NULL,
	`nazwa` VARCHAR(255)  NOT NULL,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- aktualnosc_kategoria_map
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `aktualnosc_kategoria_map`;


CREATE TABLE `aktualnosc_kategoria_map`
(
	`aktualnosc_id` INTEGER  NOT NULL,
	`kategoria_id` INTEGER  NOT NULL,
	PRIMARY KEY (`aktualnosc_id`,`kategoria_id`),
	CONSTRAINT `aktualnosc_kategoria_map_FK_1`
		FOREIGN KEY (`aktualnosc_id`)
		REFERENCES `aktualnosc` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `aktualnosc_kategoria_map_FI_2` (`kategoria_id`),
	CONSTRAINT `aktualnosc_kategoria_map_FK_2`
		FOREIGN KEY (`kategoria_id`)
		REFERENCES `aktualnosc_kategoria` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- aktualnosc_kategoria_map_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `aktualnosc_kategoria_map_pub`;


CREATE TABLE `aktualnosc_kategoria_map_pub`
(
	`aktualnosc_id` INTEGER  NOT NULL,
	`kategoria_id` INTEGER  NOT NULL,
	PRIMARY KEY (`aktualnosc_id`,`kategoria_id`),
	CONSTRAINT `aktualnosc_kategoria_map_pub_FK_1`
		FOREIGN KEY (`aktualnosc_id`)
		REFERENCES `aktualnosc_pub` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `aktualnosc_kategoria_map_pub_FI_2` (`kategoria_id`),
	CONSTRAINT `aktualnosc_kategoria_map_pub_FK_2`
		FOREIGN KEY (`kategoria_id`)
		REFERENCES `aktualnosc_kategoria` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- aktualnosc_komentarz
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `aktualnosc_komentarz`;


CREATE TABLE `aktualnosc_komentarz`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`aktualnosc_id` INTEGER,
	`status` INTEGER(11) default 0 NOT NULL,
	`parent` INTEGER(11),
	`lft` INTEGER(11)  NOT NULL,
	`rgt` INTEGER(11)  NOT NULL,
	`ip` VARCHAR(255),
	`nikname` VARCHAR(255),
	`tytul` VARCHAR(255),
	`skrot` TEXT(300),
	`tresc` TEXT(500)  NOT NULL,
	PRIMARY KEY (`id`),
	INDEX `aktualnosc_komentarz_FI_1` (`aktualnosc_id`),
	CONSTRAINT `aktualnosc_komentarz_FK_1`
		FOREIGN KEY (`aktualnosc_id`)
		REFERENCES `aktualnosc_pub` (`id`),
	INDEX `aktualnosc_komentarz_FI_2` (`status`),
	CONSTRAINT `aktualnosc_komentarz_FK_2`
		FOREIGN KEY (`status`)
		REFERENCES `aktualnosc_komentarz_status` (`id`),
	INDEX `aktualnosc_komentarz_FI_3` (`parent`),
	CONSTRAINT `aktualnosc_komentarz_FK_3`
		FOREIGN KEY (`parent`)
		REFERENCES `aktualnosc_komentarz` (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- aktualnosc_komentarz_status
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `aktualnosc_komentarz_status`;


CREATE TABLE `aktualnosc_komentarz_status`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`nazwa` VARCHAR(255)  NOT NULL,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- aktualnosc_galeria
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `aktualnosc_galeria`;


CREATE TABLE `aktualnosc_galeria`
(
	`aktualnosc_id` INTEGER  NOT NULL,
	`galeria_id` INTEGER  NOT NULL,
	PRIMARY KEY (`aktualnosc_id`,`galeria_id`),
	CONSTRAINT `aktualnosc_galeria_FK_1`
		FOREIGN KEY (`aktualnosc_id`)
		REFERENCES `aktualnosc` (`id`)
		ON DELETE CASCADE,
	INDEX `aktualnosc_galeria_FI_2` (`galeria_id`),
	CONSTRAINT `aktualnosc_galeria_FK_2`
		FOREIGN KEY (`galeria_id`)
		REFERENCES `galeria_pub` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- aktualnosc_galeria_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `aktualnosc_galeria_pub`;


CREATE TABLE `aktualnosc_galeria_pub`
(
	`aktualnosc_id` INTEGER  NOT NULL,
	`galeria_id` INTEGER  NOT NULL,
	PRIMARY KEY (`aktualnosc_id`,`galeria_id`),
	CONSTRAINT `aktualnosc_galeria_pub_FK_1`
		FOREIGN KEY (`aktualnosc_id`)
		REFERENCES `aktualnosc_pub` (`id`)
		ON DELETE CASCADE,
	INDEX `aktualnosc_galeria_pub_FI_2` (`galeria_id`),
	CONSTRAINT `aktualnosc_galeria_pub_FK_2`
		FOREIGN KEY (`galeria_id`)
		REFERENCES `galeria_pub` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- aktualnosc_multimedia_map
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `aktualnosc_multimedia_map`;


CREATE TABLE `aktualnosc_multimedia_map`
(
	`aktualnosc_id` INTEGER  NOT NULL,
	`multimedia_id` INTEGER  NOT NULL,
	PRIMARY KEY (`aktualnosc_id`,`multimedia_id`),
	CONSTRAINT `aktualnosc_multimedia_map_FK_1`
		FOREIGN KEY (`aktualnosc_id`)
		REFERENCES `aktualnosc` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `aktualnosc_multimedia_map_FI_2` (`multimedia_id`),
	CONSTRAINT `aktualnosc_multimedia_map_FK_2`
		FOREIGN KEY (`multimedia_id`)
		REFERENCES `multimedia` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- aktualnosc_multimedia_map_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `aktualnosc_multimedia_map_pub`;


CREATE TABLE `aktualnosc_multimedia_map_pub`
(
	`aktualnosc_id` INTEGER  NOT NULL,
	`multimedia_id` INTEGER  NOT NULL,
	PRIMARY KEY (`aktualnosc_id`,`multimedia_id`),
	CONSTRAINT `aktualnosc_multimedia_map_pub_FK_1`
		FOREIGN KEY (`aktualnosc_id`)
		REFERENCES `aktualnosc_pub` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `aktualnosc_multimedia_map_pub_FI_2` (`multimedia_id`),
	CONSTRAINT `aktualnosc_multimedia_map_pub_FK_2`
		FOREIGN KEY (`multimedia_id`)
		REFERENCES `multimedia` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- aktualnosc_zalacznik
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `aktualnosc_zalacznik`;


CREATE TABLE `aktualnosc_zalacznik`
(
	`aktualnosc_id` INTEGER  NOT NULL,
	`zalacznik_id` INTEGER  NOT NULL,
	`zalacznik_kolejnosc` INTEGER(5) default 0 NOT NULL,
	`zalacznik_widoczny` TINYINT(1) default 1 NOT NULL,
	PRIMARY KEY (`aktualnosc_id`,`zalacznik_id`),
	CONSTRAINT `aktualnosc_zalacznik_FK_1`
		FOREIGN KEY (`aktualnosc_id`)
		REFERENCES `aktualnosc` (`id`)
		ON DELETE CASCADE,
	INDEX `aktualnosc_zalacznik_FI_2` (`zalacznik_id`),
	CONSTRAINT `aktualnosc_zalacznik_FK_2`
		FOREIGN KEY (`zalacznik_id`)
		REFERENCES `zalacznik` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- aktualnosc_zalacznik_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `aktualnosc_zalacznik_pub`;


CREATE TABLE `aktualnosc_zalacznik_pub`
(
	`aktualnosc_id` INTEGER  NOT NULL,
	`zalacznik_id` INTEGER  NOT NULL,
	`zalacznik_kolejnosc` INTEGER(5) default 0 NOT NULL,
	`zalacznik_widoczny` TINYINT(1) default 1 NOT NULL,
	PRIMARY KEY (`aktualnosc_id`,`zalacznik_id`),
	CONSTRAINT `aktualnosc_zalacznik_pub_FK_1`
		FOREIGN KEY (`aktualnosc_id`)
		REFERENCES `aktualnosc_pub` (`id`)
		ON DELETE CASCADE,
	INDEX `aktualnosc_zalacznik_pub_FI_2` (`zalacznik_id`),
	CONSTRAINT `aktualnosc_zalacznik_pub_FK_2`
		FOREIGN KEY (`zalacznik_id`)
		REFERENCES `zalacznik` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- jezyk_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `jezyk_tbl`;


CREATE TABLE `jezyk_tbl`
(
	`jezyk_kolejnosc` INTEGER(5) default 0 NOT NULL,
	`jezyk_id` INTEGER(11)  NOT NULL,
	`jezyk_skrot` VARCHAR(5)  NOT NULL,
	`jezyk_nazwa` VARCHAR(100)  NOT NULL,
	`jezyk_nazwa_en` VARCHAR(255)  NOT NULL,
	`show` INTEGER(1) default 0 NOT NULL,
	`portal_id` INTEGER(11)  NOT NULL,
	PRIMARY KEY (`jezyk_id`,`portal_id`),
	INDEX `jezyk_tbl_FI_1` (`portal_id`),
	CONSTRAINT `jezyk_tbl_FK_1`
		FOREIGN KEY (`portal_id`)
		REFERENCES `portal` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- portal
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `portal`;


CREATE TABLE `portal`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`aktywny` TINYINT(1) default 0 NOT NULL,
	`nazwa` VARCHAR(50)  NOT NULL,
	`domena` VARCHAR(50)  NOT NULL,
	`skorka` VARCHAR(50),
	`grupa_id` INTEGER(11),
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- login_log
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `login_log`;


CREATE TABLE `login_log`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`portal_id` INTEGER(11),
	`username` VARCHAR(50)  NOT NULL,
	`status` VARCHAR(50)  NOT NULL,
	`ipaddress` VARCHAR(30)  NOT NULL,
	`panel` VARCHAR(10)  NOT NULL,
	PRIMARY KEY (`id`),
	INDEX `login_log_FI_1` (`portal_id`),
	CONSTRAINT `login_log_FK_1`
		FOREIGN KEY (`portal_id`)
		REFERENCES `portal` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- moduly_portal
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `moduly_portal`;


CREATE TABLE `moduly_portal`
(
	`portal_id` INTEGER(11) default 0 NOT NULL,
	`modul_id` INTEGER(11) default 0 NOT NULL,
	`kategoria_id` INTEGER(11),
	PRIMARY KEY (`portal_id`,`modul_id`),
	CONSTRAINT `moduly_portal_FK_1`
		FOREIGN KEY (`portal_id`)
		REFERENCES `portal` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `moduly_portal_FI_2` (`modul_id`),
	CONSTRAINT `moduly_portal_FK_2`
		FOREIGN KEY (`modul_id`)
		REFERENCES `modul` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- tlumaczenie_system_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `tlumaczenie_system_tbl`;


CREATE TABLE `tlumaczenie_system_tbl`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`tresc` INTEGER(100) default 0 NOT NULL,
	`identyfikator` INTEGER(11) default 0 NOT NULL,
	`pole` VARCHAR(50)  NOT NULL,
	`jezyk_id` INTEGER(11) default 0 NOT NULL,
	PRIMARY KEY (`id`,`jezyk_id`),
	KEY `jezyk_id`(`jezyk_id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- tryb_modul
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `tryb_modul`;


CREATE TABLE `tryb_modul`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`modul_id` INTEGER(11) default 0 NOT NULL,
	`tryb_id` INTEGER(11) default 0 NOT NULL,
	PRIMARY KEY (`id`),
	KEY `tryb_id`(`tryb_id`),
	KEY `modul_id`(`modul_id`),
	CONSTRAINT `tryb_modul_FK_1`
		FOREIGN KEY (`modul_id`)
		REFERENCES `modul` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	CONSTRAINT `tryb_modul_FK_2`
		FOREIGN KEY (`tryb_id`)
		REFERENCES `tryb_tbl` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- tryb_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `tryb_tbl`;


CREATE TABLE `tryb_tbl`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`nazwa` VARCHAR(50)  NOT NULL,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- ustawienie_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `ustawienie_tbl`;


CREATE TABLE `ustawienie_tbl`
(
	`nazwa` VARCHAR(100)  NOT NULL,
	`tresc` TEXT,
	`updated_at` DATETIME,
	`portal_id` INTEGER(11) default 0 NOT NULL,
	PRIMARY KEY (`nazwa`,`portal_id`),
	INDEX `ustawienie_tbl_FI_1` (`portal_id`),
	CONSTRAINT `ustawienie_tbl_FK_1`
		FOREIGN KEY (`portal_id`)
		REFERENCES `portal` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- pole_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `pole_tbl`;


CREATE TABLE `pole_tbl`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`tresc` VARCHAR(100)  NOT NULL,
	`jezyk_id` INTEGER(11) default 0 NOT NULL,
	PRIMARY KEY (`id`),
	KEY `jezyk_id`(`jezyk_id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- komunikat_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `komunikat_tbl`;


CREATE TABLE `komunikat_tbl`
(
	`nazwa` VARCHAR(25)  NOT NULL,
	`tresc` TEXT  NOT NULL,
	`jezyk_id` INTEGER(11) default 0 NOT NULL,
	PRIMARY KEY (`nazwa`),
	KEY `jezyk_id`(`jezyk_id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- modul
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `modul`;


CREATE TABLE `modul`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`short` VARCHAR(4)  NOT NULL,
	`permissions` TINYINT(1) default 0 NOT NULL,
	`multisite` TINYINT(1) default 0 NOT NULL,
	`banners` TINYINT(1) default 0 NOT NULL,
	`nazwa` VARCHAR(50)  NOT NULL,
	`tab_color` TINYINT(1) default 0,
	`is_menu` TINYINT(1) default 0,
	`show_in_portal` TINYINT(1) default 0,
	PRIMARY KEY (`id`),
	UNIQUE KEY `modul_U_1` (`short`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- modul_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `modul_i18n`;


CREATE TABLE `modul_i18n`
(
	`id` INTEGER  NOT NULL,
	`active` TINYINT(1) default 1 NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`portal_id` INTEGER(11) default 0 NOT NULL,
	PRIMARY KEY (`id`,`culture`,`portal_id`),
	CONSTRAINT `modul_i18n_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `modul` (`id`)
		ON DELETE CASCADE,
	INDEX `modul_i18n_FI_2` (`portal_id`),
	CONSTRAINT `modul_i18n_FK_2`
		FOREIGN KEY (`portal_id`)
		REFERENCES `portal` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- pomoc_slownik_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `pomoc_slownik_tbl`;


CREATE TABLE `pomoc_slownik_tbl`
(
	`pomoc_slownik_id` BIGINT(20)  NOT NULL AUTO_INCREMENT,
	`pomoc_slownik_nazwa` VARCHAR(255)  NOT NULL,
	`pomoc_slownik_opis` TEXT  NOT NULL,
	`pomoc_slownik_tresc_pl` TEXT  NOT NULL,
	`pomoc_slownik_tresc_en` TEXT  NOT NULL,
	PRIMARY KEY (`pomoc_slownik_id`),
	UNIQUE KEY `pomoc_slownik_nazwa` (`pomoc_slownik_nazwa`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- rejestr_fraz
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `rejestr_fraz`;


CREATE TABLE `rejestr_fraz`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`nazwa` VARCHAR(255)  NOT NULL,
	`czy_opis` TINYINT(1) default 0 NOT NULL,
	`opis` TEXT,
	`ilosc_zapytan` INTEGER(11) default 0,
	`created_at` DATETIME,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_kategoria_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_kategoria_tbl`;


CREATE TABLE `galeria_kategoria_tbl`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`updated_at` DATETIME,
	`created_at` DATETIME,
	`kolejnosc` INTEGER(11) default 0,
	`widoczna` TINYINT(1) default 0 NOT NULL,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_kategoria_tbl_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_kategoria_tbl_i18n`;


CREATE TABLE `galeria_kategoria_tbl_i18n`
(
	`nazwa` VARCHAR(100)  NOT NULL,
	`id` INTEGER  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	PRIMARY KEY (`id`,`culture`),
	CONSTRAINT `galeria_kategoria_tbl_i18n_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `galeria_kategoria_tbl` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_subkategoria_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_subkategoria_tbl`;


CREATE TABLE `galeria_subkategoria_tbl`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`updated_at` DATETIME,
	`created_at` DATETIME,
	`kolejnosc` INTEGER(11) default 0,
	`kategoria_id` INTEGER(11) default 0 NOT NULL,
	PRIMARY KEY (`id`),
	INDEX `galeria_subkategoria_tbl_FI_1` (`kategoria_id`),
	CONSTRAINT `galeria_subkategoria_tbl_FK_1`
		FOREIGN KEY (`kategoria_id`)
		REFERENCES `galeria_kategoria_tbl` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_subkategoria_tbl_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_subkategoria_tbl_i18n`;


CREATE TABLE `galeria_subkategoria_tbl_i18n`
(
	`nazwa` VARCHAR(100)  NOT NULL,
	`id` INTEGER  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	PRIMARY KEY (`id`,`culture`),
	CONSTRAINT `galeria_subkategoria_tbl_i18n_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `galeria_subkategoria_tbl` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_tag
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_tag`;


CREATE TABLE `galeria_tag`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`updated_at` DATETIME,
	`created_at` DATETIME,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_tag_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_tag_i18n`;


CREATE TABLE `galeria_tag_i18n`
(
	`id` INTEGER  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	`nazwa` VARCHAR(100)  NOT NULL,
	PRIMARY KEY (`id`,`culture`),
	CONSTRAINT `galeria_tag_i18n_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `galeria_tag` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_tag_map
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_tag_map`;


CREATE TABLE `galeria_tag_map`
(
	`galeria_id` INTEGER  NOT NULL,
	`tag_id` INTEGER  NOT NULL,
	PRIMARY KEY (`galeria_id`,`tag_id`),
	CONSTRAINT `galeria_tag_map_FK_1`
		FOREIGN KEY (`galeria_id`)
		REFERENCES `galeria_tbl` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `galeria_tag_map_FI_2` (`tag_id`),
	CONSTRAINT `galeria_tag_map_FK_2`
		FOREIGN KEY (`tag_id`)
		REFERENCES `galeria_tag` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_tbl`;


CREATE TABLE `galeria_tbl`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`updated_at` DATETIME,
	`created_at` DATETIME,
	`kolejnosc` INTEGER(11) default 0,
	`widoczna` TINYINT(1) default 0 NOT NULL,
	`obraz_id` INTEGER(11),
	`uzytkownik_id` INTEGER(11)  NOT NULL,
	`subkategoria_id` INTEGER(11)  NOT NULL,
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`id`),
	INDEX `galeria_tbl_FI_1` (`uzytkownik_id`),
	CONSTRAINT `galeria_tbl_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `galeria_tbl_FI_2` (`subkategoria_id`),
	CONSTRAINT `galeria_tbl_FK_2`
		FOREIGN KEY (`subkategoria_id`)
		REFERENCES `galeria_subkategoria_tbl` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_tbl_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_tbl_i18n`;


CREATE TABLE `galeria_tbl_i18n`
(
	`zajawka` VARCHAR(250)  NOT NULL,
	`tytul` VARCHAR(200)  NOT NULL,
	`id` INTEGER  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	PRIMARY KEY (`id`,`culture`),
	CONSTRAINT `galeria_tbl_i18n_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `galeria_tbl` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_obraz_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_obraz_tbl`;


CREATE TABLE `galeria_obraz_tbl`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`nazwa_pliku` VARCHAR(100)  NOT NULL,
	`tytul` VARCHAR(200)  NOT NULL,
	`kolejnosc` INTEGER(11) default 0,
	`uzytkownik_id` INTEGER(11)  NOT NULL,
	`galeria_id` INTEGER(11) default 0 NOT NULL,
	PRIMARY KEY (`id`),
	INDEX `galeria_obraz_tbl_FI_1` (`uzytkownik_id`),
	CONSTRAINT `galeria_obraz_tbl_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `galeria_obraz_tbl_FI_2` (`galeria_id`),
	CONSTRAINT `galeria_obraz_tbl_FK_2`
		FOREIGN KEY (`galeria_id`)
		REFERENCES `galeria_tbl` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_obraz_tbl_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_obraz_tbl_i18n`;


CREATE TABLE `galeria_obraz_tbl_i18n`
(
	`nazwa` VARCHAR(200),
	`opis` TEXT,
	`id` INTEGER  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	PRIMARY KEY (`id`,`culture`),
	CONSTRAINT `galeria_obraz_tbl_i18n_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `galeria_obraz_tbl` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_pub`;


CREATE TABLE `galeria_pub`
(
	`id` INTEGER(11) default 0 NOT NULL,
	`updated_at` DATETIME,
	`created_at` DATETIME,
	`kolejnosc` INTEGER(11) default 0,
	`widoczna` TINYINT(1) default 0 NOT NULL,
	`obraz_id` INTEGER(11),
	`uzytkownik_id` INTEGER(11)  NOT NULL,
	`subkategoria_id` INTEGER(11)  NOT NULL,
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`id`),
	CONSTRAINT `galeria_pub_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `galeria_tbl` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `galeria_pub_FI_2` (`uzytkownik_id`),
	CONSTRAINT `galeria_pub_FK_2`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `galeria_pub_FI_3` (`subkategoria_id`),
	CONSTRAINT `galeria_pub_FK_3`
		FOREIGN KEY (`subkategoria_id`)
		REFERENCES `galeria_subkategoria_tbl` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_pub_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_pub_i18n`;


CREATE TABLE `galeria_pub_i18n`
(
	`zajawka` VARCHAR(250),
	`tytul` VARCHAR(200),
	`id` INTEGER  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	PRIMARY KEY (`id`,`culture`),
	CONSTRAINT `galeria_pub_i18n_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `galeria_pub` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_rank
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_rank`;


CREATE TABLE `galeria_rank`
(
	`galeria_id` INTEGER  NOT NULL,
	`updated_at` DATETIME,
	`created_at` DATETIME,
	`rank` FLOAT default 0 NOT NULL,
	`voters` INTEGER(11) default 0 NOT NULL,
	`views` INTEGER(11) default 0 NOT NULL,
	PRIMARY KEY (`galeria_id`),
	CONSTRAINT `galeria_rank_FK_1`
		FOREIGN KEY (`galeria_id`)
		REFERENCES `galeria_pub` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_stat
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_stat`;


CREATE TABLE `galeria_stat`
(
	`galeria_id` INTEGER  NOT NULL,
	`rok` INTEGER(4)  NOT NULL,
	`miesiac` INTEGER(2)  NOT NULL,
	`wejsc` INTEGER(11),
	PRIMARY KEY (`galeria_id`,`rok`,`miesiac`),
	CONSTRAINT `galeria_stat_FK_1`
		FOREIGN KEY (`galeria_id`)
		REFERENCES `galeria_pub` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_obraz_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_obraz_pub`;


CREATE TABLE `galeria_obraz_pub`
(
	`id` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`nazwa_pliku` VARCHAR(100)  NOT NULL,
	`tytul` VARCHAR(200)  NOT NULL,
	`kolejnosc` INTEGER(11) default 0,
	`uzytkownik_id` INTEGER(11)  NOT NULL,
	`galeria_id` INTEGER(11) default 0 NOT NULL,
	PRIMARY KEY (`id`),
	INDEX `galeria_obraz_pub_FI_1` (`uzytkownik_id`),
	CONSTRAINT `galeria_obraz_pub_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `galeria_obraz_pub_FI_2` (`galeria_id`),
	CONSTRAINT `galeria_obraz_pub_FK_2`
		FOREIGN KEY (`galeria_id`)
		REFERENCES `galeria_pub` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- galeria_obraz_pub_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `galeria_obraz_pub_i18n`;


CREATE TABLE `galeria_obraz_pub_i18n`
(
	`nazwa` VARCHAR(200),
	`opis` TEXT,
	`id` INTEGER  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	PRIMARY KEY (`id`,`culture`),
	CONSTRAINT `galeria_obraz_pub_i18n_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `galeria_obraz_pub` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- sf_guard_user_profile
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `sf_guard_user_profile`;


CREATE TABLE `sf_guard_user_profile`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`imie` VARCHAR(50)  NOT NULL,
	`nazwisko` VARCHAR(50)  NOT NULL,
	`email` VARCHAR(100)  NOT NULL,
	`miasto` VARCHAR(100)  NOT NULL,
	`ulica` VARCHAR(100)  NOT NULL,
	`kod_pocztowy` VARCHAR(6)  NOT NULL,
	`nr_telefonu` VARCHAR(20)  NOT NULL,
	`user_id` INTEGER(11)  NOT NULL,
	`organizacja_id` INTEGER(11),
	`funkcja_id` INTEGER(11),
	PRIMARY KEY (`id`),
	KEY `funkcja_id`(`funkcja_id`),
	KEY `organizacja_id`(`organizacja_id`),
	INDEX `sf_guard_user_profile_FI_1` (`user_id`),
	CONSTRAINT `sf_guard_user_profile_FK_1`
		FOREIGN KEY (`user_id`)
		REFERENCES `sf_guard_user` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- sf_guard_user_messages
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `sf_guard_user_messages`;


CREATE TABLE `sf_guard_user_messages`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`temat` VARCHAR(255)  NOT NULL,
	`tresc` TEXT  NOT NULL,
	`status` TINYINT(1) default 1,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- sf_guard_user_messages_map
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `sf_guard_user_messages_map`;


CREATE TABLE `sf_guard_user_messages_map`
(
	`user_id` INTEGER(11)  NOT NULL,
	`message_id` INTEGER(11)  NOT NULL,
	PRIMARY KEY (`user_id`,`message_id`),
	CONSTRAINT `sf_guard_user_messages_map_FK_1`
		FOREIGN KEY (`user_id`)
		REFERENCES `sf_guard_user` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `sf_guard_user_messages_map_FI_2` (`message_id`),
	CONSTRAINT `sf_guard_user_messages_map_FK_2`
		FOREIGN KEY (`message_id`)
		REFERENCES `sf_guard_user_messages` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- organizacja_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `organizacja_tbl`;


CREATE TABLE `organizacja_tbl`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`nazwa` VARCHAR(50)  NOT NULL,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- dostep_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `dostep_tbl`;


CREATE TABLE `dostep_tbl`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`ip` VARCHAR(15) default '000.000.000.000' NOT NULL,
	`dopusc` SMALLINT(1) default 1 NOT NULL,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- funkcja_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `funkcja_tbl`;


CREATE TABLE `funkcja_tbl`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`nazwa` VARCHAR(50)  NOT NULL,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_kategoria_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_kategoria_tbl`;


CREATE TABLE `strona_kategoria_tbl`
(
	`strona_kategoria_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`strona_kategoria_nazwa` VARCHAR(255)  NOT NULL,
	`strona_kategoria_nadrzedna` INTEGER(10),
	`strona_kategoria_ukryta` TINYINT(1) default 0 NOT NULL,
	`strona_kategoria_menu` TINYINT(1) default 0 NOT NULL,
	`strona_kategoria_tresc` TEXT,
	`strona_kategoria_pokazuj_tresc` TINYINT(1) default 1 NOT NULL,
	`strona_kategoria_pokazuj_strony` TINYINT(1) default 1 NOT NULL,
	`strona_kategoria_strona_id` INTEGER(10),
	`strona_kategoria_uzytkownik_id` INTEGER(11)  NOT NULL,
	`strona_kategoria_data_dodania` DATETIME  NOT NULL,
	`strona_kategoria_data_modyfikacji` DATETIME  NOT NULL,
	`strona_kategoria_zatwierdzona` TINYINT(1) default 0 NOT NULL,
	PRIMARY KEY (`strona_kategoria_id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_kategoria_tbl_arch
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_kategoria_tbl_arch`;


CREATE TABLE `strona_kategoria_tbl_arch`
(
	`strona_kategoria_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`strona_kategoria_usunieta_id` INTEGER(11),
	`strona_kategoria_nazwa` VARCHAR(255)  NOT NULL,
	`strona_kategoria_nadrzedna` INTEGER(10) default 0 NOT NULL,
	`strona_kategoria_ukryta` TINYINT(1) default 0 NOT NULL,
	`strona_kategoria_menu` TINYINT(1) default 0 NOT NULL,
	`strona_kategoria_tresc` TEXT,
	`strona_kategoria_pokazuj_tresc` TINYINT(1) default 1 NOT NULL,
	`strona_kategoria_pokazuj_strony` TINYINT(1) default 1 NOT NULL,
	`strona_kategoria_strona_id` INTEGER(10),
	`strona_kategoria_uzytkownik_id` INTEGER(11) default 0 NOT NULL,
	`strona_kategoria_data_dodania` DATETIME  NOT NULL,
	`strona_kategoria_data_modyfikacji` DATETIME  NOT NULL,
	`strona_kategoria_zatwierdzona` TINYINT(1) default 0 NOT NULL,
	PRIMARY KEY (`strona_kategoria_id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_stopka_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_stopka_tbl`;


CREATE TABLE `strona_stopka_tbl`
(
	`strona_stopka_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`strona_stopka_tresc` TEXT,
	`strona_stopka_strona_id` INTEGER(11),
	`strona_stopka_strona_kategoria_id` INTEGER(11),
	PRIMARY KEY (`strona_stopka_id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tbl`;


CREATE TABLE `strona_tbl`
(
	`strona_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`uzytkownik_id` INTEGER(11) default 0 NOT NULL,
	`strona_tytul_pl` VARCHAR(255),
	`strona_data_utworzenia` DATETIME  NOT NULL,
	`strona_nadrzedna` INTEGER(11) default 0 NOT NULL,
	`strona_nazwa_nadrzednej` VARCHAR(255)  NOT NULL,
	`strona_kolejnosc` INTEGER(11) default 0 NOT NULL,
	`strona_ostatnia_modyfikacja` DATETIME  NOT NULL,
	`strona_ukryta` TINYINT(1) default 0 NOT NULL,
	`strona_menu` TINYINT(1) default 1 NOT NULL,
	`strona_glowna` TINYINT(1) default 0,
	PRIMARY KEY (`strona_id`),
	INDEX `strona_tbl_FI_1` (`uzytkownik_id`),
	CONSTRAINT `strona_tbl_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_portal
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_portal`;


CREATE TABLE `strona_portal`
(
	`portal_id` INTEGER(11) default 0 NOT NULL,
	`strona_id` INTEGER(11) default 0 NOT NULL,
	`strona_promowana` TINYINT(1) default 0 NOT NULL,
	PRIMARY KEY (`portal_id`,`strona_id`),
	KEY `strona_portal`(`portal_id`, `strona_id`),
	CONSTRAINT `strona_portal_FK_1`
		FOREIGN KEY (`portal_id`)
		REFERENCES `portal` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tbl_arch
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tbl_arch`;


CREATE TABLE `strona_tbl_arch`
(
	`strona_id` INTEGER(11)  NOT NULL,
	`uzytkownik_id` INTEGER(11),
	`strona_tytul_pl` VARCHAR(255),
	`strona_usunieta_id` INTEGER(11),
	`strona_data_utworzenia` DATETIME  NOT NULL,
	`strona_nadrzedna` INTEGER(11) default 0 NOT NULL,
	`strona_kolejnosc` INTEGER(11) default 0 NOT NULL,
	`strona_ostatnia_modyfikacja` DATETIME  NOT NULL,
	`strona_ukryta` TINYINT(1) default 0 NOT NULL,
	`strona_menu` TINYINT(1) default 1 NOT NULL,
	`strona_glowna` TINYINT(1) default 0,
	`strona_kto_usunal` VARCHAR(255),
	`strona_data_usuniecia` DATETIME  NOT NULL,
	PRIMARY KEY (`strona_id`),
	INDEX `strona_tbl_arch_FI_1` (`uzytkownik_id`),
	CONSTRAINT `strona_tbl_arch_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_portal_arch
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_portal_arch`;


CREATE TABLE `strona_portal_arch`
(
	`portal_id` INTEGER(11) default 0 NOT NULL,
	`strona_id` INTEGER(11) default 0 NOT NULL,
	`strona_promowana` TINYINT(1) default 0 NOT NULL,
	PRIMARY KEY (`portal_id`,`strona_id`),
	KEY `strona_portal`(`portal_id`, `strona_id`),
	CONSTRAINT `strona_portal_arch_FK_1`
		FOREIGN KEY (`portal_id`)
		REFERENCES `portal` (`id`)
		ON DELETE CASCADE,
	INDEX `strona_portal_arch_FI_2` (`strona_id`),
	CONSTRAINT `strona_portal_arch_FK_2`
		FOREIGN KEY (`strona_id`)
		REFERENCES `strona_tbl_arch` (`strona_id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tresc_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tresc_tbl`;


CREATE TABLE `strona_tresc_tbl`
(
	`tresc_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`tresc_publikowana` TINYINT(1) default 1 NOT NULL,
	`tresc_data_utworzenia` DATETIME  NOT NULL,
	`tresc_wytworzyl` VARCHAR(255),
	`tresc_zatwierdzil` INTEGER(11),
	`tresc_ukryta` TINYINT(1) default 0 NOT NULL,
	`tresc_tytul` VARCHAR(255)  NOT NULL,
	`tresc_tekst` LONGTEXT  NOT NULL,
	`tresc_zajawka` TEXT,
	`tresc_ukryj_zajawki_podstron` TINYINT(1) default 0 NOT NULL,
	`tresc_grafika_zajawki` VARCHAR(255),
	`tresc_nazwa_pliku_zajawki` VARCHAR(255),
	`tresc_opis_grafiki_zajawki` TEXT,
	`tresc_meta_kluczowe` VARCHAR(255)  NOT NULL,
	`tresc_meta_tytul` VARCHAR(255)  NOT NULL,
	`tresc_meta_description` VARCHAR(255)  NOT NULL,
	`tresc_jezyk_id` INTEGER(11) default 0 NOT NULL,
	`tresc_strona_id` INTEGER(11),
	`tresc_strona_kategoria_id` INTEGER(11),
	`tresc_pokazuj_tresc` TINYINT(1) default 1 NOT NULL,
	`tresc_ostatnia_modyfikacja` DATETIME  NOT NULL,
	`tresc_data_publikacji` DATETIME  NOT NULL,
	`tresc_publikacja_od` DATETIME,
	`tresc_publikacja_do` DATETIME,
	`tresc_uzytkownik_id` INTEGER(11) default 0 NOT NULL,
	`tresc_zatwierdzona` TINYINT(1) default 0 NOT NULL,
	`tresc_menu` TINYINT(1) default 1 NOT NULL,
	`tresc_promowana` TINYINT(4) default 0 NOT NULL,
	`tresc_przekierowanie` VARCHAR(255),
	`tresc_uwagi` TEXT,
	`tresc_opis_zmian` TEXT,
	`tresc_link_bezposredni` VARCHAR(255),
	`tresc_link_target` VARCHAR(50) default '_self' NOT NULL,
	`tresc_link_wew` INTEGER(11) default null,
	`tresc_dodatkowa_stopka` TEXT,
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`tresc_id`),
	KEY `tresc_jezyk_id`(`tresc_jezyk_id`),
	KEY `tresc_strona_id`(`tresc_strona_id`),
	KEY `tresc_strona_kategoria_id`(`tresc_strona_kategoria_id`),
	CONSTRAINT `strona_tresc_tbl_FK_1`
		FOREIGN KEY (`tresc_strona_id`)
		REFERENCES `strona_tbl` (`strona_id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tresc_tbl_arch
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tresc_tbl_arch`;


CREATE TABLE `strona_tresc_tbl_arch`
(
	`tresc_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`tresc_publikowana` TINYINT(1) default 1 NOT NULL,
	`tresc_data_utworzenia` DATETIME  NOT NULL,
	`tresc_wytworzyl` VARCHAR(255),
	`tresc_zatwierdzil` INTEGER(11),
	`tresc_ukryta` TINYINT(1) default 0 NOT NULL,
	`tresc_tytul` VARCHAR(255)  NOT NULL,
	`tresc_tekst` LONGTEXT  NOT NULL,
	`tresc_zajawka` TEXT  NOT NULL,
	`tresc_ukryj_zajawki_podstron` TINYINT(1) default 0 NOT NULL,
	`tresc_grafika_zajawki` VARCHAR(255),
	`tresc_nazwa_pliku_zajawki` VARCHAR(255),
	`tresc_opis_grafiki_zajawki` TEXT,
	`tresc_meta_kluczowe` VARCHAR(255)  NOT NULL,
	`tresc_meta_tytul` VARCHAR(255)  NOT NULL,
	`tresc_meta_description` VARCHAR(255)  NOT NULL,
	`tresc_jezyk_id` INTEGER(11) default 0 NOT NULL,
	`tresc_strona_id` INTEGER(11),
	`tresc_strona_usunieta_id` INTEGER(11),
	`tresc_strona_kategoria_id` INTEGER(11),
	`tresc_pokazuj_tresc` TINYINT(1) default 1 NOT NULL,
	`tresc_ostatnia_modyfikacja` DATETIME  NOT NULL,
	`tresc_data_publikacji` DATETIME,
	`tresc_publikacja_od` DATETIME,
	`tresc_publikacja_do` DATETIME,
	`tresc_uzytkownik_id` INTEGER(11) default 0 NOT NULL,
	`tresc_zatwierdzona` TINYINT(1) default 0 NOT NULL,
	`tresc_menu` TINYINT(1) default 1 NOT NULL,
	`tresc_promowana` TINYINT(4) default 0 NOT NULL,
	`tresc_przekierowanie` VARCHAR(255),
	`tresc_uwagi` TEXT,
	`tresc_opis_zmian` TEXT,
	`tresc_link_bezposredni` VARCHAR(255),
	`tresc_link_target` VARCHAR(50) default '_self' NOT NULL,
	`tresc_link_wew` INTEGER(11) default null,
	`tresc_dodatkowa_stopka` TEXT,
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`tresc_id`),
	KEY `tresc_strona_id`(`tresc_strona_id`),
	KEY `tresc_strona_kategoria_id`(`tresc_strona_kategoria_id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tresc_temp_tbl
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tresc_temp_tbl`;


CREATE TABLE `strona_tresc_temp_tbl`
(
	`tresc_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`tresc_data_utworzenia` DATETIME  NOT NULL,
	`tresc_wytworzyl` VARCHAR(255),
	`tresc_zatwierdzil` INTEGER(11),
	`tresc_ukryta` TINYINT(1) default 0 NOT NULL,
	`tresc_tytul` VARCHAR(255)  NOT NULL,
	`tresc_tekst` LONGTEXT  NOT NULL,
	`tresc_zajawka` TEXT,
	`tresc_generuj_zajawke` TINYINT(1) default 1,
	`tresc_ukryj_zajawki_podstron` TINYINT(1) default 0 NOT NULL,
	`tresc_grafika_zajawki` VARCHAR(255),
	`tresc_nazwa_pliku_zajawki` VARCHAR(255),
	`tresc_opis_grafiki_zajawki` TEXT,
	`tresc_meta_kluczowe` VARCHAR(255)  NOT NULL,
	`tresc_meta_tytul` VARCHAR(255)  NOT NULL,
	`tresc_meta_description` VARCHAR(255)  NOT NULL,
	`tresc_jezyk_id` INTEGER(11) default 0 NOT NULL,
	`tresc_strona_id` INTEGER(11),
	`tresc_strona_kategoria_id` INTEGER(11),
	`tresc_pokazuj_tresc` TINYINT(1) default 1 NOT NULL,
	`tresc_ostatnia_modyfikacja` DATETIME  NOT NULL,
	`tresc_data_publikacji` DATETIME  NOT NULL,
	`tresc_publikacja_od` DATETIME,
	`tresc_publikacja_do` DATETIME,
	`tresc_uzytkownik_id` INTEGER(11) default 0 NOT NULL,
	`tresc_zatwierdzona` TINYINT(1) default 0 NOT NULL,
	`tresc_w_publikacji` TINYINT(1) default 0 NOT NULL,
	`tresc_menu` TINYINT(1) default 1 NOT NULL,
	`tresc_promowana` TINYINT(4) default 0 NOT NULL,
	`tresc_przekierowanie` VARCHAR(255),
	`tresc_uwagi` TEXT,
	`tresc_opis_zmian` TEXT,
	`tresc_link_bezposredni` VARCHAR(255),
	`tresc_link_target` VARCHAR(50) default '_self' NOT NULL,
	`tresc_dodatkowa_stopka` TEXT,
	`tresc_link_wew` INTEGER(11) default null,
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`tresc_id`),
	KEY `tresc_jezyk_id`(`tresc_jezyk_id`),
	KEY `tresc_strona_id`(`tresc_strona_id`),
	KEY `tresc_strona_kategoria_id`(`tresc_strona_kategoria_id`),
	CONSTRAINT `strona_tresc_temp_tbl_FK_1`
		FOREIGN KEY (`tresc_strona_id`)
		REFERENCES `strona_tbl` (`strona_id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tresc_aktualnosc_kategoria_temp
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tresc_aktualnosc_kategoria_temp`;


CREATE TABLE `strona_tresc_aktualnosc_kategoria_temp`
(
	`tresc_id` INTEGER  NOT NULL,
	`kategoria_id` INTEGER  NOT NULL,
	PRIMARY KEY (`tresc_id`,`kategoria_id`),
	CONSTRAINT `strona_tresc_aktualnosc_kategoria_temp_FK_1`
		FOREIGN KEY (`tresc_id`)
		REFERENCES `strona_tresc_temp_tbl` (`tresc_id`)
		ON DELETE CASCADE,
	INDEX `strona_tresc_aktualnosc_kategoria_temp_FI_2` (`kategoria_id`),
	CONSTRAINT `strona_tresc_aktualnosc_kategoria_temp_FK_2`
		FOREIGN KEY (`kategoria_id`)
		REFERENCES `aktualnosc_kategoria` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tresc_aktualnosc_kategoria
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tresc_aktualnosc_kategoria`;


CREATE TABLE `strona_tresc_aktualnosc_kategoria`
(
	`tresc_id` INTEGER  NOT NULL,
	`kategoria_id` INTEGER  NOT NULL,
	PRIMARY KEY (`tresc_id`,`kategoria_id`),
	CONSTRAINT `strona_tresc_aktualnosc_kategoria_FK_1`
		FOREIGN KEY (`tresc_id`)
		REFERENCES `strona_tresc_tbl` (`tresc_id`)
		ON DELETE CASCADE,
	INDEX `strona_tresc_aktualnosc_kategoria_FI_2` (`kategoria_id`),
	CONSTRAINT `strona_tresc_aktualnosc_kategoria_FK_2`
		FOREIGN KEY (`kategoria_id`)
		REFERENCES `aktualnosc_kategoria` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tresc_aktualnosc_kategoria_arch
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tresc_aktualnosc_kategoria_arch`;


CREATE TABLE `strona_tresc_aktualnosc_kategoria_arch`
(
	`tresc_id` INTEGER  NOT NULL,
	`kategoria_id` INTEGER  NOT NULL,
	PRIMARY KEY (`tresc_id`,`kategoria_id`),
	CONSTRAINT `strona_tresc_aktualnosc_kategoria_arch_FK_1`
		FOREIGN KEY (`tresc_id`)
		REFERENCES `strona_tresc_tbl_arch` (`tresc_id`)
		ON DELETE CASCADE,
	INDEX `strona_tresc_aktualnosc_kategoria_arch_FI_2` (`kategoria_id`),
	CONSTRAINT `strona_tresc_aktualnosc_kategoria_arch_FK_2`
		FOREIGN KEY (`kategoria_id`)
		REFERENCES `aktualnosc_kategoria` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tresc_galeria
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tresc_galeria`;


CREATE TABLE `strona_tresc_galeria`
(
	`tresc_id` INTEGER  NOT NULL,
	`galeria_id` INTEGER  NOT NULL,
	PRIMARY KEY (`tresc_id`,`galeria_id`),
	CONSTRAINT `strona_tresc_galeria_FK_1`
		FOREIGN KEY (`tresc_id`)
		REFERENCES `strona_tresc_tbl` (`tresc_id`)
		ON DELETE CASCADE,
	INDEX `strona_tresc_galeria_FI_2` (`galeria_id`),
	CONSTRAINT `strona_tresc_galeria_FK_2`
		FOREIGN KEY (`galeria_id`)
		REFERENCES `galeria_pub` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tresc_galeria_temp
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tresc_galeria_temp`;


CREATE TABLE `strona_tresc_galeria_temp`
(
	`tresc_id` INTEGER  NOT NULL,
	`galeria_id` INTEGER  NOT NULL,
	PRIMARY KEY (`tresc_id`,`galeria_id`),
	CONSTRAINT `strona_tresc_galeria_temp_FK_1`
		FOREIGN KEY (`tresc_id`)
		REFERENCES `strona_tresc_temp_tbl` (`tresc_id`)
		ON DELETE CASCADE,
	INDEX `strona_tresc_galeria_temp_FI_2` (`galeria_id`),
	CONSTRAINT `strona_tresc_galeria_temp_FK_2`
		FOREIGN KEY (`galeria_id`)
		REFERENCES `galeria_pub` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tresc_galeria_arch
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tresc_galeria_arch`;


CREATE TABLE `strona_tresc_galeria_arch`
(
	`tresc_id` INTEGER  NOT NULL,
	`galeria_id` INTEGER  NOT NULL,
	PRIMARY KEY (`tresc_id`,`galeria_id`),
	CONSTRAINT `strona_tresc_galeria_arch_FK_1`
		FOREIGN KEY (`tresc_id`)
		REFERENCES `strona_tresc_tbl_arch` (`tresc_id`)
		ON DELETE CASCADE,
	INDEX `strona_tresc_galeria_arch_FI_2` (`galeria_id`),
	CONSTRAINT `strona_tresc_galeria_arch_FK_2`
		FOREIGN KEY (`galeria_id`)
		REFERENCES `galeria_pub` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tresc_multimedia_map
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tresc_multimedia_map`;


CREATE TABLE `strona_tresc_multimedia_map`
(
	`tresc_id` INTEGER  NOT NULL,
	`multimedia_id` INTEGER  NOT NULL,
	PRIMARY KEY (`tresc_id`,`multimedia_id`),
	CONSTRAINT `strona_tresc_multimedia_map_FK_1`
		FOREIGN KEY (`tresc_id`)
		REFERENCES `strona_tresc_tbl` (`tresc_id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `strona_tresc_multimedia_map_FI_2` (`multimedia_id`),
	CONSTRAINT `strona_tresc_multimedia_map_FK_2`
		FOREIGN KEY (`multimedia_id`)
		REFERENCES `multimedia` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tresc_multimedia_map_temp
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tresc_multimedia_map_temp`;


CREATE TABLE `strona_tresc_multimedia_map_temp`
(
	`tresc_id` INTEGER  NOT NULL,
	`multimedia_id` INTEGER  NOT NULL,
	PRIMARY KEY (`tresc_id`,`multimedia_id`),
	CONSTRAINT `strona_tresc_multimedia_map_temp_FK_1`
		FOREIGN KEY (`tresc_id`)
		REFERENCES `strona_tresc_temp_tbl` (`tresc_id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `strona_tresc_multimedia_map_temp_FI_2` (`multimedia_id`),
	CONSTRAINT `strona_tresc_multimedia_map_temp_FK_2`
		FOREIGN KEY (`multimedia_id`)
		REFERENCES `multimedia` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tresc_multimedia_map_arch
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tresc_multimedia_map_arch`;


CREATE TABLE `strona_tresc_multimedia_map_arch`
(
	`tresc_id` INTEGER  NOT NULL,
	`multimedia_id` INTEGER  NOT NULL,
	PRIMARY KEY (`tresc_id`,`multimedia_id`),
	CONSTRAINT `strona_tresc_multimedia_map_arch_FK_1`
		FOREIGN KEY (`tresc_id`)
		REFERENCES `strona_tresc_tbl_arch` (`tresc_id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `strona_tresc_multimedia_map_arch_FI_2` (`multimedia_id`),
	CONSTRAINT `strona_tresc_multimedia_map_arch_FK_2`
		FOREIGN KEY (`multimedia_id`)
		REFERENCES `multimedia` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- log_strona
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `log_strona`;


CREATE TABLE `log_strona`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`id_strony` INTEGER(11) default 0 NOT NULL,
	`id_tresc` INTEGER(11) default null,
	`id_tresc_temp` INTEGER(11) default null,
	`id_tresc_arch` INTEGER(11) default null,
	`operacja` TEXT,
	`created_at` DATETIME,
	`user_id` INTEGER(11) default null,
	PRIMARY KEY (`id`),
	INDEX `log_strona_FI_1` (`user_id`),
	CONSTRAINT `log_strona_FK_1`
		FOREIGN KEY (`user_id`)
		REFERENCES `sf_guard_user` (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- log_messages
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `log_messages`;


CREATE TABLE `log_messages`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- stat_strona_tresc
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `stat_strona_tresc`;


CREATE TABLE `stat_strona_tresc`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`id_strona` INTEGER(11)  NOT NULL,
	`id_jezyk` INTEGER(11)  NOT NULL,
	`rok` INTEGER(4)  NOT NULL,
	`miesiac` INTEGER(2)  NOT NULL,
	`wejsc` INTEGER(255),
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tresc_zalacznik
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tresc_zalacznik`;


CREATE TABLE `strona_tresc_zalacznik`
(
	`tresc_id` INTEGER  NOT NULL,
	`zalacznik_id` INTEGER  NOT NULL,
	`zalacznik_kolejnosc` INTEGER(5) default 0 NOT NULL,
	`zalacznik_widoczny` TINYINT(1) default 1 NOT NULL,
	PRIMARY KEY (`tresc_id`,`zalacznik_id`),
	CONSTRAINT `strona_tresc_zalacznik_FK_1`
		FOREIGN KEY (`tresc_id`)
		REFERENCES `strona_tresc_tbl` (`tresc_id`)
		ON DELETE CASCADE,
	INDEX `strona_tresc_zalacznik_FI_2` (`zalacznik_id`),
	CONSTRAINT `strona_tresc_zalacznik_FK_2`
		FOREIGN KEY (`zalacznik_id`)
		REFERENCES `zalacznik` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tresc_zalacznik_temp
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tresc_zalacznik_temp`;


CREATE TABLE `strona_tresc_zalacznik_temp`
(
	`tresc_temp_id` INTEGER  NOT NULL,
	`zalacznik_id` INTEGER  NOT NULL,
	`zalacznik_kolejnosc` INTEGER(5) default 0 NOT NULL,
	`zalacznik_widoczny` TINYINT(1) default 1 NOT NULL,
	PRIMARY KEY (`tresc_temp_id`,`zalacznik_id`),
	CONSTRAINT `strona_tresc_zalacznik_temp_FK_1`
		FOREIGN KEY (`tresc_temp_id`)
		REFERENCES `strona_tresc_temp_tbl` (`tresc_id`)
		ON DELETE CASCADE,
	INDEX `strona_tresc_zalacznik_temp_FI_2` (`zalacznik_id`),
	CONSTRAINT `strona_tresc_zalacznik_temp_FK_2`
		FOREIGN KEY (`zalacznik_id`)
		REFERENCES `zalacznik` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- strona_tresc_zalacznik_arch
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `strona_tresc_zalacznik_arch`;


CREATE TABLE `strona_tresc_zalacznik_arch`
(
	`tresc_arch_id` INTEGER  NOT NULL,
	`zalacznik_id` INTEGER  NOT NULL,
	`zalacznik_kolejnosc` INTEGER(5) default 0 NOT NULL,
	`zalacznik_widoczny` TINYINT(1) default 1 NOT NULL,
	PRIMARY KEY (`tresc_arch_id`,`zalacznik_id`),
	CONSTRAINT `strona_tresc_zalacznik_arch_FK_1`
		FOREIGN KEY (`tresc_arch_id`)
		REFERENCES `strona_tresc_tbl_arch` (`tresc_id`)
		ON DELETE CASCADE,
	INDEX `strona_tresc_zalacznik_arch_FI_2` (`zalacznik_id`),
	CONSTRAINT `strona_tresc_zalacznik_arch_FK_2`
		FOREIGN KEY (`zalacznik_id`)
		REFERENCES `zalacznik` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- zalacznik_kategoria
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `zalacznik_kategoria`;


CREATE TABLE `zalacznik_kategoria`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`nazwa` VARCHAR(100)  NOT NULL,
	`opis` VARCHAR(250)  NOT NULL,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- zalacznik
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `zalacznik`;


CREATE TABLE `zalacznik`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`sciezka` VARCHAR(255)  NOT NULL,
	`nazwa_pliku` VARCHAR(255)  NOT NULL,
	`rozmiar_pliku` INTEGER(255)  NOT NULL,
	`nazwa` VARCHAR(255)  NOT NULL,
	`opis` TEXT,
	`created_at` DATETIME,
	`kategoria_id` INTEGER(11),
	PRIMARY KEY (`id`),
	INDEX `zalacznik_FI_1` (`kategoria_id`),
	CONSTRAINT `zalacznik_FK_1`
		FOREIGN KEY (`kategoria_id`)
		REFERENCES `zalacznik_kategoria` (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kali_kategorie
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kali_kategorie`;


CREATE TABLE `kali_kategorie`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kali_status
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kali_status`;


CREATE TABLE `kali_status`
(
	`id` INTEGER(3)  NOT NULL,
	`nazwa` VARCHAR(255)  NOT NULL,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kali_kategorie_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kali_kategorie_i18n`;


CREATE TABLE `kali_kategorie_i18n`
(
	`nazwa` VARCHAR(255)  NOT NULL,
	`id` INTEGER  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	PRIMARY KEY (`id`,`culture`),
	CONSTRAINT `kali_kategorie_i18n_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `kali_kategorie` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kali_organizatorzy
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kali_organizatorzy`;


CREATE TABLE `kali_organizatorzy`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`uzytkownik_id` INTEGER(11),
	`nazwa` VARCHAR(255)  NOT NULL,
	`ulica` VARCHAR(255)  NOT NULL,
	`miasto` VARCHAR(255)  NOT NULL,
	`kod_pocztowy` VARCHAR(10) default '00-000' NOT NULL,
	`email` VARCHAR(255),
	`www` VARCHAR(255),
	`tel` VARCHAR(255),
	`fax` VARCHAR(255),
	`osoba_kontaktowa` VARCHAR(255),
	`aktywny` TINYINT(1) default 1 NOT NULL,
	PRIMARY KEY (`id`),
	INDEX `kali_organizatorzy_FI_1` (`uzytkownik_id`),
	CONSTRAINT `kali_organizatorzy_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kali_impreza
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kali_impreza`;


CREATE TABLE `kali_impreza`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`uzytkownik_id` INTEGER(11) default NULL,
	`nazwa` VARCHAR(255)  NOT NULL,
	`miejsce` VARCHAR(255)  NOT NULL,
	`kategoria_id` INTEGER(11)  NOT NULL,
	`organizator_id` INTEGER(11),
	`inni_organizatorzy` TEXT,
	`status_id` INTEGER(11),
	`data_rozpoczecia` DATE,
	`data_zakonczenia` DATE,
	`ilosc_dni` INTEGER(11) default 0,
	`godzina_rozpoczecia` TIME,
	`godzina_zakonczenia` TIME,
	`data_orientacyjna` TINYINT(1) default 0 NOT NULL,
	`strona_www` VARCHAR(255),
	`zglaszajacy` TEXT  NOT NULL,
	`newsletter` TINYINT(1) default 1 NOT NULL,
	`aktywna` TINYINT(1) default 1 NOT NULL,
	`zatwierdzona` TINYINT(1) default 0 NOT NULL,
	`grafika_zajawki` VARCHAR(255),
	`zgloszona` TINYINT(1) default 0,
	`promowana` TINYINT(1) default 0,
	`loc_x` DECIMAL(19,15) default 0.000000000000000,
	`loc_y` DECIMAL(19,15) default 0.000000000000000,
	`loc_z` INTEGER(11),
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`id`),
	INDEX `kali_impreza_FI_1` (`uzytkownik_id`),
	CONSTRAINT `kali_impreza_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`),
	INDEX `kali_impreza_FI_2` (`kategoria_id`),
	CONSTRAINT `kali_impreza_FK_2`
		FOREIGN KEY (`kategoria_id`)
		REFERENCES `kali_kategorie` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `kali_impreza_FI_3` (`organizator_id`),
	CONSTRAINT `kali_impreza_FK_3`
		FOREIGN KEY (`organizator_id`)
		REFERENCES `kali_organizatorzy` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `kali_impreza_FI_4` (`status_id`),
	CONSTRAINT `kali_impreza_FK_4`
		FOREIGN KEY (`status_id`)
		REFERENCES `kali_status` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kali_impreza_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kali_impreza_i18n`;


CREATE TABLE `kali_impreza_i18n`
(
	`opis` TEXT  NOT NULL,
	`skrot` VARCHAR(255),
	`opis_grafiki_zajawki` TEXT(500),
	`id` INTEGER  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	PRIMARY KEY (`id`,`culture`),
	CONSTRAINT `kali_impreza_i18n_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `kali_impreza` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kali_impreza_zalacznik
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kali_impreza_zalacznik`;


CREATE TABLE `kali_impreza_zalacznik`
(
	`impreza_id` INTEGER  NOT NULL,
	`zalacznik_id` INTEGER  NOT NULL,
	`zalacznik_kolejnosc` INTEGER(5) default 0 NOT NULL,
	PRIMARY KEY (`impreza_id`,`zalacznik_id`),
	CONSTRAINT `kali_impreza_zalacznik_FK_1`
		FOREIGN KEY (`impreza_id`)
		REFERENCES `kali_impreza` (`id`)
		ON DELETE CASCADE,
	INDEX `kali_impreza_zalacznik_FI_2` (`zalacznik_id`),
	CONSTRAINT `kali_impreza_zalacznik_FK_2`
		FOREIGN KEY (`zalacznik_id`)
		REFERENCES `zalacznik` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kali_impreza_galeria
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kali_impreza_galeria`;


CREATE TABLE `kali_impreza_galeria`
(
	`impreza_id` INTEGER  NOT NULL,
	`galeria_id` INTEGER  NOT NULL,
	PRIMARY KEY (`impreza_id`,`galeria_id`),
	CONSTRAINT `kali_impreza_galeria_FK_1`
		FOREIGN KEY (`impreza_id`)
		REFERENCES `kali_impreza` (`id`)
		ON DELETE CASCADE,
	INDEX `kali_impreza_galeria_FI_2` (`galeria_id`),
	CONSTRAINT `kali_impreza_galeria_FK_2`
		FOREIGN KEY (`galeria_id`)
		REFERENCES `galeria_pub` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kali_impreza_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kali_impreza_pub`;


CREATE TABLE `kali_impreza_pub`
(
	`id` INTEGER(11)  NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`uzytkownik_id` INTEGER(11) default NULL,
	`nazwa` VARCHAR(255)  NOT NULL,
	`miejsce` VARCHAR(255)  NOT NULL,
	`kategoria_id` INTEGER(11)  NOT NULL,
	`organizator_id` INTEGER(11),
	`inni_organizatorzy` TEXT,
	`status_id` INTEGER(11),
	`data_rozpoczecia` DATE,
	`data_zakonczenia` DATE,
	`ilosc_dni` INTEGER(11) default 0,
	`godzina_rozpoczecia` TIME,
	`godzina_zakonczenia` TIME,
	`data_orientacyjna` TINYINT(1) default 0 NOT NULL,
	`strona_www` VARCHAR(255),
	`zglaszajacy` TEXT  NOT NULL,
	`newsletter` TINYINT(1) default 1 NOT NULL,
	`aktywna` TINYINT(1) default 1 NOT NULL,
	`zatwierdzona` TINYINT(1) default 0 NOT NULL,
	`grafika_zajawki` VARCHAR(255),
	`zgloszona` TINYINT(1) default 0,
	`promowana` TINYINT(1) default 0,
	`loc_x` DECIMAL(19,15) default 0.000000000000000,
	`loc_y` DECIMAL(19,15) default 0.000000000000000,
	`loc_z` INTEGER(11),
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`id`),
	CONSTRAINT `kali_impreza_pub_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `kali_impreza` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `kali_impreza_pub_FI_2` (`uzytkownik_id`),
	CONSTRAINT `kali_impreza_pub_FK_2`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`),
	INDEX `kali_impreza_pub_FI_3` (`kategoria_id`),
	CONSTRAINT `kali_impreza_pub_FK_3`
		FOREIGN KEY (`kategoria_id`)
		REFERENCES `kali_kategorie` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `kali_impreza_pub_FI_4` (`organizator_id`),
	CONSTRAINT `kali_impreza_pub_FK_4`
		FOREIGN KEY (`organizator_id`)
		REFERENCES `kali_organizatorzy` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `kali_impreza_pub_FI_5` (`status_id`),
	CONSTRAINT `kali_impreza_pub_FK_5`
		FOREIGN KEY (`status_id`)
		REFERENCES `kali_status` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kali_impreza_pub_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kali_impreza_pub_i18n`;


CREATE TABLE `kali_impreza_pub_i18n`
(
	`opis` TEXT  NOT NULL,
	`skrot` VARCHAR(255),
	`opis_grafiki_zajawki` TEXT(500),
	`id` INTEGER  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	PRIMARY KEY (`id`,`culture`),
	CONSTRAINT `kali_impreza_pub_i18n_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `kali_impreza_pub` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kali_impreza_zalacznik_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kali_impreza_zalacznik_pub`;


CREATE TABLE `kali_impreza_zalacznik_pub`
(
	`impreza_id` INTEGER  NOT NULL,
	`zalacznik_id` INTEGER  NOT NULL,
	`zalacznik_kolejnosc` INTEGER(5) default 0 NOT NULL,
	PRIMARY KEY (`impreza_id`,`zalacznik_id`),
	CONSTRAINT `kali_impreza_zalacznik_pub_FK_1`
		FOREIGN KEY (`impreza_id`)
		REFERENCES `kali_impreza_pub` (`id`)
		ON DELETE CASCADE,
	INDEX `kali_impreza_zalacznik_pub_FI_2` (`zalacznik_id`),
	CONSTRAINT `kali_impreza_zalacznik_pub_FK_2`
		FOREIGN KEY (`zalacznik_id`)
		REFERENCES `zalacznik` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kali_impreza_galeria_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kali_impreza_galeria_pub`;


CREATE TABLE `kali_impreza_galeria_pub`
(
	`impreza_id` INTEGER  NOT NULL,
	`galeria_id` INTEGER  NOT NULL,
	PRIMARY KEY (`impreza_id`,`galeria_id`),
	CONSTRAINT `kali_impreza_galeria_pub_FK_1`
		FOREIGN KEY (`impreza_id`)
		REFERENCES `kali_impreza_pub` (`id`)
		ON DELETE CASCADE,
	INDEX `kali_impreza_galeria_pub_FI_2` (`galeria_id`),
	CONSTRAINT `kali_impreza_galeria_pub_FK_2`
		FOREIGN KEY (`galeria_id`)
		REFERENCES `galeria_pub` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kal_historyczne
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kal_historyczne`;


CREATE TABLE `kal_historyczne`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`updated_at` DATETIME,
	`created_at` DATETIME,
	`data` DATE default '0000-00-00' NOT NULL,
	`uzytkownik_id` INTEGER(11),
	`opublikowal` INTEGER(11),
	`aktywne` TINYINT(1) default 1 NOT NULL,
	`zatwierdzone` TINYINT(1) default 0 NOT NULL,
	`grafika_zajawki` VARCHAR(255),
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`id`),
	INDEX `kal_historyczne_FI_1` (`uzytkownik_id`),
	CONSTRAINT `kal_historyczne_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`),
	INDEX `kal_historyczne_FI_2` (`opublikowal`),
	CONSTRAINT `kal_historyczne_FK_2`
		FOREIGN KEY (`opublikowal`)
		REFERENCES `sf_guard_user` (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kal_historyczne_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kal_historyczne_i18n`;


CREATE TABLE `kal_historyczne_i18n`
(
	`nazwa` VARCHAR(255)  NOT NULL,
	`opis` TEXT  NOT NULL,
	`skrot` VARCHAR(255),
	`opis_grafiki_zajawki` TEXT(500),
	`id` INTEGER  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	PRIMARY KEY (`id`,`culture`),
	CONSTRAINT `kal_historyczne_i18n_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `kal_historyczne` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kal_historyczne_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kal_historyczne_pub`;


CREATE TABLE `kal_historyczne_pub`
(
	`id` INTEGER(11)  NOT NULL,
	`updated_at` DATETIME,
	`created_at` DATETIME,
	`data` DATE default '0000-00-00' NOT NULL,
	`uzytkownik_id` INTEGER(11),
	`opublikowal` INTEGER(11),
	`aktywne` TINYINT(1) default 1 NOT NULL,
	`zatwierdzone` TINYINT(1) default 0 NOT NULL,
	`grafika_zajawki` VARCHAR(255),
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`id`),
	CONSTRAINT `kal_historyczne_pub_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `kal_historyczne` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `kal_historyczne_pub_FI_2` (`uzytkownik_id`),
	CONSTRAINT `kal_historyczne_pub_FK_2`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`),
	INDEX `kal_historyczne_pub_FI_3` (`opublikowal`),
	CONSTRAINT `kal_historyczne_pub_FK_3`
		FOREIGN KEY (`opublikowal`)
		REFERENCES `sf_guard_user` (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kal_historyczne_pub_i18n
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kal_historyczne_pub_i18n`;


CREATE TABLE `kal_historyczne_pub_i18n`
(
	`nazwa` VARCHAR(255)  NOT NULL,
	`opis` TEXT  NOT NULL,
	`skrot` VARCHAR(255),
	`opis_grafiki_zajawki` TEXT(500),
	`id` INTEGER  NOT NULL,
	`culture` VARCHAR(7)  NOT NULL,
	PRIMARY KEY (`id`,`culture`),
	CONSTRAINT `kal_historyczne_pub_i18n_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `kal_historyczne_pub` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- imieniny
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `imieniny`;


CREATE TABLE `imieniny`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`dzien` INTEGER(2) default 0 NOT NULL,
	`miesiac` INTEGER(2) default 0 NOT NULL,
	`imiona` VARCHAR(255)  NOT NULL,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- newsletter_users
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `newsletter_users`;


CREATE TABLE `newsletter_users`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`uzytkownik_id` INTEGER(11),
	`email` VARCHAR(255)  NOT NULL,
	`aktywny` TINYINT(1) default 0,
	`suma_kontrolna` VARCHAR(255)  NOT NULL,
	PRIMARY KEY (`id`),
	UNIQUE KEY `suma_kontrolna` (`suma_kontrolna`),
	UNIQUE KEY `email` (`email`),
	INDEX `newsletter_users_FI_1` (`uzytkownik_id`),
	CONSTRAINT `newsletter_users_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- newsletter_users_groups
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `newsletter_users_groups`;


CREATE TABLE `newsletter_users_groups`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`nazwa` VARCHAR(255)  NOT NULL,
	PRIMARY KEY (`id`),
	UNIQUE KEY `nazwa` (`nazwa`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- newsletter_users_groups_map
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `newsletter_users_groups_map`;


CREATE TABLE `newsletter_users_groups_map`
(
	`newsletter_user_id` INTEGER(11)  NOT NULL,
	`group_id` INTEGER  NOT NULL,
	PRIMARY KEY (`newsletter_user_id`,`group_id`),
	CONSTRAINT `newsletter_users_groups_map_FK_1`
		FOREIGN KEY (`newsletter_user_id`)
		REFERENCES `newsletter_users` (`id`)
		ON DELETE CASCADE,
	INDEX `newsletter_users_groups_map_FI_2` (`group_id`),
	CONSTRAINT `newsletter_users_groups_map_FK_2`
		FOREIGN KEY (`group_id`)
		REFERENCES `newsletter_users_groups` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- newsletter_users_akategorie
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `newsletter_users_akategorie`;


CREATE TABLE `newsletter_users_akategorie`
(
	`newsletter_user_id` INTEGER(11)  NOT NULL,
	`kategoria_id` INTEGER  NOT NULL,
	PRIMARY KEY (`newsletter_user_id`,`kategoria_id`),
	CONSTRAINT `newsletter_users_akategorie_FK_1`
		FOREIGN KEY (`newsletter_user_id`)
		REFERENCES `newsletter_users` (`id`)
		ON DELETE CASCADE,
	INDEX `newsletter_users_akategorie_FI_2` (`kategoria_id`),
	CONSTRAINT `newsletter_users_akategorie_FK_2`
		FOREIGN KEY (`kategoria_id`)
		REFERENCES `aktualnosc_kategoria` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- newsletter_users_kali_kategorie
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `newsletter_users_kali_kategorie`;


CREATE TABLE `newsletter_users_kali_kategorie`
(
	`newsletter_user_id` INTEGER(11)  NOT NULL,
	`kategoria_id` INTEGER  NOT NULL,
	PRIMARY KEY (`newsletter_user_id`,`kategoria_id`),
	CONSTRAINT `newsletter_users_kali_kategorie_FK_1`
		FOREIGN KEY (`newsletter_user_id`)
		REFERENCES `newsletter_users` (`id`)
		ON DELETE CASCADE,
	INDEX `newsletter_users_kali_kategorie_FI_2` (`kategoria_id`),
	CONSTRAINT `newsletter_users_kali_kategorie_FK_2`
		FOREIGN KEY (`kategoria_id`)
		REFERENCES `kali_kategorie` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- newsletter_messages
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `newsletter_messages`;


CREATE TABLE `newsletter_messages`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`temat` VARCHAR(255)  NOT NULL,
	`tresc` TEXT  NOT NULL,
	`do_wyslania` TINYINT(1) default 1,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- newsletter_messages_groups
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `newsletter_messages_groups`;


CREATE TABLE `newsletter_messages_groups`
(
	`message_id` INTEGER(11)  NOT NULL,
	`group_id` INTEGER  NOT NULL,
	PRIMARY KEY (`message_id`,`group_id`),
	CONSTRAINT `newsletter_messages_groups_FK_1`
		FOREIGN KEY (`message_id`)
		REFERENCES `newsletter_messages` (`id`)
		ON DELETE CASCADE,
	INDEX `newsletter_messages_groups_FI_2` (`group_id`),
	CONSTRAINT `newsletter_messages_groups_FK_2`
		FOREIGN KEY (`group_id`)
		REFERENCES `newsletter_users_groups` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- newsletter_
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `newsletter_`;


CREATE TABLE `newsletter_`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`aktualnosc_id` INTEGER(11),
	`impreza_id` INTEGER(11),
	`wyslana` TINYINT(1) default 0 NOT NULL,
	`do_wysylki` TINYINT(1) default 1,
	PRIMARY KEY (`id`),
	INDEX `newsletter__FI_1` (`aktualnosc_id`),
	CONSTRAINT `newsletter__FK_1`
		FOREIGN KEY (`aktualnosc_id`)
		REFERENCES `aktualnosc` (`id`)
		ON DELETE CASCADE,
	INDEX `newsletter__FI_2` (`impreza_id`),
	CONSTRAINT `newsletter__FK_2`
		FOREIGN KEY (`impreza_id`)
		REFERENCES `kali_impreza` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- epublikacje
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `epublikacje`;


CREATE TABLE `epublikacje`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`publikacja` DATETIME,
	`zatwierdzone` TINYINT(1) default 0 NOT NULL,
	`user_id` INTEGER,
	`wytworzyl` VARCHAR(255)  NOT NULL,
	`naglowek` VARCHAR(255)  NOT NULL,
	`opis` TEXT  NOT NULL,
	`tresc` VARCHAR(255)  NOT NULL,
	`zdjecie` VARCHAR(255)  NOT NULL,
	`kategoria` INTEGER(11)  NOT NULL,
	`keywords` TEXT,
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`id`),
	INDEX `epublikacje_FI_1` (`user_id`),
	CONSTRAINT `epublikacje_FK_1`
		FOREIGN KEY (`user_id`)
		REFERENCES `sf_guard_user` (`id`)
		ON DELETE CASCADE,
	INDEX `epublikacje_FI_2` (`kategoria`),
	CONSTRAINT `epublikacje_FK_2`
		FOREIGN KEY (`kategoria`)
		REFERENCES `epublikacje_kategoria` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- epublikacje_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `epublikacje_pub`;


CREATE TABLE `epublikacje_pub`
(
	`id` INTEGER(11)  NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`publikacja` DATETIME,
	`user_id` INTEGER,
	`wytworzyl` VARCHAR(255)  NOT NULL,
	`naglowek` VARCHAR(255)  NOT NULL,
	`opis` TEXT  NOT NULL,
	`tresc` VARCHAR(255)  NOT NULL,
	`zdjecie` VARCHAR(255)  NOT NULL,
	`kategoria` INTEGER(11)  NOT NULL,
	`keywords` TEXT,
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`id`),
	CONSTRAINT `epublikacje_pub_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `epublikacje` (`id`)
		ON DELETE CASCADE,
	INDEX `epublikacje_pub_FI_2` (`user_id`),
	CONSTRAINT `epublikacje_pub_FK_2`
		FOREIGN KEY (`user_id`)
		REFERENCES `sf_guard_user` (`id`)
		ON DELETE CASCADE,
	INDEX `epublikacje_pub_FI_3` (`kategoria`),
	CONSTRAINT `epublikacje_pub_FK_3`
		FOREIGN KEY (`kategoria`)
		REFERENCES `epublikacje_kategoria` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- epublikacje_zalaczniki
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `epublikacje_zalaczniki`;


CREATE TABLE `epublikacje_zalaczniki`
(
	`epublikacje_id` INTEGER  NOT NULL,
	`zalacznik_id` INTEGER  NOT NULL,
	`zalacznik_kolejnosc` INTEGER(5) default 0,
	PRIMARY KEY (`epublikacje_id`,`zalacznik_id`),
	CONSTRAINT `epublikacje_zalaczniki_FK_1`
		FOREIGN KEY (`epublikacje_id`)
		REFERENCES `epublikacje` (`id`)
		ON DELETE CASCADE,
	INDEX `epublikacje_zalaczniki_FI_2` (`zalacznik_id`),
	CONSTRAINT `epublikacje_zalaczniki_FK_2`
		FOREIGN KEY (`zalacznik_id`)
		REFERENCES `zalacznik` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- epublikacje_zalaczniki_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `epublikacje_zalaczniki_pub`;


CREATE TABLE `epublikacje_zalaczniki_pub`
(
	`epublikacje_id` INTEGER  NOT NULL,
	`zalacznik_id` INTEGER  NOT NULL,
	`zalacznik_kolejnosc` INTEGER(5) default 0,
	PRIMARY KEY (`epublikacje_id`,`zalacznik_id`),
	CONSTRAINT `epublikacje_zalaczniki_pub_FK_1`
		FOREIGN KEY (`epublikacje_id`)
		REFERENCES `epublikacje_pub` (`id`)
		ON DELETE CASCADE,
	INDEX `epublikacje_zalaczniki_pub_FI_2` (`zalacznik_id`),
	CONSTRAINT `epublikacje_zalaczniki_pub_FK_2`
		FOREIGN KEY (`zalacznik_id`)
		REFERENCES `zalacznik` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- epublikacje_kategoria
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `epublikacje_kategoria`;


CREATE TABLE `epublikacje_kategoria`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`nazwa` VARCHAR(100)  NOT NULL,
	`kolejnosc` INTEGER(10) default 0,
	PRIMARY KEY (`id`),
	UNIQUE KEY `epublikacje_kategoria_U_1` (`nazwa`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kontakt_adresaci
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kontakt_adresaci`;


CREATE TABLE `kontakt_adresaci`
(
	`id` INTEGER(10)  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`nazwa` VARCHAR(255) default '' NOT NULL,
	`osoba` VARCHAR(255) default '',
	`ulica` VARCHAR(255) default '',
	`numer` VARCHAR(10) default '',
	`kod` VARCHAR(6) default '',
	`miejscowosc` VARCHAR(255) default '',
	`email` VARCHAR(255) default '' NOT NULL,
	`telefon` VARCHAR(20) default '',
	`uwagi` TEXT,
	`aktywne` TINYINT(1) default 1,
	`potwierdzenie` TEXT,
	`email_wymagany` TINYINT(1) default 0 NOT NULL,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- kontakt_ustawienia
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `kontakt_ustawienia`;


CREATE TABLE `kontakt_ustawienia`
(
	`opcja` VARCHAR(255)  NOT NULL,
	`wartosc` VARCHAR(255),
	PRIMARY KEY (`opcja`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- zgloszenia
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `zgloszenia`;


CREATE TABLE `zgloszenia`
(
	`id` INTEGER(10)  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`adresat` INTEGER(10)  NOT NULL,
	`tytul` VARCHAR(255) default '',
	`tresc` TEXT  NOT NULL,
	`osoba` VARCHAR(255) default '',
	`email` VARCHAR(255) default '',
	`telefon` VARCHAR(15) default '',
	`zalacznik` VARCHAR(255) default '',
	`ip` VARCHAR(39) default '' NOT NULL,
	`referer` VARCHAR(255) default '',
	`lat` VARCHAR(255) default '',
	`lng` VARCHAR(255) default '',
	`zoom` VARCHAR(255) default '',
	PRIMARY KEY (`id`),
	INDEX `zgloszenia_FI_1` (`adresat`),
	CONSTRAINT `zgloszenia_FK_1`
		FOREIGN KEY (`adresat`)
		REFERENCES `kontakt_adresaci` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- multimedia_kategorie
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `multimedia_kategorie`;


CREATE TABLE `multimedia_kategorie`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`nazwa` VARCHAR(255)  NOT NULL,
	`ikona` VARCHAR(255),
	`kolejnosc` INTEGER(11) default 0,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- multimedia_kategorie_tematy
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `multimedia_kategorie_tematy`;


CREATE TABLE `multimedia_kategorie_tematy`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`kategoria_id` INTEGER  NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`nazwa` VARCHAR(255)  NOT NULL,
	`ikona` VARCHAR(255),
	`kolejnosc` INTEGER(11) default 0,
	PRIMARY KEY (`id`),
	INDEX `multimedia_kategorie_tematy_FI_1` (`kategoria_id`),
	CONSTRAINT `multimedia_kategorie_tematy_FK_1`
		FOREIGN KEY (`kategoria_id`)
		REFERENCES `multimedia_kategorie` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- multimedia
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `multimedia`;


CREATE TABLE `multimedia`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`referer_id` INTEGER(11),
	`version` TINYINT(1) default 0 NOT NULL,
	`do_publikacji` TINYINT(1) default 0 NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`tryb` TINYINT(1) default 0,
	`link` TEXT,
	`code` TEXT,
	`temat_id` INTEGER  NOT NULL,
	`uzytkownik_id` INTEGER(11),
	`tytul` VARCHAR(255)  NOT NULL,
	`publikacja_od` DATETIME,
	`publikacja_do` DATETIME,
	`grafika` VARCHAR(255),
	`plik` VARCHAR(255),
	`opis` TEXT,
	`tagi` TEXT,
	`status` TINYINT(1) default 0 NOT NULL,
	`wyswietlenia` INTEGER(11),
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`id`),
	INDEX `multimedia_FI_1` (`referer_id`),
	CONSTRAINT `multimedia_FK_1`
		FOREIGN KEY (`referer_id`)
		REFERENCES `multimedia` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `multimedia_FI_2` (`temat_id`),
	CONSTRAINT `multimedia_FK_2`
		FOREIGN KEY (`temat_id`)
		REFERENCES `multimedia_kategorie_tematy` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `multimedia_FI_3` (`uzytkownik_id`),
	CONSTRAINT `multimedia_FK_3`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- multimedia_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `multimedia_pub`;


CREATE TABLE `multimedia_pub`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`do_publikacji` TINYINT(1) default 0 NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`temat_id` INTEGER  NOT NULL,
	`uzytkownik_id` INTEGER(11),
	`tytul` VARCHAR(255)  NOT NULL,
	`publikacja_od` DATETIME,
	`publikacja_do` DATETIME,
	`grafika` VARCHAR(255),
	`plik` VARCHAR(255)  NOT NULL,
	`opis` TEXT,
	`status` TINYINT(1) default 0 NOT NULL,
	PRIMARY KEY (`id`),
	CONSTRAINT `multimedia_pub_FK_1`
		FOREIGN KEY (`id`)
		REFERENCES `multimedia` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `multimedia_pub_FI_2` (`temat_id`),
	CONSTRAINT `multimedia_pub_FK_2`
		FOREIGN KEY (`temat_id`)
		REFERENCES `multimedia_kategorie_tematy` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `multimedia_pub_FI_3` (`uzytkownik_id`),
	CONSTRAINT `multimedia_pub_FK_3`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- ankiety
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `ankiety`;


CREATE TABLE `ankiety`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`do_publikacji` TINYINT(1) default 0 NOT NULL,
	`panel_boczny` TINYINT(1) default 0 NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`nazwa` VARCHAR(255)  NOT NULL,
	`publikacja_od` DATE,
	`publikacja_do` DATE,
	`kolejnosc` INTEGER,
	`culture` INTEGER default 1 NOT NULL,
	`uzytkownik_id` INTEGER(11),
	PRIMARY KEY (`id`),
	KEY `ankiety_FI_1`(`uzytkownik_id`),
	CONSTRAINT `ankiety_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- ankiety_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `ankiety_pub`;


CREATE TABLE `ankiety_pub`
(
	`id` INTEGER(11)  NOT NULL,
	`panel_boczny` TINYINT(1) default 0 NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`nazwa` VARCHAR(255)  NOT NULL,
	`publikacja_od` DATE,
	`publikacja_do` DATE,
	`kolejnosc` INTEGER,
	`culture` INTEGER default 1 NOT NULL,
	`uzytkownik_id` INTEGER(11),
	PRIMARY KEY (`id`),
	KEY `ankiety_pub_FI_1`(`uzytkownik_id`),
	CONSTRAINT `ankiety_pub_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- ankiety_pytania
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `ankiety_pytania`;


CREATE TABLE `ankiety_pytania`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`ankieta_id` INTEGER(11)  NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`pytanie` TEXT  NOT NULL,
	`typ` INTEGER  NOT NULL,
	`kolejnosc` INTEGER,
	PRIMARY KEY (`id`),
	INDEX `ankiety_pytania_FI_1` (`ankieta_id`),
	CONSTRAINT `ankiety_pytania_FK_1`
		FOREIGN KEY (`ankieta_id`)
		REFERENCES `ankiety` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- ankiety_pytania_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `ankiety_pytania_pub`;


CREATE TABLE `ankiety_pytania_pub`
(
	`id` INTEGER(11)  NOT NULL,
	`ankieta_id` INTEGER(11)  NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`pytanie` TEXT  NOT NULL,
	`typ` INTEGER  NOT NULL,
	`kolejnosc` INTEGER,
	PRIMARY KEY (`id`),
	INDEX `ankiety_pytania_pub_FI_1` (`ankieta_id`),
	CONSTRAINT `ankiety_pytania_pub_FK_1`
		FOREIGN KEY (`ankieta_id`)
		REFERENCES `ankiety_pub` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- ankiety_odpowiedzi
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `ankiety_odpowiedzi`;


CREATE TABLE `ankiety_odpowiedzi`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`ankieta_id` INTEGER(11)  NOT NULL,
	`pytanie_id` INTEGER(11)  NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`odpowiedz` TEXT,
	`glosy` INTEGER,
	`kolejnosc` INTEGER,
	PRIMARY KEY (`id`),
	INDEX `ankiety_odpowiedzi_FI_1` (`ankieta_id`),
	CONSTRAINT `ankiety_odpowiedzi_FK_1`
		FOREIGN KEY (`ankieta_id`)
		REFERENCES `ankiety` (`id`)
		ON DELETE CASCADE,
	INDEX `ankiety_odpowiedzi_FI_2` (`pytanie_id`),
	CONSTRAINT `ankiety_odpowiedzi_FK_2`
		FOREIGN KEY (`pytanie_id`)
		REFERENCES `ankiety_pytania` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- ankiety_odpowiedzi_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `ankiety_odpowiedzi_pub`;


CREATE TABLE `ankiety_odpowiedzi_pub`
(
	`id` INTEGER(11)  NOT NULL,
	`ankieta_id` INTEGER(11)  NOT NULL,
	`pytanie_id` INTEGER(11)  NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`odpowiedz` TEXT,
	`glosy` INTEGER,
	`kolejnosc` INTEGER,
	PRIMARY KEY (`id`),
	INDEX `ankiety_odpowiedzi_pub_FI_1` (`ankieta_id`),
	CONSTRAINT `ankiety_odpowiedzi_pub_FK_1`
		FOREIGN KEY (`ankieta_id`)
		REFERENCES `ankiety_pub` (`id`)
		ON DELETE CASCADE,
	INDEX `ankiety_odpowiedzi_pub_FI_2` (`pytanie_id`),
	CONSTRAINT `ankiety_odpowiedzi_pub_FK_2`
		FOREIGN KEY (`pytanie_id`)
		REFERENCES `ankiety_pytania_pub` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- ankiety_odpowiedzi_otwarte
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `ankiety_odpowiedzi_otwarte`;


CREATE TABLE `ankiety_odpowiedzi_otwarte`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`ankieta_id` INTEGER(11)  NOT NULL,
	`pytanie_id` INTEGER(11)  NOT NULL,
	`created_at` DATETIME,
	`odpowiedz` TEXT,
	PRIMARY KEY (`id`),
	INDEX `ankiety_odpowiedzi_otwarte_FI_1` (`ankieta_id`),
	CONSTRAINT `ankiety_odpowiedzi_otwarte_FK_1`
		FOREIGN KEY (`ankieta_id`)
		REFERENCES `ankiety_pub` (`id`)
		ON DELETE CASCADE,
	INDEX `ankiety_odpowiedzi_otwarte_FI_2` (`pytanie_id`),
	CONSTRAINT `ankiety_odpowiedzi_otwarte_FK_2`
		FOREIGN KEY (`pytanie_id`)
		REFERENCES `ankiety_pytania_pub` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- mion
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `mion`;


CREATE TABLE `mion`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`identyfikator` VARCHAR(11),
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`temat` VARCHAR(255)  NOT NULL,
	`zajawka` TEXT,
	`grafika` VARCHAR(255),
	`tresc` TEXT  NOT NULL,
	`stan_prawny` DATE,
	`wiek1` TINYINT(1) default 0,
	`wiek2` TINYINT(1) default 0,
	`wiek3` TINYINT(1) default 0,
	`wiek4` TINYINT(1) default 0,
	`wiek5` TINYINT(1) default 0,
	`np_lekki` TINYINT(1) default 0,
	`np_umiarkowany` TINYINT(1) default 0,
	`np_znaczny` TINYINT(1) default 0,
	`przyczyna_wzrok` TINYINT(1) default 0,
	`przyczyna_mowa` TINYINT(1) default 0,
	`przyczyna_ruch` TINYINT(1) default 0,
	`przyczyna_inne` TINYINT(1) default 0,
	`zatwierdzona` TINYINT(1) default 0,
	`uzytkownik_id` INTEGER(11),
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`id`),
	INDEX `mion_FI_1` (`uzytkownik_id`),
	CONSTRAINT `mion_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- mion_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `mion_pub`;


CREATE TABLE `mion_pub`
(
	`id` INTEGER(11)  NOT NULL,
	`identyfikator` VARCHAR(11),
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`temat` VARCHAR(255)  NOT NULL,
	`zajawka` TEXT,
	`grafika` VARCHAR(255),
	`tresc` TEXT  NOT NULL,
	`stan_prawny` DATE,
	`wiek1` TINYINT(1) default 0,
	`wiek2` TINYINT(1) default 0,
	`wiek3` TINYINT(1) default 0,
	`wiek4` TINYINT(1) default 0,
	`wiek5` TINYINT(1) default 0,
	`np_lekki` TINYINT(1) default 0,
	`np_umiarkowany` TINYINT(1) default 0,
	`np_znaczny` TINYINT(1) default 0,
	`przyczyna_wzrok` TINYINT(1) default 0,
	`przyczyna_mowa` TINYINT(1) default 0,
	`przyczyna_ruch` TINYINT(1) default 0,
	`przyczyna_inne` TINYINT(1) default 0,
	`uzytkownik_id` INTEGER(11),
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`id`),
	INDEX `mion_pub_FI_1` (`uzytkownik_id`),
	CONSTRAINT `mion_pub_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- mion_zalacznik
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `mion_zalacznik`;


CREATE TABLE `mion_zalacznik`
(
	`mion_id` INTEGER  NOT NULL,
	`zalacznik_id` INTEGER  NOT NULL,
	`zalacznik_kolejnosc` INTEGER(5) default 0,
	PRIMARY KEY (`mion_id`,`zalacznik_id`),
	CONSTRAINT `mion_zalacznik_FK_1`
		FOREIGN KEY (`mion_id`)
		REFERENCES `mion` (`id`)
		ON DELETE CASCADE,
	INDEX `mion_zalacznik_FI_2` (`zalacznik_id`),
	CONSTRAINT `mion_zalacznik_FK_2`
		FOREIGN KEY (`zalacznik_id`)
		REFERENCES `zalacznik` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- mion_zalacznik_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `mion_zalacznik_pub`;


CREATE TABLE `mion_zalacznik_pub`
(
	`mion_id` INTEGER  NOT NULL,
	`zalacznik_id` INTEGER  NOT NULL,
	`zalacznik_kolejnosc` INTEGER(5) default 0,
	PRIMARY KEY (`mion_id`,`zalacznik_id`),
	CONSTRAINT `mion_zalacznik_pub_FK_1`
		FOREIGN KEY (`mion_id`)
		REFERENCES `mion_pub` (`id`)
		ON DELETE CASCADE,
	INDEX `mion_zalacznik_pub_FI_2` (`zalacznik_id`),
	CONSTRAINT `mion_zalacznik_pub_FK_2`
		FOREIGN KEY (`zalacznik_id`)
		REFERENCES `zalacznik` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- mion_kategoria
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `mion_kategoria`;


CREATE TABLE `mion_kategoria`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`nazwa` VARCHAR(150)  NOT NULL,
	`kolejnosc` INTEGER(10) default 0,
	PRIMARY KEY (`id`),
	UNIQUE KEY `mion_kategoria_U_1` (`nazwa`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- mion_kategoria_map
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `mion_kategoria_map`;


CREATE TABLE `mion_kategoria_map`
(
	`mion_id` INTEGER  NOT NULL,
	`kategoria_id` INTEGER  NOT NULL,
	PRIMARY KEY (`mion_id`,`kategoria_id`),
	CONSTRAINT `mion_kategoria_map_FK_1`
		FOREIGN KEY (`mion_id`)
		REFERENCES `mion` (`id`)
		ON DELETE CASCADE,
	INDEX `mion_kategoria_map_FI_2` (`kategoria_id`),
	CONSTRAINT `mion_kategoria_map_FK_2`
		FOREIGN KEY (`kategoria_id`)
		REFERENCES `mion_kategoria` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- mion_kategoria_map_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `mion_kategoria_map_pub`;


CREATE TABLE `mion_kategoria_map_pub`
(
	`mion_id` INTEGER  NOT NULL,
	`kategoria_id` INTEGER  NOT NULL,
	PRIMARY KEY (`mion_id`,`kategoria_id`),
	CONSTRAINT `mion_kategoria_map_pub_FK_1`
		FOREIGN KEY (`mion_id`)
		REFERENCES `mion_pub` (`id`)
		ON DELETE CASCADE,
	INDEX `mion_kategoria_map_pub_FI_2` (`kategoria_id`),
	CONSTRAINT `mion_kategoria_map_pub_FK_2`
		FOREIGN KEY (`kategoria_id`)
		REFERENCES `mion_kategoria` (`id`)
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- banery_grupy
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `banery_grupy`;


CREATE TABLE `banery_grupy`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`id_modulu` VARCHAR(4)  NOT NULL,
	`pole_banerowe` VARCHAR(50)  NOT NULL,
	`nazwa` VARCHAR(255)  NOT NULL,
	`kolejnosc` INTEGER default 10000 NOT NULL,
	`wyswietlanie` VARCHAR(10) default 'random',
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- banery_dane
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `banery_dane`;


CREATE TABLE `banery_dane`
(
	`id` INTEGER  NOT NULL AUTO_INCREMENT,
	`id_grupy` INTEGER  NOT NULL,
	`portal_id` INTEGER(11),
	`jezyk` VARCHAR(7),
	`typ` VARCHAR(10)  NOT NULL,
	`nazwa` VARCHAR(255),
	`plik_banera` VARCHAR(255),
	`skrypt_banera` VARCHAR(255),
	`skrypt_ads` TEXT,
	`hidden` TINYINT default 0,
	`link` TEXT,
	`title` VARCHAR(255),
	`target` VARCHAR(10) default '_blank',
	`data_start` DATE,
	`data_stop` DATE,
	`godzina_start` TIME,
	`godzina_stop` TIME,
	`max_views` BIGINT default 0,
	`ile_views` BIGINT default 0,
	`max_clicks` BIGINT default 0,
	`ile_clicks` BIGINT default 0,
	`kolejnosc` INTEGER default 10000 NOT NULL,
	PRIMARY KEY (`id`),
	INDEX `banery_dane_FI_1` (`id_grupy`),
	CONSTRAINT `banery_dane_FK_1`
		FOREIGN KEY (`id_grupy`)
		REFERENCES `banery_grupy` (`id`)
		ON DELETE CASCADE,
	INDEX `banery_dane_FI_2` (`portal_id`),
	CONSTRAINT `banery_dane_FK_2`
		FOREIGN KEY (`portal_id`)
		REFERENCES `portal` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- log
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `log`;


CREATE TABLE `log`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`modul_short` VARCHAR(6),
	`uzytkownik_id` INTEGER(11),
	`created_at` DATETIME,
	`tresc` TEXT  NOT NULL,
	`obiekt_nazwa` VARCHAR(255),
	`obiekt_tytul` VARCHAR(255),
	`obiekt_id` VARCHAR(255),
	PRIMARY KEY (`id`),
	INDEX `log_FI_1` (`uzytkownik_id`),
	CONSTRAINT `log_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- dokumenty_rodzaj
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `dokumenty_rodzaj`;


CREATE TABLE `dokumenty_rodzaj`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`nazwa` VARCHAR(255)  NOT NULL,
	`rodzaj_skrot` VARCHAR(20)  NOT NULL,
	`status` INTEGER default 0 NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- dokumenty_dziedzina
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `dokumenty_dziedzina`;


CREATE TABLE `dokumenty_dziedzina`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`nazwa` VARCHAR(255)  NOT NULL,
	`status` INTEGER default 0 NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	PRIMARY KEY (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- dokumenty
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `dokumenty`;


CREATE TABLE `dokumenty`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`uzytkownik_id` INTEGER(11),
	`uzytkownik_aktualizacja_id` INTEGER(11),
	`rodzaj_id` INTEGER(11)  NOT NULL,
	`nr1` VARCHAR(50),
	`nr2` VARCHAR(50),
	`nr3` VARCHAR(50),
	`rok` INTEGER(4),
	`symbol` VARCHAR(20),
	`dziedzina_id` INTEGER(11)  NOT NULL,
	`dziedzina_dodatkowa_id` INTEGER(11),
	`dokument_tytul` TEXT  NOT NULL,
	`dokument_podstawa_prawna` TEXT,
	`dokument_data_podpisania` DATE  NOT NULL,
	`dokument_data_wejscia` DATE,
	`dokument_utrata_mocy` DATE,
	`dokument_tresc` TEXT,
	`dokument_tresc_plik` VARCHAR(255),
	`dokument_tresc_plik_zawartosc` TEXT,
	`dokument_tekst_jednolity` TEXT,
	`dokument_tekst_jednolity_plik` VARCHAR(255),
	`dokument_tekst_jednolity_plik_zawartosc` TEXT,
	`slowa_kluczowe` TEXT,
	`uwagi` TEXT,
	`opis_zmiany` TEXT,
	`status` INTEGER(1) default 0 NOT NULL,
	`wersja` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`id`),
	INDEX `dokumenty_FI_1` (`uzytkownik_id`),
	CONSTRAINT `dokumenty_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`),
	INDEX `dokumenty_FI_2` (`uzytkownik_aktualizacja_id`),
	CONSTRAINT `dokumenty_FK_2`
		FOREIGN KEY (`uzytkownik_aktualizacja_id`)
		REFERENCES `sf_guard_user` (`id`),
	INDEX `dokumenty_FI_3` (`rodzaj_id`),
	CONSTRAINT `dokumenty_FK_3`
		FOREIGN KEY (`rodzaj_id`)
		REFERENCES `dokumenty_rodzaj` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `dokumenty_FI_4` (`dziedzina_id`),
	CONSTRAINT `dokumenty_FK_4`
		FOREIGN KEY (`dziedzina_id`)
		REFERENCES `dokumenty_dziedzina` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `dokumenty_FI_5` (`dziedzina_dodatkowa_id`),
	CONSTRAINT `dokumenty_FK_5`
		FOREIGN KEY (`dziedzina_dodatkowa_id`)
		REFERENCES `dokumenty_dziedzina` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- dokumenty_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `dokumenty_pub`;


CREATE TABLE `dokumenty_pub`
(
	`id` INTEGER(11)  NOT NULL,
	`uzytkownik_id` INTEGER(11),
	`uzytkownik_aktualizacja_id` INTEGER(11),
	`rodzaj_id` INTEGER(11)  NOT NULL,
	`nr1` VARCHAR(50),
	`nr2` VARCHAR(50),
	`nr3` VARCHAR(50),
	`rok` INTEGER(4),
	`symbol` VARCHAR(20),
	`dziedzina_id` INTEGER(11)  NOT NULL,
	`dziedzina_dodatkowa_id` INTEGER(11),
	`dokument_tytul` TEXT  NOT NULL,
	`dokument_podstawa_prawna` TEXT,
	`dokument_data_podpisania` DATE  NOT NULL,
	`dokument_data_wejscia` DATE,
	`dokument_utrata_mocy` DATE,
	`dokument_tresc` TEXT,
	`dokument_tresc_plik` VARCHAR(255),
	`dokument_tresc_plik_zawartosc` TEXT,
	`dokument_tekst_jednolity` TEXT,
	`dokument_tekst_jednolity_plik` VARCHAR(255),
	`dokument_tekst_jednolity_plik_zawartosc` TEXT,
	`slowa_kluczowe` TEXT,
	`uwagi` TEXT,
	`opis_zmiany` TEXT,
	`status` INTEGER(1) default 0 NOT NULL,
	`wersja` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`id`),
	INDEX `dokumenty_pub_FI_1` (`uzytkownik_id`),
	CONSTRAINT `dokumenty_pub_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`),
	INDEX `dokumenty_pub_FI_2` (`uzytkownik_aktualizacja_id`),
	CONSTRAINT `dokumenty_pub_FK_2`
		FOREIGN KEY (`uzytkownik_aktualizacja_id`)
		REFERENCES `sf_guard_user` (`id`),
	INDEX `dokumenty_pub_FI_3` (`rodzaj_id`),
	CONSTRAINT `dokumenty_pub_FK_3`
		FOREIGN KEY (`rodzaj_id`)
		REFERENCES `dokumenty_rodzaj` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `dokumenty_pub_FI_4` (`dziedzina_id`),
	CONSTRAINT `dokumenty_pub_FK_4`
		FOREIGN KEY (`dziedzina_id`)
		REFERENCES `dokumenty_dziedzina` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `dokumenty_pub_FI_5` (`dziedzina_dodatkowa_id`),
	CONSTRAINT `dokumenty_pub_FK_5`
		FOREIGN KEY (`dziedzina_dodatkowa_id`)
		REFERENCES `dokumenty_dziedzina` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- dokumenty_arch
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `dokumenty_arch`;


CREATE TABLE `dokumenty_arch`
(
	`arch_id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`id` INTEGER(11)  NOT NULL,
	`uzytkownik_id` INTEGER(11),
	`uzytkownik_aktualizacja_id` INTEGER(11),
	`rodzaj_id` INTEGER(11)  NOT NULL,
	`nr1` VARCHAR(50),
	`nr2` VARCHAR(50),
	`nr3` VARCHAR(50),
	`rok` INTEGER(4),
	`symbol` VARCHAR(20),
	`dziedzina_id` INTEGER(11)  NOT NULL,
	`dziedzina_dodatkowa_id` INTEGER(11),
	`dokument_tytul` TEXT  NOT NULL,
	`dokument_podstawa_prawna` TEXT,
	`dokument_data_podpisania` DATE  NOT NULL,
	`dokument_data_wejscia` DATE,
	`dokument_utrata_mocy` DATE,
	`dokument_tresc` TEXT,
	`dokument_tresc_plik` VARCHAR(255),
	`dokument_tresc_plik_zawartosc` TEXT,
	`dokument_tekst_jednolity` TEXT,
	`dokument_tekst_jednolity_plik` VARCHAR(255),
	`dokument_tekst_jednolity_plik_zawartosc` TEXT,
	`slowa_kluczowe` TEXT,
	`uwagi` TEXT,
	`opis_zmiany` TEXT,
	`status` INTEGER(1) default 0 NOT NULL,
	`wersja` INTEGER(11) default 0 NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`komentarz` TINYINT(1) default 1,
	PRIMARY KEY (`arch_id`),
	INDEX `dokumenty_arch_FI_1` (`uzytkownik_id`),
	CONSTRAINT `dokumenty_arch_FK_1`
		FOREIGN KEY (`uzytkownik_id`)
		REFERENCES `sf_guard_user` (`id`),
	INDEX `dokumenty_arch_FI_2` (`uzytkownik_aktualizacja_id`),
	CONSTRAINT `dokumenty_arch_FK_2`
		FOREIGN KEY (`uzytkownik_aktualizacja_id`)
		REFERENCES `sf_guard_user` (`id`),
	INDEX `dokumenty_arch_FI_3` (`rodzaj_id`),
	CONSTRAINT `dokumenty_arch_FK_3`
		FOREIGN KEY (`rodzaj_id`)
		REFERENCES `dokumenty_rodzaj` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `dokumenty_arch_FI_4` (`dziedzina_id`),
	CONSTRAINT `dokumenty_arch_FK_4`
		FOREIGN KEY (`dziedzina_id`)
		REFERENCES `dokumenty_dziedzina` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `dokumenty_arch_FI_5` (`dziedzina_dodatkowa_id`),
	CONSTRAINT `dokumenty_arch_FK_5`
		FOREIGN KEY (`dziedzina_dodatkowa_id`)
		REFERENCES `dokumenty_dziedzina` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- dokumenty_nowelizacje
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `dokumenty_nowelizacje`;


CREATE TABLE `dokumenty_nowelizacje`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`dokument_id` INTEGER(11)  NOT NULL,
	`dokument_nowelizowany_id` INTEGER(11)  NOT NULL,
	PRIMARY KEY (`id`),
	INDEX `dokumenty_nowelizacje_FI_1` (`dokument_id`),
	CONSTRAINT `dokumenty_nowelizacje_FK_1`
		FOREIGN KEY (`dokument_id`)
		REFERENCES `dokumenty` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `dokumenty_nowelizacje_FI_2` (`dokument_nowelizowany_id`),
	CONSTRAINT `dokumenty_nowelizacje_FK_2`
		FOREIGN KEY (`dokument_nowelizowany_id`)
		REFERENCES `dokumenty` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- dokumenty_nowelizacje_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `dokumenty_nowelizacje_pub`;


CREATE TABLE `dokumenty_nowelizacje_pub`
(
	`id` INTEGER(11)  NOT NULL,
	`dokument_id` INTEGER(11)  NOT NULL,
	`dokument_nowelizowany_id` INTEGER(11)  NOT NULL,
	PRIMARY KEY (`id`),
	INDEX `dokumenty_nowelizacje_pub_FI_1` (`dokument_id`),
	CONSTRAINT `dokumenty_nowelizacje_pub_FK_1`
		FOREIGN KEY (`dokument_id`)
		REFERENCES `dokumenty_pub` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE,
	INDEX `dokumenty_nowelizacje_pub_FI_2` (`dokument_nowelizowany_id`),
	CONSTRAINT `dokumenty_nowelizacje_pub_FK_2`
		FOREIGN KEY (`dokument_nowelizowany_id`)
		REFERENCES `dokumenty_pub` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- dokumenty_zalaczniki
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `dokumenty_zalaczniki`;


CREATE TABLE `dokumenty_zalaczniki`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`dokument_id` INTEGER(11)  NOT NULL,
	`zalacznik_nazwa` VARCHAR(255),
	`zalacznik_plik` VARCHAR(255)  NOT NULL,
	`zalacznik_plik_opis` TEXT,
	`zalacznik_zawartosc` TEXT,
	`zalacznik_kolejnosc` INTEGER(11),
	PRIMARY KEY (`id`),
	INDEX `dokumenty_zalaczniki_FI_1` (`dokument_id`),
	CONSTRAINT `dokumenty_zalaczniki_FK_1`
		FOREIGN KEY (`dokument_id`)
		REFERENCES `dokumenty` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- dokumenty_zalaczniki_pub
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `dokumenty_zalaczniki_pub`;


CREATE TABLE `dokumenty_zalaczniki_pub`
(
	`id` INTEGER(11)  NOT NULL,
	`dokument_id` INTEGER(11)  NOT NULL,
	`zalacznik_nazwa` VARCHAR(255),
	`zalacznik_plik` VARCHAR(255)  NOT NULL,
	`zalacznik_plik_opis` TEXT,
	`zalacznik_zawartosc` TEXT,
	`zalacznik_kolejnosc` INTEGER(11),
	PRIMARY KEY (`id`),
	INDEX `dokumenty_zalaczniki_pub_FI_1` (`dokument_id`),
	CONSTRAINT `dokumenty_zalaczniki_pub_FK_1`
		FOREIGN KEY (`dokument_id`)
		REFERENCES `dokumenty_pub` (`id`)
		ON UPDATE CASCADE
		ON DELETE CASCADE
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- comments
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `comments`;


CREATE TABLE `comments`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`object_id` INTEGER(11)  NOT NULL,
	`module_short` VARCHAR(4)  NOT NULL,
	`created_at` DATETIME,
	`updated_at` DATETIME,
	`status` INTEGER(11) default 0 NOT NULL,
	`parent` INTEGER(11),
	`ip` VARCHAR(255),
	`nick` VARCHAR(255)  NOT NULL,
	`email` VARCHAR(255),
	`text` TEXT(500)  NOT NULL,
	`rating` INTEGER(11) default 0,
	PRIMARY KEY (`id`),
	INDEX `comments_FI_1` (`module_short`),
	CONSTRAINT `comments_FK_1`
		FOREIGN KEY (`module_short`)
		REFERENCES `modul` (`short`)
		ON DELETE CASCADE,
	INDEX `comments_FI_2` (`parent`),
	CONSTRAINT `comments_FK_2`
		FOREIGN KEY (`parent`)
		REFERENCES `comments` (`id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- outher_services
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `outher_services`;


CREATE TABLE `outher_services`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`service_name` VARCHAR(255)  NOT NULL,
	`object_name` VARCHAR(255),
	`object_id` INTEGER(11),
	`outher_id` VARCHAR(255),
	`outher_cat` VARCHAR(255),
	`outher_url` TEXT,
	`outher_status` VARCHAR(255),
	PRIMARY KEY (`id`),
	KEY `outher_services_I_1`(`object_id`)
)Engine=InnoDB;

#-----------------------------------------------------------------------------
#-- gtranslate
#-----------------------------------------------------------------------------

DROP TABLE IF EXISTS `gtranslate`;


CREATE TABLE `gtranslate`
(
	`id` INTEGER(11)  NOT NULL AUTO_INCREMENT,
	`pl` VARCHAR(255),
	`en` VARCHAR(255),
	`de` VARCHAR(255),
	`ru` VARCHAR(255),
	`fr` VARCHAR(255),
	PRIMARY KEY (`id`),
	KEY `pl`(`pl`),
	KEY `en`(`en`),
	KEY `de`(`de`),
	KEY `ru`(`ru`),
	KEY `fr`(`fr`)
)Engine=InnoDB;

# This restores the fkey checks, after having unset them earlier
SET FOREIGN_KEY_CHECKS = 1;
