diff --git a/docker-compose.yml b/docker-compose.yml index 5e679b3..b375c8f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,6 +25,7 @@ services: image: postgres:latest ports: - "5432:5432" + restart: on-failure volumes: - ../FinalTask3/src/main/resources/sql:/docker-entrypoint-initdb.d - ./src/main/resources/sql/create_tables.sql:/docker-entrypoint-initdb.d/create_tables.sql diff --git a/src/main/resources/sql/create_tables.sql b/src/main/resources/sql/create_tables.sql index 6d09cff..84c2b6e 100644 --- a/src/main/resources/sql/create_tables.sql +++ b/src/main/resources/sql/create_tables.sql @@ -1,19 +1,18 @@ -CREATE TABLE IF NOT EXISTS roles ( - name VARCHAR(255) PRIMARY KEY +CREATE TABLE IF NOT EXISTS public.roles ( + name VARCHAR(45) COLLATE pg_catalog."default" NOT NULL, + CONSTRAINT roles_pkey PRIMARY KEY (name) ); -CREATE TABLE IF NOT EXISTS public.countries -( - name character varying(45) COLLATE pg_catalog."default" NOT NULL, +CREATE TABLE IF NOT EXISTS public.countries ( + name VARCHAR(45) COLLATE pg_catalog."default" NOT NULL, is_active boolean NOT NULL, CONSTRAINT countries_pkey PRIMARY KEY (name) ); -CREATE TABLE IF NOT EXISTS public.cities -( - name character varying(45) COLLATE pg_catalog."default" NOT NULL, +CREATE TABLE IF NOT EXISTS public.cities ( + name VARCHAR(45) COLLATE pg_catalog."default" NOT NULL, is_active boolean NOT NULL, - country_name character varying(45) COLLATE pg_catalog."default" NOT NULL, + country_name VARCHAR(45) COLLATE pg_catalog."default" NOT NULL, CONSTRAINT cities_pkey PRIMARY KEY (name), CONSTRAINT cities_country_name_fkey FOREIGN KEY (country_name) REFERENCES public.countries (name) MATCH SIMPLE @@ -21,11 +20,10 @@ CREATE TABLE IF NOT EXISTS public.cities ON DELETE NO ACTION ); -CREATE TABLE IF NOT EXISTS public.postal_codes -( - code character varying(45) COLLATE pg_catalog."default" NOT NULL, +CREATE TABLE IF NOT EXISTS public.postal_codes ( + code VARCHAR(45) COLLATE pg_catalog."default" NOT NULL, is_active boolean NOT NULL, - city_name character varying COLLATE pg_catalog."default", + city_name VARCHAR COLLATE pg_catalog."default", CONSTRAINT postal_codes_pkey PRIMARY KEY (code), CONSTRAINT postal_codes_city_name_fkey FOREIGN KEY (city_name) REFERENCES public.cities (name) MATCH SIMPLE @@ -34,4 +32,84 @@ CREATE TABLE IF NOT EXISTS public.postal_codes NOT VALID ); +CREATE TABLE IF NOT EXISTS public.delivery_methods ( + name VARCHAR(45) COLLATE pg_catalog."default" NOT NULL, + is_active boolean NOT NULL, + CONSTRAINT delivery_methods_pkey PRIMARY KEY (name) +); + +CREATE TABLE IF NOT EXISTS public.order_statuses ( + name VARCHAR(45) COLLATE pg_catalog."default" NOT NULL, + is_active boolean NOT NULL, + CONSTRAINT order_statuses_pkey PRIMARY KEY (name) +); + +CREATE TABLE IF NOT EXISTS public.payment_methods ( + name VARCHAR(45) COLLATE pg_catalog."default" NOT NULL, + is_active boolean NOT NULL, + CONSTRAINT payment_methods_pkey PRIMARY KEY (name) +); + +CREATE TABLE IF NOT EXISTS public.payment_statuses ( + name VARCHAR(45) COLLATE pg_catalog."default" NOT NULL, + is_active boolean NOT NULL, + CONSTRAINT payment_statuses_pkey PRIMARY KEY (name) +); + +CREATE TABLE IF NOT EXISTS public.book_genres ( + name VARCHAR(45) COLLATE pg_catalog."default" NOT NULL, + CONSTRAINT book_genres_pkey PRIMARY KEY (name) +); + +CREATE TABLE IF NOT EXISTS public.book_parameter_formats ( + name VARCHAR(45) COLLATE pg_catalog."default" NOT NULL, + CONSTRAINT book_parameter_formats_pkey PRIMARY KEY (name) +); +CREATE TABLE IF NOT EXISTS public.user_addresses ( + id integer NOT NULL, + postal_code VARCHAR(45) COLLATE pg_catalog."default" NOT NULL, + street VARCHAR(60) COLLATE pg_catalog."default" NOT NULL, + number VARCHAR(255) COLLATE pg_catalog."default" NOT NULL, + is_active boolean NOT NULL, + CONSTRAINT user_addresses_pkey PRIMARY KEY (id), + CONSTRAINT user_addresses_postal_code_fkey FOREIGN KEY (postal_code) + REFERENCES public.postal_codes (code) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION +); + +CREATE TABLE IF NOT EXISTS public.users ( + id integer NOT NULL, + name VARCHAR(45) COLLATE pg_catalog."default" NOT NULL, + surname VARCHAR(45) COLLATE pg_catalog."default" NOT NULL, + date_of_birth date NOT NULL, + email_address VARCHAR COLLATE pg_catalog."default" NOT NULL, + password VARCHAR COLLATE pg_catalog."default" NOT NULL, + is_active boolean NOT NULL, + phone_number VARCHAR(45) COLLATE pg_catalog."default" NOT NULL, + address_id integer, + CONSTRAINT users_pkey PRIMARY KEY (id), + CONSTRAINT users_email_address_key UNIQUE (email_address), + CONSTRAINT users_address_id_fkey FOREIGN KEY (address_id) + REFERENCES public.user_addresses (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION +); + +CREATE TABLE IF NOT EXISTS public.user_roles ( + user_id integer NOT NULL, + role_id VARCHAR(45) COLLATE pg_catalog."default" NOT NULL, + assigned_date date NOT NULL, + id integer NOT NULL, + CONSTRAINT user_roles_pkey PRIMARY KEY (user_id, role_id), + CONSTRAINT user_roles_role_fkey FOREIGN KEY (role_id) + REFERENCES public.roles (name) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION + NOT VALID, + CONSTRAINT user_roles_user_id_fkey FOREIGN KEY (user_id) + REFERENCES public.users (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION +); \ No newline at end of file diff --git a/src/main/resources/sql/fill_tables.sql b/src/main/resources/sql/fill_tables.sql index 06de7c2..08edb3c 100644 --- a/src/main/resources/sql/fill_tables.sql +++ b/src/main/resources/sql/fill_tables.sql @@ -17,4 +17,59 @@ VALUES INSERT INTO public.postal_codes (code, is_active, city_name) VALUES ('18014', true, 'Granada'), - ('48143', true, 'Münster'); \ No newline at end of file + ('48143', true, 'Münster'); + +INSERT INTO public.delivery_methods (name, is_active) +VALUES + ('EXPRESS', true), + ('STANDARD', true); + +INSERT INTO public.order_statuses (name, is_active) +VALUES + ('Pending payment', true), + ('Pending shipment', true), + ('Shipped', true), + ('Delivered', true); + +INSERT INTO public.payment_methods (name, is_active) +VALUES + ('Cash', true), + ('By card', true); + +INSERT INTO public.payment_statuses (name, is_active) +VALUES + ('Pending', true), + ('Paid', true); + +INSERT INTO public.book_genres (name) +VALUES + ('Thriller'), + ('Essay'), + ('Fantasy'); + +INSERT INTO public.book_parameter_formats (name) +VALUES + ('E-book'), + ('Paperback'), + ('Hardcover'); + +INSERT INTO public.user_addresses ( + id, postal_code, street, number, is_active +) +VALUES ( + 1, '18014', 'Street', 1, true +); + +INSERT INTO public.users ( + id, name, surname, date_of_birth, email_address, password, is_active, phone_number, address_id +) +VALUES ( + 1, 'Admin', 'Admin', '01-01-2000', 'admin@email.com', '$2a$10$UXwOIA7tOQES3gO2shUsDO.AISCnWLy.aaxUzQd1te2Uki.0qPZpG', true, 123456789, 1 +); + +INSERT INTO public.user_roles ( + user_id, role_id, assigned_date, id +) +VALUES ( + 1, 'ADMIN', '01-01-2000', 1 +); \ No newline at end of file