Adding migration scripts for Dmp, DmpReference, Description and DescriptionReference entities, other fixes / clear up dmp entity

This commit is contained in:
Thomas Georgios Giannos 2023-10-27 17:05:48 +03:00
parent 8d1c988135
commit e31970c7ea
9 changed files with 126 additions and 124 deletions

View File

@ -5,15 +5,13 @@ import eu.eudat.commons.enums.IsActive;
import eu.eudat.data.converters.DateToUTCConverter;
import eu.eudat.data.converters.enums.DescriptionStatusConverter;
import eu.eudat.data.converters.enums.IsActiveConverter;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Id;
import jakarta.persistence.*;
import java.time.Instant;
import java.util.UUID;
//@Entity
//@Table(name = "\"Description\"")
@Entity
@Table(name = "\"Description\"")
public class DescriptionEntity {
@Id

View File

@ -8,8 +8,8 @@ import jakarta.persistence.*;
import java.time.Instant;
import java.util.UUID;
//@Entity
//@Table(name = "\"DescriptionReference\"")
@Entity
@Table(name = "\"DescriptionReference\"")
public class DescriptionReferenceEntity {
@Id

View File

@ -10,9 +10,8 @@ import org.hibernate.annotations.GenericGenerator;
import java.time.Instant;
import java.util.UUID;
//TODO: (thgiannos) Wire up when all other dependent entities are refactored
//@Entity
//@Table(name = "\"DMP\"")
@Entity
@Table(name = "\"Dmp\"")
public class DmpEntity {
@Id
@ -85,73 +84,23 @@ public class DmpEntity {
public static final String _isActive = "isActive";
@Column(name = "\"finalized_at\"")
@Column(name = "finalized_at")
@Convert(converter = DateToUTCConverter.class)
private Instant finalizedAt;
public static final String _finalizedAt = "finalizedAt";
@Column(name = "\"published_at\"")
@Column(name = "published_at")
@Convert(converter = DateToUTCConverter.class)
private Instant publishedAt;
public static final String _publishedAt = "publishedAt";
// @ManyToOne(fetch = FetchType.LAZY)
// @JoinColumn(name = "\"Grant\"")
//TODO: (thgiannos) Previously 'Grant'
private UUID grant;
public static final String _grant = "grant";
//TODO: (thgiannos) Handle using the DMPEntity builder
// @OneToMany(fetch = FetchType.LAZY, mappedBy = "dmp")
// private Set<DMPDatasetProfile> associatedDmps;
// @ManyToOne(fetch = FetchType.LAZY)
// @JoinColumn(name = "\"Profile\"")
//TODO: (thgiannos) Previously 'DMPProfile'
private UUID profile;
public static final String _profile = "profile";
// @ManyToOne(fetch = FetchType.LAZY)
// @JoinColumn(name = "\"Creator\"")
//TODO: (thgiannos) Previously 'UserInfo'
@Column(name = "creator")
private UUID creator;
public static final String _creator = "creator";
//TODO: (thgiannos) Handle using the DMPEntity builder
// @OneToMany(mappedBy = "entityId", fetch = FetchType.LAZY)
// private Set<EntityDoiEntity> dois;
// @ManyToOne(fetch = FetchType.LAZY)
// @JoinColumn(name = "\"Project\"")
//TODO: (thgiannos) Previously 'Project'
private UUID project;
public static final String _project = "project";
// TODO: (thgiannos) Implement join entity
// @OneToMany(fetch = FetchType.LAZY)
// @JoinTable(name = "\"DMPOrganisation\"",
// joinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")},
// inverseJoinColumns = {@JoinColumn(name = "\"Organisation\"", referencedColumnName = "\"ID\"")}
// )
// private Set<Organisation> organisations;
// TODO: (thgiannos) Implement join entity
// @OneToMany(fetch = FetchType.LAZY)
// @JoinTable(name = "\"DMPResearcher\"",
// joinColumns = {@JoinColumn(name = "\"DMP\"", referencedColumnName = "\"ID\"")},
// inverseJoinColumns = {@JoinColumn(name = "\"Researcher\"", referencedColumnName = "\"ID\"")}
// )
// private Set<Researcher> researchers;
//TODO: (thgiannos) Handle using the DMPEntity builder
// private Set<UserDMP> users;
public UUID getId() {
return id;
}
@ -272,22 +221,6 @@ public class DmpEntity {
this.publishedAt = publishedAt;
}
public UUID getGrant() {
return grant;
}
public void setGrant(UUID grant) {
this.grant = grant;
}
public UUID getProfile() {
return profile;
}
public void setProfile(UUID profile) {
this.profile = profile;
}
public UUID getCreator() {
return creator;
}
@ -296,12 +229,4 @@ public class DmpEntity {
this.creator = creator;
}
public UUID getProject() {
return project;
}
public void setProject(UUID project) {
this.project = project;
}
}

View File

@ -69,22 +69,10 @@ public class Dmp {
public static final String _publishedAt = "publishedAt";
private UUID grant;
public static final String _grant = "grant";
private UUID profile;
public static final String _profile = "profile";
private UUID creator;
public static final String _creator = "creator";
private UUID project;
public static final String _project = "project";
private String hash;
public static final String _hash = "hash";
@ -216,22 +204,6 @@ public class Dmp {
this.publishedAt = publishedAt;
}
public UUID getGrant() {
return grant;
}
public void setGrant(UUID grant) {
this.grant = grant;
}
public UUID getProfile() {
return profile;
}
public void setProfile(UUID profile) {
this.profile = profile;
}
public UUID getCreator() {
return creator;
}
@ -240,14 +212,6 @@ public class Dmp {
this.creator = creator;
}
public UUID getProject() {
return project;
}
public void setProject(UUID project) {
this.project = project;
}
public String getHash() {
return hash;
}

View File

@ -1,3 +1,9 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.01.004';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
ALTER TABLE public."DMPProfile" RENAME TO "DmpBlueprint";
ALTER TABLE public."DmpBlueprint" RENAME "ID" TO id;
@ -23,4 +29,8 @@ UPDATE public."DmpBlueprint" SET is_active = 1;
UPDATE public."DmpBlueprint" SET is_active = 0 where status = 99;
UPDATE public."DmpBlueprint" SET status = 0 where is_active = 0;
ALTER TABLE public."DmpBlueprint" ALTER COLUMN is_active SET NOT NULL;
ALTER TABLE public."DmpBlueprint" ALTER COLUMN is_active SET NOT NULL;
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.004', '2023-10-27 12:00:00.000000+02', now(), 'Align dmp blueprint table.');
END$$;

View File

@ -0,0 +1,29 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.01.005';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
CREATE TABLE IF NOT EXISTS public."Dmp"
(
"id" uuid NOT NULL,
"label" character varying(250) COLLATE pg_catalog."default" NOT NULL,
"version" integer NOT NULL,
"status" smallint NOT NULL DEFAULT 0,
"properties" text COLLATE pg_catalog."default",
"dmp_properties" text COLLATE pg_catalog."default",
"group_id" uuid,
"description" text COLLATE pg_catalog."default",
"is_public" boolean NOT NULL DEFAULT false,
"extra_properties" text COLLATE pg_catalog."default",
"created_at" timestamp without time zone NOT NULL DEFAULT now(),
"updated_at" timestamp without time zone NOT NULL DEFAULT now(),
"is_active" smallint NOT NULL DEFAULT 1,
"finalized_at" timestamp without time zone,
"published_at" timestamp without time zone,
CONSTRAINT "Dmp_pkey" PRIMARY KEY (id)
)
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.005', '2023-10-27 12:00:00.000000+02', now(), 'Add Dmp table.');
END$$;

View File

@ -0,0 +1,23 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.01.006';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
CREATE TABLE IF NOT EXISTS public."DmpReference"
(
"id" uuid NOT NULL,
"dmp_id" uuid NOT NULL,
"reference_id" uuid NOT NULL,
"data" text COLLATE pg_catalog."default",
"created_at" timestamp without time zone NOT NULL DEFAULT now(),
"updated_at" timestamp without time zone NOT NULL DEFAULT now(),
"is_active" smallint NOT NULL DEFAULT 1,
CONSTRAINT "DmpReference_pkey" PRIMARY KEY (id),
CONSTRAINT "DmpReference_dmp_id_fkey" FOREIGN KEY ("dmp_id") REFERENCES public."Dmp"("id"),
CONSTRAINT "DmpReference_reference_id_fkey" FOREIGN KEY ("reference_id") REFERENCES public."Reference"("id")
)
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.006', '2023-10-27 12:00:00.000000+02', now(), 'Add DescriptionReference table.');
END$$;

View File

@ -0,0 +1,30 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.01.007';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
CREATE TABLE IF NOT EXISTS public."Description"
(
"id" uuid NOT NULL,
"label" character varying(250) COLLATE pg_catalog."default" NOT NULL,
"dmp" uuid,
"uri" character varying(250) COLLATE pg_catalog."default",
"properties" text COLLATE pg_catalog."default",
"profile" uuid,
"reference" text COLLATE pg_catalog."default",
"status" smallint NOT NULL DEFAULT 0,
"description" text COLLATE pg_catalog."default",
"dmp_section_index" integer NOT NULL,
"created_at" timestamp without time zone NOT NULL DEFAULT now(),
"updated_at" timestamp without time zone NOT NULL DEFAULT now(),
"is_active" smallint NOT NULL DEFAULT 1,
"finalized_at" timestamp without time zone,
CONSTRAINT "Description_pkey" PRIMARY KEY (id),
CONSTRAINT "Description_dmp_fkey" FOREIGN KEY ("dmp") REFERENCES public."Dmp"("id"),
CONSTRAINT "Description_profile_fkey" FOREIGN KEY ("profile") REFERENCES public."DescriptionTemplate"("ID")
)
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.007', '2023-10-27 12:00:00.000000+02', now(), 'Add Description table (former Dataset).');
END$$;

View File

@ -0,0 +1,23 @@
DO $$DECLARE
this_version CONSTANT varchar := '00.01.008';
BEGIN
PERFORM * FROM "DBVersion" WHERE version = this_version;
IF FOUND THEN RETURN; END IF;
CREATE TABLE IF NOT EXISTS public."DescriptionReference"
(
"id" uuid NOT NULL,
"data" text COLLATE pg_catalog."default" NOT NULL,
"description_id" uuid NOT NULL,
"reference_id" uuid NOT NULL,
"created_at" timestamp without time zone NOT NULL DEFAULT now(),
"updated_at" timestamp without time zone NOT NULL DEFAULT now(),
"is_active" smallint NOT NULL DEFAULT 1,
CONSTRAINT "DescriptionReference_pkey" PRIMARY KEY (id),
CONSTRAINT "DescriptionReference_description_fkey" FOREIGN KEY ("description_id") REFERENCES public."Description"("id"),
CONSTRAINT "DescriptionReference_reference_fkey" FOREIGN KEY ("reference_id") REFERENCES public."Reference"("id")
)
INSERT INTO public."DBVersion" VALUES ('DMPDB', '00.01.008', '2023-10-27 12:00:00.000000+02', now(), 'Add DescriptionReference table.');
END$$;