
-----------------------------------------------------------------------------
-- category
-----------------------------------------------------------------------------

DROP TABLE "category" CASCADE;


CREATE TABLE "category"
(
	"id" serial  NOT NULL,
	"category_id" INTEGER,
	"created_at" TIMESTAMP,
	"updated_at" TIMESTAMP,
	"category_id_path" VARCHAR(255),
	"tree_level" INT2,
	"category_sort" INT2,
	"name_pl" VARCHAR(128),
	"name_en" VARCHAR(128),
	"name_de" VARCHAR(128),
	"name_ru" VARCHAR(128),
	"description_pl" TEXT,
	"description_en" TEXT,
	"description_de" TEXT,
	"description_ru" TEXT,
	"mobile_description_pl" TEXT,
	"mobile_description_en" TEXT,
	"mobile_description_de" TEXT,
	"mobile_description_ru" TEXT,
	"active_pl" BOOLEAN default 'f',
	"active_en" BOOLEAN default 'f',
	"active_de" BOOLEAN default 'f',
	"active_ru" BOOLEAN default 'f',
	"vertical_position" BOOLEAN default 'f',
	"mobile" BOOLEAN default 'f' NOT NULL,
	"name_es" VARCHAR(128),
	"description_es" TEXT,
	"mobile_description_es" TEXT,
	"active_es" BOOLEAN default 'f',
	PRIMARY KEY ("id")
);

COMMENT ON TABLE "category" IS '';


SET search_path TO public;
-----------------------------------------------------------------------------
-- complaint
-----------------------------------------------------------------------------

DROP TABLE "complaint" CASCADE;


CREATE TABLE "complaint"
(
	"id" serial  NOT NULL,
	"product_name" VARCHAR(255)  NOT NULL,
	"guarantee_card_number" VARCHAR(255)  NOT NULL,
	"serial_number" VARCHAR(255)  NOT NULL,
	"invoice_number" VARCHAR(255)  NOT NULL,
	"from_day" DATE  NOT NULL,
	"invoice_date" DATE  NOT NULL,
	"person_name" VARCHAR(100)  NOT NULL,
	"person_surname" VARCHAR(100)  NOT NULL,
	"person_position" VARCHAR(255)  NOT NULL,
	"person_phone" VARCHAR(30)  NOT NULL,
	"person_address" VARCHAR(255)  NOT NULL,
	"remark" TEXT  NOT NULL,
	"cur_date" DATE  NOT NULL,
	"place" VARCHAR(255)  NOT NULL,
	PRIMARY KEY ("id")
);

COMMENT ON TABLE "complaint" IS '';


SET search_path TO public;
-----------------------------------------------------------------------------
-- product
-----------------------------------------------------------------------------

DROP TABLE "product" CASCADE;


CREATE TABLE "product"
(
	"id" serial  NOT NULL,
	"category_id" INTEGER,
	"created_at" TIMESTAMP,
	"updated_at" TIMESTAMP,
	"rank" INTEGER,
	"serial" VARCHAR(16),
	"dimension_pl" TEXT,
	"dimension_en" TEXT,
	"dimension_de" TEXT,
	"dimension_ru" TEXT,
	"name_pl" VARCHAR(128),
	"name_en" VARCHAR(128),
	"name_de" VARCHAR(128),
	"name_ru" VARCHAR(128),
	"description_pl" TEXT,
	"description_en" TEXT,
	"description_de" TEXT,
	"description_ru" TEXT,
	"short_description_pl" TEXT,
	"short_description_en" TEXT,
	"short_description_de" TEXT,
	"short_description_ru" TEXT,
	"active_pl" BOOLEAN default 'f',
	"active_en" BOOLEAN default 'f',
	"active_de" BOOLEAN default 'f',
	"active_ru" BOOLEAN default 'f',
	"mobile_description_pl" TEXT,
	"mobile_description_en" TEXT,
	"mobile_description_de" TEXT,
	"mobile_description_ru" TEXT,
	"vertical_position" BOOLEAN default 'f',
	"mobile" BOOLEAN default 'f' NOT NULL,
	"dimension_es" TEXT,
	"name_es" VARCHAR(128),
	"description_es" TEXT,
	"short_description_es" TEXT,
	"active_es" BOOLEAN default 'f',
	"mobile_description_es" TEXT,
	PRIMARY KEY ("id")
);

COMMENT ON TABLE "product" IS '';


SET search_path TO public;
-----------------------------------------------------------------------------
-- promotion
-----------------------------------------------------------------------------

DROP TABLE "promotion" CASCADE;


CREATE TABLE "promotion"
(
	"id" serial  NOT NULL,
	"name_pl" VARCHAR(128),
	"name_en" VARCHAR(128),
	"name_de" VARCHAR(128),
	"name_ru" VARCHAR(128),
	"created_at" TIMESTAMP,
	"updated_at" TIMESTAMP,
	"start_date" DATE,
	"end_date" DATE,
	"active_pl" BOOLEAN default 'f',
	"active_en" BOOLEAN default 'f',
	"active_de" BOOLEAN default 'f',
	"active_ru" BOOLEAN default 'f',
	"name_es" VARCHAR(128),
	"active_es" BOOLEAN default 'f',
	PRIMARY KEY ("id")
);

COMMENT ON TABLE "promotion" IS '';


SET search_path TO public;
-----------------------------------------------------------------------------
-- product_promotion
-----------------------------------------------------------------------------

DROP TABLE "product_promotion" CASCADE;


CREATE TABLE "product_promotion"
(
	"promotion_id" INTEGER  NOT NULL,
	"product_id" INTEGER  NOT NULL,
	PRIMARY KEY ("promotion_id","product_id")
);

COMMENT ON TABLE "product_promotion" IS '';


SET search_path TO public;
-----------------------------------------------------------------------------
-- product_image
-----------------------------------------------------------------------------

DROP TABLE "product_image" CASCADE;


CREATE TABLE "product_image"
(
	"id" serial  NOT NULL,
	"product_id" INTEGER  NOT NULL,
	"photo" VARCHAR(250),
	"thumb" VARCHAR(250),
	"rank" INTEGER,
	"created_at" TIMESTAMP,
	"description_pl" TEXT,
	"description_en" TEXT,
	"description_de" TEXT,
	"description_ru" TEXT,
	"description_es" TEXT,
	PRIMARY KEY ("id")
);

COMMENT ON TABLE "product_image" IS '';


SET search_path TO public;
-----------------------------------------------------------------------------
-- contact
-----------------------------------------------------------------------------

DROP TABLE "contact" CASCADE;


CREATE TABLE "contact"
(
	"id" serial  NOT NULL,
	"name_pl" VARCHAR(50),
	"name_en" VARCHAR(50),
	"name_de" VARCHAR(50),
	"name_ru" VARCHAR(50),
	"description" TEXT,
	"continent" VARCHAR(50)  NOT NULL,
	"name_es" VARCHAR(50),
	PRIMARY KEY ("id")
);

COMMENT ON TABLE "contact" IS '';


SET search_path TO public;
-----------------------------------------------------------------------------
-- past_projects
-----------------------------------------------------------------------------

DROP TABLE "past_projects" CASCADE;


CREATE TABLE "past_projects"
(
	"id" serial  NOT NULL,
	"title" VARCHAR(255),
	"google_link" TEXT,
	"active" BOOLEAN default 'f',
	"category_id" INTEGER  NOT NULL,
	"description_pl" TEXT,
	"description_en" TEXT,
	"description_de" TEXT,
	"description_ru" TEXT,
	"description_es" TEXT,
	PRIMARY KEY ("id")
);

COMMENT ON TABLE "past_projects" IS '';


SET search_path TO public;
-----------------------------------------------------------------------------
-- past_project_image
-----------------------------------------------------------------------------

DROP TABLE "past_project_image" CASCADE;


CREATE TABLE "past_project_image"
(
	"id" serial  NOT NULL,
	"past_project_id" INTEGER  NOT NULL,
	"photo" VARCHAR(250),
	"thumb" VARCHAR(250),
	"rank" INTEGER,
	"created_at" TIMESTAMP,
	"description_pl" TEXT,
	"description_en" TEXT,
	"description_de" TEXT,
	"description_ru" TEXT,
	"description_es" TEXT,
	PRIMARY KEY ("id")
);

COMMENT ON TABLE "past_project_image" IS '';


SET search_path TO public;
-----------------------------------------------------------------------------
-- label_storage
-----------------------------------------------------------------------------

DROP TABLE "label_storage" CASCADE;


CREATE TABLE "label_storage"
(
	"id" serial  NOT NULL,
	"label" VARCHAR(250),
	"name_pl" VARCHAR(250),
	"name_en" VARCHAR(250),
	"name_de" VARCHAR(250),
	"name_ru" VARCHAR(250),
	"name_es" VARCHAR(250),
	PRIMARY KEY ("id")
);

COMMENT ON TABLE "label_storage" IS '';


SET search_path TO public;
-----------------------------------------------------------------------------
-- static_pages
-----------------------------------------------------------------------------

DROP TABLE "static_pages" CASCADE;


CREATE TABLE "static_pages"
(
	"id" serial  NOT NULL,
	"name_pl" VARCHAR(128),
	"name_en" VARCHAR(128),
	"name_de" VARCHAR(128),
	"name_ru" VARCHAR(128),
	"description_pl" TEXT,
	"description_en" TEXT,
	"description_de" TEXT,
	"description_ru" TEXT,
	"name_es" VARCHAR(128),
	"description_es" TEXT,
	PRIMARY KEY ("id")
);

COMMENT ON TABLE "static_pages" IS '';


SET search_path TO public;
-----------------------------------------------------------------------------
-- language
-----------------------------------------------------------------------------

DROP TABLE "language" CASCADE;


CREATE TABLE "language"
(
	"id" serial  NOT NULL,
	"name" VARCHAR(250)  NOT NULL,
	"short" VARCHAR(2)  NOT NULL,
	"code" VARCHAR(5)  NOT NULL,
	PRIMARY KEY ("id")
);

COMMENT ON TABLE "language" IS '';


SET search_path TO public;
-----------------------------------------------------------------------------
-- news
-----------------------------------------------------------------------------

DROP TABLE "news" CASCADE;


CREATE TABLE "news"
(
	"id" serial  NOT NULL,
	"title_pl" VARCHAR(255),
	"title_en" VARCHAR(255),
	"title_de" VARCHAR(255),
	"title_ru" VARCHAR(255),
	"description_pl" TEXT,
	"description_en" TEXT,
	"description_de" TEXT,
	"description_ru" TEXT,
	"active_pl" BOOLEAN default 't',
	"active_en" BOOLEAN default 't',
	"active_de" BOOLEAN default 't',
	"active_ru" BOOLEAN default 't',
	"more_url" VARCHAR(255),
	"start_date" DATE,
	"end_date" DATE,
	"created_at" TIMESTAMP,
	"files" TEXT,
	"title_es" VARCHAR(255),
	"description_es" TEXT,
	"active_es" BOOLEAN default 't',
	"abstract_pl" TEXT,
	"abstract_en" TEXT,
	"abstract_de" TEXT,
	"abstract_ru" TEXT,
	"abstract_es" TEXT,
	PRIMARY KEY ("id")
);

COMMENT ON TABLE "news" IS '';


SET search_path TO public;
-----------------------------------------------------------------------------
-- news_photo
-----------------------------------------------------------------------------

DROP TABLE "news_photo" CASCADE;


CREATE TABLE "news_photo"
(
	"id" serial(11)  NOT NULL,
	"news_id" INTEGER(11)  NOT NULL,
	"photo" VARCHAR(255),
	"description_pl" TEXT,
	"description_en" TEXT,
	"description_de" TEXT,
	"description_ru" TEXT,
	"main_photo" BOOLEAN default 'f',
	"sort" INTEGER(11),
	"description_es" TEXT,
	PRIMARY KEY ("id")
);

COMMENT ON TABLE "news_photo" IS '';


SET search_path TO public;
-----------------------------------------------------------------------------
-- events
-----------------------------------------------------------------------------

DROP TABLE "events" CASCADE;


CREATE TABLE "events"
(
	"id" serial(11)  NOT NULL,
	"start_at" TIMESTAMP,
	"end_at" TIMESTAMP,
	"created_at" TIMESTAMP,
	"updated_at" TIMESTAMP,
	"title_pl" VARCHAR(255),
	"content_pl" TEXT,
	"location_pl" VARCHAR(100),
	"stand_pl" VARCHAR(100),
	"is_active_pl" BOOLEAN default 't',
	"title_en" VARCHAR(255),
	"content_en" TEXT,
	"location_en" VARCHAR(100),
	"stand_en" VARCHAR(100),
	"is_active_en" BOOLEAN default 't',
	"title_de" VARCHAR(255),
	"content_de" TEXT,
	"location_de" VARCHAR(100),
	"stand_de" VARCHAR(100),
	"is_active_de" BOOLEAN default 't',
	"title_ru" VARCHAR(255),
	"content_ru" TEXT,
	"location_ru" VARCHAR(100),
	"stand_ru" VARCHAR(100),
	"is_active_ru" BOOLEAN default 't',
	"title_es" VARCHAR(255),
	"content_es" TEXT,
	"location_es" VARCHAR(100),
	"stand_es" VARCHAR(100),
	"is_active_es" BOOLEAN default 't',
	"image" VARCHAR(150),
	PRIMARY KEY ("id")
);

COMMENT ON TABLE "events" IS '';


SET search_path TO public;
ALTER TABLE "category" ADD CONSTRAINT "category_FK_1" FOREIGN KEY ("category_id") REFERENCES "category" ("id") ON DELETE RESTRICT;

ALTER TABLE "product" ADD CONSTRAINT "product_FK_1" FOREIGN KEY ("category_id") REFERENCES "category" ("id") ON DELETE RESTRICT;

ALTER TABLE "product_promotion" ADD CONSTRAINT "product_promotion_FK_1" FOREIGN KEY ("promotion_id") REFERENCES "promotion" ("id") ON DELETE CASCADE;

ALTER TABLE "product_promotion" ADD CONSTRAINT "product_promotion_FK_2" FOREIGN KEY ("product_id") REFERENCES "product" ("id") ON DELETE CASCADE;

ALTER TABLE "product_image" ADD CONSTRAINT "product_image_FK_1" FOREIGN KEY ("product_id") REFERENCES "product" ("id") ON DELETE CASCADE;

ALTER TABLE "past_projects" ADD CONSTRAINT "past_projects_FK_1" FOREIGN KEY ("category_id") REFERENCES "category" ("id") ON DELETE CASCADE;

ALTER TABLE "past_project_image" ADD CONSTRAINT "past_project_image_FK_1" FOREIGN KEY ("past_project_id") REFERENCES "past_projects" ("id") ON DELETE CASCADE;

ALTER TABLE "news_photo" ADD CONSTRAINT "news_photo_FK_1" FOREIGN KEY ("news_id") REFERENCES "news" ("id") ON UPDATE CASCADE ON DELETE CASCADE;
