Defining Tenant Schema For Consortia

AuthorAdesh Singh
JIRA task

https://folio-org.atlassian.net/browse/MODFISTO-394 

Define DB schema for storing tenants and create table

https://folio-org.atlassian.net/browse/MODFISTO-400 
Define DB schema for storing user and affiliation associations and create table

Business RequirementsDefine DB schema for storing tenants and create table
Define DB schema for storing user and affiliation associations and create table
Architects ReviewPending
PO reviewPending

Revision History

Version

Date

Owner

Description

Reason

v1.002.28.2023

Adesh Singh

Initial versionAdd DB schema

Overview

Problems

Todo

In scope

Todo

Out Of Scope

Todo

Architecturally Significant Requirements

Solution Design

Todo

Data Model

The "tenants" for consortia will be stored in the mod-consortia module; accordingly, the data schemas and tables described in this document are also for mod-consortia.

There will be 1 table for tenants named tenant. This table will be placed in the mod_consortia schema. 

Liquibase Script

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                   http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">

  <changeSet id="MODFISTO-394@@create-tenant-table" author="singhadesh">

    <createTable tableName="tenant">
      <column name="id" type="text">
        <constraints primaryKey="true" primaryKeyName="pk_tenant_id"/>
      </column>
      <column name="name" type="text">
        <constraints unique="true" nullable="false"/>
      </column>
    </createTable>
  </changeSet>

</databaseChangeLog>

tenant

Data Model and Data example for this table:

ColumnColumn DatatypeSenseis Mendatory?is Unique?Column Data Example
idString
YYf0012346541234
nameString
YYThree Rivers Collage

Data Model

The "user_tenat" is to storing users and affiliations associations

Liquibase Script

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                   http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">

  <changeSet id="MODFISTO-400@@create-user-tenant-table" author="azizbekxm">

    <createTable tableName="user_tenant">
      <column name="id" type="uuid">
        <constraints primaryKey="true" primaryKeyName="pk_id"/>
      </column>
      <column name="user_id" type="uuid">
        <constraints unique="false" nullable="false"/>
      </column>
      <column name="username" type="text">
        <constraints unique="false" nullable="false"/>
      </column>
      <column name="tenant_id" type="text">
        <constraints unique="false" nullable="false"
                     foreignKeyName="fk_tenant_id" referencedTableName="tenant" referencedColumnNames="id" />
      </column>
      <column name="is_primary" type="boolean" defaultValueBoolean="false">
        <constraints unique="false" nullable="false"/>
      </column>
    </createTable>

    <createIndex indexName="user_id_idx" tableName="user_tenant">
      <column name="user_id"/>
    </createIndex>
    <createIndex indexName="user_name_idx" tableName="user_tenant">
      <column name="username"/>
    </createIndex>

  </changeSet>

</databaseChangeLog>


tenant_user

Data Model and Data example for this table:

ColumnColumn Data TypeSenseIs mandatory?Is unique?Notes
idUUIDHow to identify a user and tenant tableYYUUID of user and tenant table and it is primary key
user_idUUIDHow to identify a user?YYUUID of the user
usernameString(text)How to identify a username?YNusername of the user
tenant_idString(text)What tenantId does the user associate with?YNUUID of the affiliation is associated with the user. - Foreign Key to tenant table
is_primaryBooleanis Tenant primary for the user?YNWhether this tenant is the primary tenant for the user.

Entity Relation Diagram