Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Type: contact_type
- -- DROP TYPE IF EXISTS public.contact_type;
- CREATE TYPE public.contact_type AS ENUM
- ('unknown', 'direction', 'commercial', 'production', 'support', 'external', '#err');
- ALTER TYPE public.contact_type
- OWNER TO postgres;
- --//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--
- ----//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//
- --//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--
- -- FUNCTION: public.update_date_alter()
- -- DROP FUNCTION IF EXISTS public.update_date_alter();
- CREATE OR REPLACE FUNCTION public.update_date_alter()
- RETURNS trigger
- LANGUAGE 'plpgsql'
- COST 100
- VOLATILE NOT LEAKPROOF
- AS $BODY$
- BEGIN
- NEW.date_alter = NOW();
- RETURN NEW;
- END;
- $BODY$;
- ALTER FUNCTION public.update_date_alter()
- OWNER TO postgres;
- --//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--
- ----//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//
- --//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--
- -- Table: public.company
- -- DROP TABLE IF EXISTS public.company;
- CREATE TABLE IF NOT EXISTS public.company
- (
- comp_id bigserial NOT NULL,
- comp_name character varying(255) COLLATE pg_catalog."default" NOT NULL,
- comp_active boolean NOT NULL DEFAULT true,
- date_create timestamp with time zone DEFAULT now(),
- date_alter timestamp with time zone DEFAULT now(),
- CONSTRAINT "company_PRIMARY_KEY" PRIMARY KEY (comp_id)
- )
- TABLESPACE pg_default;
- ALTER TABLE IF EXISTS public.company
- OWNER to postgres;
- -- Index: company_unique_name
- -- DROP INDEX IF EXISTS public.company_unique_name;
- CREATE UNIQUE INDEX IF NOT EXISTS company_unique_name
- ON public.company USING btree
- (comp_name COLLATE pg_catalog."default" ASC NULLS LAST)
- TABLESPACE pg_default
- WHERE comp_active;
- -- Trigger: comp_update_date_alter
- -- DROP TRIGGER IF EXISTS comp_update_date_alter ON public.company;
- CREATE TRIGGER comp_update_date_alter
- BEFORE UPDATE
- ON public.company
- FOR EACH ROW
- EXECUTE FUNCTION public.update_date_alter();
- --//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--
- ----//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//
- --//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--
- -- Table: public.contact
- -- DROP TABLE IF EXISTS public.contact;
- CREATE TABLE IF NOT EXISTS public.contact
- (
- con_id bigserial NOT NULL ,
- con_lastname character varying(100) COLLATE pg_catalog."default",
- con_firstname character varying(50) COLLATE pg_catalog."default",
- con_mail character varying(255) COLLATE pg_catalog."default" NOT NULL DEFAULT 'unknown@example.com'::character varying,
- con_active boolean NOT NULL DEFAULT true,
- comp_id bigint NOT NULL DEFAULT 1,
- con_comment text COLLATE pg_catalog."default",
- con_status contact_type NOT NULL DEFAULT 'unknown'::contact_type,
- con_date_first_interaction timestamp with time zone,
- con_date_last_interaction timestamp with time zone,
- date_create timestamp with time zone DEFAULT now(),
- date_alter timestamp with time zone DEFAULT now(),
- CONSTRAINT "contact_PRIMARY_KEY" PRIMARY KEY (con_id),
- CONSTRAINT contact_has_company FOREIGN KEY (comp_id)
- REFERENCES public.company (comp_id) MATCH SIMPLE
- ON UPDATE CASCADE
- ON DELETE SET DEFAULT
- DEFERRABLE INITIALLY DEFERRED,
- CONSTRAINT contact_first_interaction_cannot_be_in_future CHECK (con_date_first_interaction IS NULL OR con_date_first_interaction <= now()),
- CONSTRAINT contact_first_interaction_imply_last_interaction CHECK (con_date_first_interaction IS NULL OR con_date_last_interaction IS NOT NULL),
- CONSTRAINT contact_last_interaction_cannot_be_in_future CHECK (con_date_last_interaction IS NULL OR con_date_last_interaction <= now()),
- CONSTRAINT contact_last_interaction_cannot_be_lower_than_first_one CHECK (con_date_last_interaction IS NULL OR con_date_last_interaction >= con_date_first_interaction),
- CONSTRAINT contact_last_interaction_imply_first_interaction CHECK (con_date_last_interaction IS NULL OR con_date_first_interaction IS NOT NULL)
- )
- TABLESPACE pg_default;
- ALTER TABLE IF EXISTS public.contact
- OWNER to postgres;
- -- Index: contact_comp_id_idx
- -- DROP INDEX IF EXISTS public.contact_comp_id_idx;
- CREATE INDEX IF NOT EXISTS contact_comp_id_idx
- ON public.contact USING btree
- (comp_id ASC NULLS LAST)
- TABLESPACE pg_default;
- -- Index: contact_created_idx
- -- DROP INDEX IF EXISTS public.contact_created_idx;
- CREATE INDEX IF NOT EXISTS contact_created_idx
- ON public.contact USING btree
- ((timezone('Europe/Paris'::text, date_create)::date) DESC NULLS FIRST)
- TABLESPACE pg_default;
- -- Index: contact_last_interaction_year_month_idx
- -- DROP INDEX IF EXISTS public.contact_last_interaction_year_month_idx;
- CREATE INDEX IF NOT EXISTS contact_last_interaction_year_month_idx
- ON public.contact USING btree
- (date_part('year'::text, timezone('Europe/Paris'::text, con_date_last_interaction)) DESC NULLS FIRST, date_part('month'::text, timezone('Europe/Paris'::text, con_date_last_interaction)) DESC NULLS FIRST)
- TABLESPACE pg_default;
- -- Index: contact_unique_active_email
- -- DROP INDEX IF EXISTS public.contact_unique_active_email;
- CREATE UNIQUE INDEX IF NOT EXISTS contact_unique_active_email
- ON public.contact USING btree
- (con_mail COLLATE pg_catalog."default" ASC NULLS LAST)
- TABLESPACE pg_default
- WHERE con_active;
- -- Index: contact_upplastname_firstname
- -- DROP INDEX IF EXISTS public.contact_upplastname_firstname;
- CREATE INDEX IF NOT EXISTS contact_upplastname_firstname
- ON public.contact USING btree
- (upper(con_lastname::text) COLLATE pg_catalog."default" ASC NULLS LAST, con_firstname COLLATE pg_catalog."default" ASC NULLS LAST)
- TABLESPACE pg_default
- WHERE con_active;
- -- Index: contact_year_create_idx
- -- DROP INDEX IF EXISTS public.contact_year_create_idx;
- CREATE INDEX IF NOT EXISTS contact_year_create_idx
- ON public.contact USING btree
- (date_part('year'::text, timezone('Europe/Paris'::text, date_create)) ASC NULLS LAST)
- TABLESPACE pg_default;
- -- Trigger: contact_update_date_alter
- -- DROP TRIGGER IF EXISTS contact_update_date_alter ON public.contact;
- CREATE TRIGGER contact_update_date_alter
- BEFORE UPDATE
- ON public.contact
- FOR EACH ROW
- EXECUTE FUNCTION public.update_date_alter();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement