From 91d9d6af192db3e6680f4090476f495dc58cdaba Mon Sep 17 00:00:00 2001 From: Ruslan Getmansky Date: Wed, 14 Dec 2016 11:26:36 +0200 Subject: [PATCH] P5-877: Create new table structure and API handling for saving interior images in Society --- migrations/000.022.sql | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 migrations/000.022.sql diff --git a/migrations/000.022.sql b/migrations/000.022.sql new file mode 100644 index 0000000..864ab7b --- /dev/null +++ b/migrations/000.022.sql @@ -0,0 +1,61 @@ +-- P5-877 +-- Table: public.rooms +/* +DROP TABLE IF EXISTS public.interiors; +DROP TABLE IF EXISTS public.rooms; +DROP INDEX IF EXISTS public.interiors_print_id_idx; +*/ + +CREATE TABLE IF NOT EXISTS public.rooms +( + id SERIAL NOT NULL, + name CHARACTER VARYING(255) NOT NULL, + + CONSTRAINT rooms_pkey PRIMARY KEY (id) +); + +CREATE UNIQUE INDEX rooms_name_idx + ON public.rooms (name); + + +CREATE TABLE IF NOT EXISTS public.interiors +( + id SERIAL NOT NULL, + print_id INTEGER NOT NULL, + room_id INTEGER, + "position" SMALLINT NOT NULL DEFAULT 0, + create_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), + + CONSTRAINT interiors_pkey PRIMARY KEY (id), + CONSTRAINT interiors_print_id_fkey FOREIGN KEY (print_id) + REFERENCES public."product-printproducts" (printid) ON DELETE CASCADE, + CONSTRAINT interiors_room_id_fkey FOREIGN KEY (room_id) + REFERENCES public.rooms (id) ON DELETE RESTRICT +); + +-- COVERING INDEX FOR print_id foreign key +CREATE INDEX interiors_print_id_idx + ON public.interiors (print_id); + +CREATE UNIQUE INDEX interiors_print_id_room_id_idx + ON public.interiors (print_id, room_id); + + +INSERT INTO public.rooms (id, name) VALUES + (1, 'room01_painting_landscape'), + (2, 'room01_painting_square'), + (3, 'room01_painting_standing'), + (4, 'room01_wallpaper_landscape'), + (5, 'room02_painting_landscape'), + (6, 'room02_painting_square'), + (7, 'room02_painting_standing'), + (8, 'room02_wallpaper_landscape'), + (9, 'room02_wallpaper_square'), + (10, 'room02_wallpaper_standing'), + (11, 'room03_painting_landscape'), + (12, 'room03_painting_square'), + (13, 'room03_painting_standing'), + (14, 'room03_wallpaper_landscape'), + (15, 'room03_wallpaper_square'), + (16, 'room03_wallpaper_standing') +; \ No newline at end of file