diff --git a/backend/sql/1-create_person.sql b/backend/sql/1-create_person.sql index fe9a335..48f9799 100644 --- a/backend/sql/1-create_person.sql +++ b/backend/sql/1-create_person.sql @@ -1,8 +1,8 @@ --- Table: public.Person +-- Table: Person --- DROP TABLE IF EXISTS public."Person"; +-- DROP TABLE IF EXISTS "Person"; -CREATE TABLE IF NOT EXISTS public."Person" +CREATE TABLE IF NOT EXISTS "Person" ( id SERIAL PRIMARY KEY, email character varying(128) NOT NULL UNIQUE, -- Primary e-mail @@ -14,9 +14,4 @@ CREATE TABLE IF NOT EXISTS public."Person" place_of_living character varying(128), about_me character varying(4096), qualification character varying(64) -) - -TABLESPACE pg_default; - -ALTER TABLE IF EXISTS public."Person" - OWNER to pg_database_owner; \ No newline at end of file +) \ No newline at end of file diff --git a/backend/sql/10-create_request_reset_password.sql b/backend/sql/10-create_request_reset_password.sql index 559bf86..2c889c8 100644 --- a/backend/sql/10-create_request_reset_password.sql +++ b/backend/sql/10-create_request_reset_password.sql @@ -1,17 +1,12 @@ --- Table: public.RequestResetPassword +-- Table: RequestResetPassword --- DROP TABLE IF EXISTS public."RequestResetPassword"; +-- DROP TABLE IF EXISTS "RequestResetPassword"; -CREATE TABLE IF NOT EXISTS public."RequestResetPassword" +CREATE TABLE IF NOT EXISTS "RequestResetPassword" ( id serial, email character varying(128) NOT NULL, secret character varying NOT NULL, time_of_request timestamp without time zone NOT NULL DEFAULT now(), CONSTRAINT "RequestResetPassword_pkey" PRIMARY KEY (id) -) - -TABLESPACE pg_default; - -ALTER TABLE IF EXISTS public."RequestResetPassword" - OWNER to postgres; \ No newline at end of file +) \ No newline at end of file diff --git a/backend/sql/11-create_experience.sql b/backend/sql/11-create_experience.sql index f6be6e6..58922e2 100644 --- a/backend/sql/11-create_experience.sql +++ b/backend/sql/11-create_experience.sql @@ -1,8 +1,8 @@ --- Table: public.Experience +-- Table: Experience --- DROP TABLE IF EXISTS public."Experience"; +-- DROP TABLE IF EXISTS "Experience"; -CREATE TABLE IF NOT EXISTS public."Experience" +CREATE TABLE IF NOT EXISTS "Experience" ( id serial, title character varying(128) NOT NULL, @@ -14,16 +14,11 @@ CREATE TABLE IF NOT EXISTS public."Experience" type character varying(32) NOT NULL, CONSTRAINT "Experience_pkey" PRIMARY KEY (id), CONSTRAINT "OrganizationFk" FOREIGN KEY (organization_id) - REFERENCES public."Organization" (id) MATCH SIMPLE + REFERENCES "Organization" (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE SET NULL, CONSTRAINT "PersonFk" FOREIGN KEY (person_id) - REFERENCES public."Person" (id) MATCH SIMPLE + REFERENCES "Person" (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE -) - -TABLESPACE pg_default; - -ALTER TABLE IF EXISTS public."Experience" - OWNER to postgres; \ No newline at end of file +) \ No newline at end of file diff --git a/backend/sql/2-create_activation_link.sql b/backend/sql/2-create_activation_link.sql index 1be4584..331dd9d 100644 --- a/backend/sql/2-create_activation_link.sql +++ b/backend/sql/2-create_activation_link.sql @@ -1,18 +1,13 @@ --- Table: public.ActivationLink +-- Table: ActivationLink --- DROP TABLE IF EXISTS public."ActivationLink"; +-- DROP TABLE IF EXISTS "ActivationLink"; -CREATE TABLE IF NOT EXISTS public."ActivationLink" +CREATE TABLE IF NOT EXISTS "ActivationLink" ( identifier character varying PRIMARY KEY, person_id integer NOT NULL, CONSTRAINT "PersonActivationLinkFK" FOREIGN KEY (person_id) - REFERENCES public."Person" (id) MATCH SIMPLE + REFERENCES "Person" (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE -) - -TABLESPACE pg_default; - -ALTER TABLE IF EXISTS public."ActivationLink" - OWNER to pg_database_owner; \ No newline at end of file +) \ No newline at end of file diff --git a/backend/sql/3-create_organization.sql b/backend/sql/3-create_organization.sql index 5a50921..4c9bda5 100644 --- a/backend/sql/3-create_organization.sql +++ b/backend/sql/3-create_organization.sql @@ -1,16 +1,11 @@ --- Table: public.Organization + -- Table: Organization --- DROP TABLE IF EXISTS public."Organization"; + -- DROP TABLE IF EXISTS "Organization"; -CREATE TABLE IF NOT EXISTS public."Organization" -( - id SERIAL PRIMARY KEY, - name character varying(128) NOT NULL, - location character varying, - description text -) - -TABLESPACE pg_default; - -ALTER TABLE IF EXISTS public."Organization" - OWNER to pg_database_owner; \ No newline at end of file + CREATE TABLE IF NOT EXISTS "Organization" + ( + id SERIAL PRIMARY KEY, + name character varying(128) NOT NULL, + location character varying, + description text + ) \ No newline at end of file diff --git a/backend/sql/4-create_organization_post.sql b/backend/sql/4-create_organization_post.sql index 11ea289..4404656 100644 --- a/backend/sql/4-create_organization_post.sql +++ b/backend/sql/4-create_organization_post.sql @@ -1,8 +1,8 @@ --- Table: public.OrganizationPost +-- Table: OrganizationPost --- DROP TABLE IF EXISTS public."OrganizationPost"; +-- DROP TABLE IF EXISTS "OrganizationPost"; -CREATE TABLE IF NOT EXISTS public."OrganizationPost" +CREATE TABLE IF NOT EXISTS "OrganizationPost" ( id SERIAL PRIMARY KEY, organization_id integer NOT NULL, @@ -10,18 +10,13 @@ CREATE TABLE IF NOT EXISTS public."OrganizationPost" created_at timestamp without time zone DEFAULT now(), original_author integer NOT NULL, CONSTRAINT "AuthorIdFK" FOREIGN KEY (original_author) - REFERENCES public."Person" (id) MATCH SIMPLE + REFERENCES "Person" (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE NOT VALID, CONSTRAINT "OrganizationIdFk" FOREIGN KEY (organization_id) - REFERENCES public."Organization" (id) MATCH SIMPLE + REFERENCES "Organization" (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE NOT VALID -) - -TABLESPACE pg_default; - -ALTER TABLE IF EXISTS public."OrganizationPost" - OWNER to postgres; \ No newline at end of file +) \ No newline at end of file diff --git a/backend/sql/5-create_organization_administrator.sql b/backend/sql/5-create_organization_administrator.sql index 48caff4..a08c678 100644 --- a/backend/sql/5-create_organization_administrator.sql +++ b/backend/sql/5-create_organization_administrator.sql @@ -1,24 +1,19 @@ --- Table: public.OrganizationAdministrator +-- Table: OrganizationAdministrator --- DROP TABLE IF EXISTS public."OrganizationAdministrator"; +-- DROP TABLE IF EXISTS "OrganizationAdministrator"; -CREATE TABLE IF NOT EXISTS public."OrganizationAdministrator" +CREATE TABLE IF NOT EXISTS "OrganizationAdministrator" ( id_person integer NOT NULL, id_organization integer NOT NULL, CONSTRAINT "OrganizationAdministrator_pkey" PRIMARY KEY (id_organization, id_person), CONSTRAINT "OrganizationAdministratorOrganizationId" FOREIGN KEY (id_organization) - REFERENCES public."Organization" (id) MATCH SIMPLE + REFERENCES "Organization" (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE NOT VALID, CONSTRAINT "OrganizationAdministratorUserId" FOREIGN KEY (id_person) - REFERENCES public."Person" (id) MATCH SIMPLE + REFERENCES "Person" (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE -) - -TABLESPACE pg_default; - -ALTER TABLE IF EXISTS public."OrganizationAdministrator" - OWNER to pg_database_owner; \ No newline at end of file +) \ No newline at end of file diff --git a/backend/sql/6-create_message.sql b/backend/sql/6-create_message.sql index 8291620..202db6e 100644 --- a/backend/sql/6-create_message.sql +++ b/backend/sql/6-create_message.sql @@ -1,8 +1,8 @@ --- Table: public.Message +-- Table: Message --- DROP TABLE IF EXISTS public."Message"; +-- DROP TABLE IF EXISTS "Message"; -CREATE TABLE IF NOT EXISTS public."Message" +CREATE TABLE IF NOT EXISTS "Message" ( id serial NOT NULL, person_id integer NOT NULL, @@ -13,30 +13,25 @@ CREATE TABLE IF NOT EXISTS public."Message" sender_type character varying(12) NOT NULL, CONSTRAINT "Message_pkey" PRIMARY KEY (id), CONSTRAINT "Message_author_on_behalf_of_company_fkey" FOREIGN KEY (author_on_behalf_of_organization) - REFERENCES public."Person" (id) MATCH SIMPLE + REFERENCES "Person" (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE, CONSTRAINT "Message_organization_id_fkey" FOREIGN KEY (organization_id) - REFERENCES public."Organization" (id) MATCH SIMPLE + REFERENCES "Organization" (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE, CONSTRAINT "Message_person_id_fkey" FOREIGN KEY (person_id) - REFERENCES public."Person" (id) MATCH SIMPLE + REFERENCES "Person" (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE CASCADE, CONSTRAINT "Message_sender_type_check" CHECK (sender_type::text = 'ORGANIZATION'::text OR sender_type::text = 'PERSON'::text), CONSTRAINT "Message_sender_constraint" CHECK (author_on_behalf_of_organization IS NULL AND sender_type::text = 'PERSON'::text OR author_on_behalf_of_organization IS NOT NULL AND sender_type::text = 'ORGANIZATION'::text) ) -TABLESPACE pg_default; - -ALTER TABLE IF EXISTS public."Message" - OWNER to postgres; - -COMMENT ON COLUMN public."Message".sender_type +COMMENT ON COLUMN "Message".sender_type IS 'sender_type can be either be PERSON or ORGANIZATION, depending who''s sending the message. It is PERSON if and only if author_on_behalf_of_organization is NULL. It is ORGANIZATION if and only if author_on_behalf_of_organization is NOT NULL. This column may seem redundant if we already know how to identify a sender, but it does give more clarity to the API implementers'; -COMMENT ON CONSTRAINT "Message_sender_type_check" ON public."Message" +COMMENT ON CONSTRAINT "Message_sender_type_check" ON "Message" IS 'We want the sender to be either PERSON or ORGANIZATION'; -COMMENT ON CONSTRAINT "Message_sender_constraint" ON public."Message" +COMMENT ON CONSTRAINT "Message_sender_constraint" ON "Message" IS 'If ''author_on_behalf_of_organization'' is NULL, then the sender is a person, instead, if ''author_on_behalf_of_organization'' is not NULL, the sender is a organization'; \ No newline at end of file diff --git a/backend/sql/7-create_tag.sql b/backend/sql/7-create_tag.sql index 73d410a..058fe87 100644 --- a/backend/sql/7-create_tag.sql +++ b/backend/sql/7-create_tag.sql @@ -1,15 +1,10 @@ --- Table: public.Tag + -- Table: Tag --- DROP TABLE IF EXISTS public."Tag"; + -- DROP TABLE IF EXISTS "Tag"; -CREATE TABLE IF NOT EXISTS public."Tag" -( - id SERIAL, - tag character varying(256) NOT NULL, - CONSTRAINT "Tag_pkey" PRIMARY KEY (id) -) - -TABLESPACE pg_default; - -ALTER TABLE IF EXISTS public."Tag" - OWNER to postgres; \ No newline at end of file + CREATE TABLE IF NOT EXISTS "Tag" + ( + id SERIAL, + tag character varying(256) NOT NULL, + CONSTRAINT "Tag_pkey" PRIMARY KEY (id) + ) \ No newline at end of file diff --git a/backend/sql/8-create_job_offer.sql b/backend/sql/8-create_job_offer.sql index 1eee20e..8fc4994 100644 --- a/backend/sql/8-create_job_offer.sql +++ b/backend/sql/8-create_job_offer.sql @@ -1,8 +1,8 @@ --- Table: public.JobOffer +-- Table: JobOffer --- DROP TABLE IF EXISTS public."JobOffer"; +-- DROP TABLE IF EXISTS "JobOffer"; -CREATE TABLE IF NOT EXISTS public."JobOffer" +CREATE TABLE IF NOT EXISTS "JobOffer" ( id SERIAL, title character varying(2048) NOT NULL, @@ -15,13 +15,8 @@ CREATE TABLE IF NOT EXISTS public."JobOffer" organization_id integer, CONSTRAINT "JobOffer_pkey" PRIMARY KEY (id), CONSTRAINT "OrganizationFK" FOREIGN KEY (organization_id) - REFERENCES public."Organization" (id) MATCH SIMPLE + REFERENCES "Organization" (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE NOT VALID -) - -TABLESPACE pg_default; - -ALTER TABLE IF EXISTS public."JobOffer" - OWNER to postgres; \ No newline at end of file +) \ No newline at end of file diff --git a/backend/sql/9-create_job_offer_tag.sql b/backend/sql/9-create_job_offer_tag.sql index d829c1a..2b6ad01 100644 --- a/backend/sql/9-create_job_offer_tag.sql +++ b/backend/sql/9-create_job_offer_tag.sql @@ -1,25 +1,20 @@ --- Table: public.JobOfferTag +-- Table: JobOfferTag -- This table allows to create a N-to-N map between Tag and JobOffer --- DROP TABLE IF EXISTS public."JobOfferTag"; +-- DROP TABLE IF EXISTS "JobOfferTag"; -CREATE TABLE IF NOT EXISTS public."JobOfferTag" +CREATE TABLE IF NOT EXISTS "JobOfferTag" ( id serial, job_offer_id integer NOT NULL, tag_id integer NOT NULL, CONSTRAINT "JobOfferTag_pkey" PRIMARY KEY (id), CONSTRAINT "JobOfferFk" FOREIGN KEY (job_offer_id) - REFERENCES public."JobOffer" (id) MATCH SIMPLE + REFERENCES "JobOffer" (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE, CONSTRAINT "TagFk" FOREIGN KEY (tag_id) - REFERENCES public."Tag" (id) MATCH SIMPLE + REFERENCES "Tag" (id) MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE -) - -TABLESPACE pg_default; - -ALTER TABLE IF EXISTS public."JobOfferTag" - OWNER to postgres; \ No newline at end of file +) \ No newline at end of file