From 2ddeea37c29bbe9258c211f7b79a1ae1fcf43c8e Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Sat, 18 Apr 2020 17:27:06 -0400 Subject: [PATCH] Work on multitenancy --- .../ca/uhn/hapi/fhir/docs/files.properties | 1 + .../docs/images/jpa_erd_resource_links.svg | 2 +- .../fhir/docs/images/jpa_erd_resources.svg | 2 +- .../uhn/hapi/fhir/docs/server_jpa/schema.md | 311 +++++++++++++++++- .../jpa/model/entity/BaseHasResource.java | 1 - 5 files changed, 306 insertions(+), 11 deletions(-) diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/files.properties b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/files.properties index a95a0c52e40..b766e3fa56f 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/files.properties +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/files.properties @@ -41,6 +41,7 @@ section.server_jpa.title=JPA Server page.server_jpa.introduction=Introduction page.server_jpa.get_started=Get Started ⚡ page.server_jpa.architecture=Architecture +page.server_jpa.schema=Database Schema page.server_jpa.configuration=Configuration page.server_jpa.search=Search page.server_jpa.performance=Performance diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/images/jpa_erd_resource_links.svg b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/images/jpa_erd_resource_links.svg index 7bc3188c8cc..35602100172 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/images/jpa_erd_resource_links.svg +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/images/jpa_erd_resource_links.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/images/jpa_erd_resources.svg b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/images/jpa_erd_resources.svg index 4ebc5af86cf..759a50a4bfe 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/images/jpa_erd_resources.svg +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/images/jpa_erd_resources.svg @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa/schema.md b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa/schema.md index 40ec00ff5e2..ed69f90b0f9 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa/schema.md +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa/schema.md @@ -4,7 +4,7 @@ It contains a description of the tables within the HAPI FHIR JPA database. Note that columns are shown using Java datatypes as opposed to SQL datatypes, because the exact SQL datatype used will vary depending on the underlying database platform. -# Concepts: PID +# Background: Persistent IDs (PIDs) The HAPI FHIR JPA schema relies heavily on the concept of internal persistent IDs on tables, using a Java type of Long (8-byte integer, which translates to an *int8* or *number(19)* on various database platforms). @@ -12,16 +12,118 @@ Many tables use an internal persistent ID as their primary key, allowing the fle The persistent ID column is generally called `PID` in the database schema, although there are exceptions. -# Individual Resources: HFJ_RESOURCE, HFJ_RES_VER, HFJ_FORCED_ID - -Resources - # HFJ_RESOURCE: Resource Master Table +Resources + The HFJ_RESOURCE table indicates a single resource of any type in the database. For example, the resource `Patient/1` will have exactly one row in this table, representing all versions of the resource. +## Columns + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameRelationshipsDatatypeNullableDescription
PARTITION_IDIntegerNullable + This is the optional partition ID, if the resource is in a partition. See Partitioning. +
PARTITION_DATETimestampNullable + This is the optional partition date, if the resource is in a partition. See Partitioning. +
RES_VERLong + This is the current version ID of the resource. Will contain 1 when the resource is first + created, 2 the first time it is updated, etc. + This column is equivalent to the HFJ_RES_VER.RES_VER + column, although it does not have a foreign-key dependency in order to allow selective expunge of versions + when necessary. Not to be confused with RES_VERSION below. +
RES_VERSIONString + This column contains the FHIR version associated with this resource, using a constant drawn + from FhirVersionEnum. + Not to be confused with RES_VER above. +
RES_TYPEString + Contains the resource type (e.g. Patient) +
HASH_SHA256Long + This column contains a SHA-256 hash of the current resource contents, exclusive of resource metadata. + This is used in order to detect NO-OP writes to the resource. +
RES_PUBLISHEDTimestamp + Contains the date that the first version of the resource was created. +
RES_UPDATEDTimestamp + Contains the date that the most recent version of the resource was created. +
RES_DELETED_ATTimestampNullable + If the most recent version of the resource is a delete, this contains the timestamp at which + the resource was deleted. Otherwise, contains NULL. +
+ +
@@ -31,6 +133,86 @@ The HFJ_RES_VER table contains individual versions of a resource. If the resourc The complete raw contents of the resource is stored in the `RES_TEXT` column, using the encoding specified in the `RES_ENCODING` column. +## Columns + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameRelationshipsDatatypeNullableDescription
PARTITION_IDIntegerNullable + This is the optional partition ID, if the resource is in a partition. See Partitioning. +
PARTITION_DATETimestampNullable + This is the optional partition date, if the resource is in a partition. See Partitioning. +
PIDPKLong + This is the row persistent ID. +
RES_IDFK to HFJ_RESOURCELong + This is the persistent ID of the resource being versioned. +
RES_VERLong + Contains the specific version (starting with 1) of the resource that this row corresponds to. +
RES_ENCODINGString + Describes the encoding of the resource being used to store this resource in RES_TEXT. See + Encodings below for allowable values. +
RES_TEXTbyte[] + Contains the actual full text of the resource being stored. +
+ ## Encodings @@ -60,12 +242,72 @@ However, when client-assigned IDs are used, these may contain text values in ord If the server has been configured with a [Resource Server ID Strategy](/apidocs/hapi-fhir-jpaserver-api/undefined/ca/uhn/fhir/jpa/api/config/DaoConfig.html#setResourceServerIdStrategy(ca.uhn.fhir.jpa.api.config.DaoConfig.IdStrategyEnum)) of [UUID](/apidocs/hapi-fhir-jpaserver-api/undefined/ca/uhn/fhir/jpa/api/config/DaoConfig.IdStrategyEnum.html#UUID), or the server has been configured with a [Resource Client ID Strategy](/apidocs/hapi-fhir-jpaserver-api/undefined/ca/uhn/fhir/jpa/api/config/DaoConfig.html#setResourceClientIdStrategy(ca.uhn.fhir.jpa.api.config.DaoConfig.ClientIdStrategyEnum)) of [ANY](/apidocs/hapi-fhir-jpaserver-api/undefined/ca/uhn/fhir/jpa/api/config/DaoConfig.ClientIdStrategyEnum.html#ANY) the server will create a Forced ID for all resources (not only resources having textual IDs). +## Columns + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameRelationshipsDatatypeNullableDescription
PARTITION_IDIntegerNullable + This is the optional partition ID, if the resource is in a partition. See Partitioning. +
PARTITION_DATETimestampNullable + This is the optional partition date, if the resource is in a partition. See Partitioning. +
PIDPKLong + This is the row persistent ID. +
RESOURCE_PIDFK to HFJ_RESOURCELong + This is the persistent ID of the resource being versioned. +
FORCED_IDString + Contains the specific version (starting with 1) of the resource that this row corresponds to. +
# HFJ_RES_LINK: Search Links -Resources +Resources When a resource is created or updated, it is indexed for searching. Any search parameters of type [Reference](http://hl7.org/fhir/search.html#reference) are resolved, and one or more rows may be created in the **HFJ_RES_LINK** table. @@ -75,37 +317,89 @@ When a resource is created or updated, it is indexed for searching. Any search p Name + Relationships Datatype + Nullable Description + + PARTITION_ID + + Integer + Nullable + + This is the optional partition ID, if the resource is in a partition. See Partitioning. + Note that the partition indicated by the PARTITION_ID and PARTITION_DATE columns refers to the partition + of the SOURCE resource, and not necessarily the TARGET. + + + + PARTITION_DATE + + Timestamp + Nullable + + This is the optional partition date, if the resource is in a partition. See Partitioning. + Note that the partition indicated by the PARTITION_ID and PARTITION_DATE columns refers to the partition + of the SOURCE resource, and not necessarily the TARGET. + + PID + Long + Holds the persistent ID SRC_PATH + String + Contains the FHIRPath expression within the source resource containing the path to the target resource, as supplied by the SearchParameter resource that defined the link. SRC_RESOURCE_ID + Long + Contains a FK reference to the resource containing the link to the target resource. TARGET_RESOURCE_ID + Long + Nullable - Contains a FK reference to the resource that is the target resource. + Contains a FK reference to the resource that is the target resource. Will not be populated if the link contains + a reference to an external resource, or a canonical reference. + + + + TARGET_RESOURCE_URL + + String + Nullable + + If this row contains a reference to an external resource or a canonical reference, this column will contain + the absolute URL. + + + + SP_UPDATED + + Timestamp + + + Contains the last updated timestamp for this row. @@ -113,6 +407,7 @@ When a resource is created or updated, it is indexed for searching. Any search p -# HFJ_SPIDX_xxx: Search Indexes +# Background: Search Indexes The HFJ_SPIDX (Search Parameter Index) tables are used to index resources for searching. When a resource is created or updated, a set of rows in these tables will be added. These are used for finding appropriate rows to return when performing FHIR searches. + diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/BaseHasResource.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/BaseHasResource.java index 97b0b46f6c5..a1bf1ff9ff7 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/BaseHasResource.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/entity/BaseHasResource.java @@ -42,7 +42,6 @@ public abstract class BaseHasResource extends BasePartitionable implements IBase @Temporal(TemporalType.TIMESTAMP) private Date myDeleted; - // TODO: move to resource history table @Column(name = "RES_VERSION", nullable = true, length = 7) @Enumerated(EnumType.STRING) @OptimisticLock(excluded = true)