diff --git a/backend/sql/0-create_databse.sql b/backend/sql/0-create_databse.sql new file mode 100644 index 0000000..013346c --- /dev/null +++ b/backend/sql/0-create_databse.sql @@ -0,0 +1,13 @@ +-- Database: Blink + +-- DROP DATABASE IF EXISTS "Blink"; + +CREATE DATABASE "Blink" + WITH + OWNER = pg_database_owner + ENCODING = 'UTF8' + LC_COLLATE = 'Italian_Italy.1252' + LC_CTYPE = 'Italian_Italy.1252' + TABLESPACE = pg_default + CONNECTION LIMIT = -1 + IS_TEMPLATE = False; \ No newline at end of file diff --git a/backend/sql/1-create_person.sql b/backend/sql/1-create_person.sql new file mode 100644 index 0000000..2f0ccd3 --- /dev/null +++ b/backend/sql/1-create_person.sql @@ -0,0 +1,21 @@ +-- Table: public.Person + +-- DROP TABLE IF EXISTS public."Person"; + +CREATE TABLE IF NOT EXISTS public."Person" +( + id integer NOT NULL DEFAULT nextval('"Person_id_seq"'::regclass), + email character varying(128) COLLATE pg_catalog."default" NOT NULL, + password character varying(128) COLLATE pg_catalog."default" NOT NULL, + displayname character varying(128) COLLATE pg_catalog."default" NOT NULL, + date_of_birth date, + available boolean, + enabled boolean NOT NULL DEFAULT false, + place_of_living character varying(128) COLLATE pg_catalog."default", + CONSTRAINT "Person_pkey" PRIMARY KEY (id) +) + +TABLESPACE pg_default; + +ALTER TABLE IF EXISTS public."Person" + OWNER to pg_database_owner; \ No newline at end of file diff --git a/backend/sql/2-create_activation_link.sql b/backend/sql/2-create_activation_link.sql new file mode 100644 index 0000000..c766fa1 --- /dev/null +++ b/backend/sql/2-create_activation_link.sql @@ -0,0 +1,19 @@ +-- Table: public.ActivationLink + +-- DROP TABLE IF EXISTS public."ActivationLink"; + +CREATE TABLE IF NOT EXISTS public."ActivationLink" +( + identifier character varying COLLATE pg_catalog."default" NOT NULL, + person_id integer NOT NULL, + CONSTRAINT "ActivationLink_pkey" PRIMARY KEY (identifier), + CONSTRAINT "PersonActivationLinkFK" FOREIGN KEY (person_id) + REFERENCES public."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 diff --git a/backend/sql/3-create_organization.sql b/backend/sql/3-create_organization.sql new file mode 100644 index 0000000..1bad9da --- /dev/null +++ b/backend/sql/3-create_organization.sql @@ -0,0 +1,18 @@ +-- Table: public.Organization + +-- DROP TABLE IF EXISTS public."Organization"; + +CREATE TABLE IF NOT EXISTS public."Organization" +( + id integer NOT NULL DEFAULT nextval('"Organization_id_seq"'::regclass), + name character varying(128) COLLATE pg_catalog."default" NOT NULL, + location character varying COLLATE pg_catalog."default", + description text COLLATE pg_catalog."default", + is_hiring boolean, + CONSTRAINT "Organization_pkey" PRIMARY KEY (id) +) + +TABLESPACE pg_default; + +ALTER TABLE IF EXISTS public."Organization" + OWNER to pg_database_owner; \ No newline at end of file diff --git a/backend/sql/4-create_organization_post.sql b/backend/sql/4-create_organization_post.sql new file mode 100644 index 0000000..475c2a2 --- /dev/null +++ b/backend/sql/4-create_organization_post.sql @@ -0,0 +1,21 @@ +-- Table: public.OrganizationPost + +-- DROP TABLE IF EXISTS public."OrganizationPost"; + +CREATE TABLE IF NOT EXISTS public."OrganizationPost" +( + id integer NOT NULL DEFAULT nextval('"OrganizationPost_id_seq"'::regclass), + organization_id integer NOT NULL, + content text COLLATE pg_catalog."default" NOT NULL, + CONSTRAINT "OrganizationPost_pkey" PRIMARY KEY (id), + CONSTRAINT "OrganizationIdFk" FOREIGN KEY (organization_id) + REFERENCES public."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 diff --git a/backend/sql/5-create_organization_administrator.sql b/backend/sql/5-create_organization_administrator.sql new file mode 100644 index 0000000..a98a5b5 --- /dev/null +++ b/backend/sql/5-create_organization_administrator.sql @@ -0,0 +1,24 @@ +-- Table: public.OrganizationAdministrator + +-- DROP TABLE IF EXISTS public."OrganizationAdministrator"; + +CREATE TABLE IF NOT EXISTS public."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 + ON UPDATE NO ACTION + ON DELETE NO ACTION + NOT VALID, + CONSTRAINT "OrganizationAdministratorUserId" FOREIGN KEY (id_person) + REFERENCES public."Person" (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION +) + +TABLESPACE pg_default; + +ALTER TABLE IF EXISTS public."OrganizationAdministrator" + OWNER to pg_database_owner; \ No newline at end of file