Skip to content

Commit

Permalink
Working on DB design and setup
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro committed Oct 9, 2023
1 parent 86f5ae9 commit 529c463
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package org.orcid.persistence.jpa.entities;

import java.util.Objects;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
*
* @author Will Simpson
*
*/
@Table(name = "email_domain")
@Entity
public class EmailDomainEntity extends BaseEntity<Long> {

private static final long serialVersionUID = 7138838021634315502L;

public enum DomainCategory {PERSONAL, PROFESSIONAL, UNDEFINED}

private Long id;
private String emailDomain;
private DomainCategory category;


@Override
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "email_domain_seq")
@SequenceGenerator(name = "email_domain_seq", sequenceName = "email_domain_seq", allocationSize = 1)
@Column(name = "id")
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

@Column(name = "email_domain")
public String getEmailDomain() {
return emailDomain;
}

public void setCategory(DomainCategory category) {
this.category = category;
}

@Column(name = "category")
public DomainCategory getCategory() {
return category;
}

public void setEmailDomain(String emailDomain) {
this.emailDomain = emailDomain;
}

@Override
public int hashCode() {
return Objects.hash(category, emailDomain, id);
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
EmailDomainEntity other = (EmailDomainEntity) obj;
return category == other.category && Objects.equals(emailDomain, other.emailDomain) && Objects.equals(id, other.id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.orcid.persistence.jpa.entities;

import java.util.Objects;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
*
* @author Will Simpson
*
*/
@Table(name = "email_domain_to_org_id")
@Entity
public class EmailDomainToOrgIdEntity extends BaseEntity<Long> {

private static final long serialVersionUID = 7138838021634315502L;

public enum DomainCategory {PERSONAL, PROFESSIONAL, UNDEFINED}

private Long id;
private EmailDomainEntity emailDomian;
private OrgDisambiguatedEntity orgDisambiguated;


@Override
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "email_domain_to_org_id_seq")
@SequenceGenerator(name = "email_domain_to_org_id_seq", sequenceName = "email_domain_to_org_id_seq", allocationSize = 1)
@Column(name = "id")
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "email_domian_id")
public EmailDomainEntity getEmailDomian() {
return emailDomian;
}

public void setEmailDomian(EmailDomainEntity emailDomian) {
this.emailDomian = emailDomian;
}

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "org_disambiguated_id")
public OrgDisambiguatedEntity getOrgDisambiguated() {
return orgDisambiguated;
}

public void setOrgDisambiguated(OrgDisambiguatedEntity orgDisambiguated) {
this.orgDisambiguated = orgDisambiguated;
}
}
1 change: 1 addition & 0 deletions orcid-persistence/src/main/resources/db-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,5 @@
<include file="/db/updates/statistics.xml" />
<include file="/db/updates/identifier-types/update-ethos-to-be-case-sensitive.xml" />
<include file="/db/updates/dw_client_details_add_user_obo_enabled.xml" />
<include file="/db/updates/create_email_domain_mapping_tables.xml" />
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">

<changeSet author="Angel Montenegro" id="CREATE-EMAIL-DOMAIN-TABLE">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="email_domain" />
</not>
</preConditions>

<createTable tableName="email_domain">
<column name="id" type="bigint">
<constraints nullable="false" primaryKey="true"
primaryKeyName="email_domain_pkey" />
</column>
<column name="email_domain" type="VARCHAR(64)">
<constraints nullable="false" />
</column>
<column name="category" type="VARCHAR(16)">
<constraints nullable="false" />
</column>
<column name="date_created" type="TIMESTAMP WITH TIME ZONE" />
<column name="last_modified" type="TIMESTAMP WITH TIME ZONE" />
</createTable>
</changeSet>

<changeSet author="Angel Montenegro" id="CREATE-EMAIL-DOMAIN-TO-ORG-ID-TABLE">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="email_domain_to_org_id" />
</not>
</preConditions>

<createTable tableName="email_domain_to_org_id">
<column name="id" type="bigint">
<constraints nullable="false" primaryKey="true"
primaryKeyName="email_domain_to_org_id_pkey" />
</column>
<column name="email_domian_id" type="bigint">
<constraints nullable="false" />
</column>
<column name="org_disambiguated_id" type="bigint">
<constraints nullable="false" />
</column>
<column name="date_created" type="TIMESTAMP WITH TIME ZONE" />
<column name="last_modified" type="TIMESTAMP WITH TIME ZONE" />
</createTable>

<sql>ALTER TABLE email_domain_to_org_id ADD CONSTRAINT email_domain_fk FOREIGN KEY (email_domian_id) REFERENCES email_domain (id);</sql>
<sql>ALTER TABLE email_domain_to_org_id ADD CONSTRAINT org_disambiguated_id_fk FOREIGN KEY (org_disambiguated_id) REFERENCES org_disambiguated (id);</sql>
<sql>create index email_domain_to_org_id_domain_index on email_domain_to_org_id(email_domian_id);</sql>
<sql>create index email_domain_to_org_id_org_index on email_domain_to_org_id(org_disambiguated_id);</sql>
</changeSet>

<changeSet id="CREATE-SEQUENCES" author="Angel Montenegro" dbms="postgresql">
<preConditions onFail="MARK_RAN">
<not>
<sequenceExists sequenceName="email_domain_seq"/>
<sequenceExists sequenceName="email_domain_to_org_id_seq"/>
</not>
</preConditions>
<createSequence sequenceName="email_domain_seq" startValue="1000" />
<createSequence sequenceName="email_domain_to_org_id_seq" startValue="1000" />
</changeSet>

<changeSet id="CREATE-AUTOCOLS" author="Angel Montenegro" dbms="hsqldb">
<addAutoIncrement tableName="email_domain" columnName="id" columnDataType="bigint"/>
<addAutoIncrement tableName="email_domain_to_org_id" columnName="id" columnDataType="bigint"/>
</changeSet>

<changeSet id="EMAIL-DOMAIN-INDEX" author="Angel Montenegro" dbms="postgresql">
<preConditions onFail="MARK_RAN">
<not>
<indexExists indexName="email_domain_domain_index" tableName="email_domain" />
</not>
</preConditions>
<sql>create index email_domain_domain_index on email_domain(email_domain);</sql>
</changeSet>

<changeSet id="GRANT-READ-PERMISSIONS-TO-ORCIDRO" author="Angel Montenegro" dbms="postgresql">
<sql>GRANT SELECT ON email_domain to orcidro;</sql>
<sql>GRANT SELECT ON email_domain_to_org_id to orcidro;</sql>
</changeSet>

</databaseChangeLog>

0 comments on commit 529c463

Please sign in to comment.