DO $$ 
    BEGIN
	IF EXISTS (SELECT "Id" FROM public."Versions" WHERE "Build">=1765) THEN
		RETURN;
          END IF;
        BEGIN
    IF EXISTS (SELECT "Id" FROM public."Versions" WHERE "Path" ='ALTER EventMaterials.DocumentId' ) THEN


       INSERT INTO public."Versions" ("Path", "Build") VALUES('ALTER EventMaterials.DocumentId',616);
	   DROP TABLE public."EventMaterials";

CREATE TABLE public."EventMaterials" (
    "Id" bigserial NOT NULL,
    "EventId" bigint NOT NULL,
    "DocumentId" bigint NOT NULL,
    "Timestamp" timestamp without time zone DEFAULT timezone('utc', now())  NOT NULL,
  PRIMARY KEY ("EventId", "DocumentId")
); 

CREATE INDEX "IDX_EventMaterials_DocumentId"
    ON public."EventMaterials" USING btree
    ("DocumentId" ASC NULLS LAST)
    TABLESPACE pg_default; 


    END IF;
 

         

        EXCEPTION
            WHEN duplicate_column THEN RAISE NOTICE 'column <DocumentId> already exists in <EventMaterials>.';
        END;
    END;
$$
