Skip to content

Commit

Permalink
chore(MTR): remove tenantid from application and related objects (#3293)
Browse files Browse the repository at this point in the history
Sub-classes:
* SApplication (org.bonitasoft.engine.business.application.model)
* SApplicationWithIcon
(org.bonitasoft.engine.business.application.model)
* SApplicationPage
* SApplicationMenu

* also remove tenantId from Profile & Page, as they are dependencies of Application* objects (+page + menu)

MTR = Multi-tenancy removal

Relates to https://bonitasoft.atlassian.net/browse/PROD-379
  • Loading branch information
educhastenier authored Dec 20, 2024
1 parent a0fd5ad commit 64a2df3
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 254 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.bonitasoft.engine.test.persistence.builder.ApplicationPageBuilder.anApplicationPage;
import static org.bonitasoft.engine.test.persistence.builder.GroupBuilder.aGroup;
import static org.bonitasoft.engine.test.persistence.builder.PageBuilder.aPage;
import static org.bonitasoft.engine.test.persistence.builder.PersistentObjectBuilder.DEFAULT_TENANT_ID;
import static org.bonitasoft.engine.test.persistence.builder.ProfileBuilder.aProfile;
import static org.bonitasoft.engine.test.persistence.builder.ProfileMemberBuilder.aProfileMember;
import static org.bonitasoft.engine.test.persistence.builder.RoleBuilder.aRole;
Expand Down Expand Up @@ -73,8 +72,7 @@ public void getApplicationByToken_returns_the_application_with_the_given_token()
final SApplication retrievedApp = repository.getApplicationByToken("app2");

//then
assertThat(retrievedApp)
.isEqualTo(repository.getById(SApplication.class, application2.getId(), DEFAULT_TENANT_ID));
assertThat(retrievedApp).isEqualTo(repository.getById(SApplication.class, application2.getId()));
}

@Test
Expand All @@ -89,8 +87,7 @@ public void getApplication_returns_the_application_with_the_given_id() {
.withVersion("1.0").withPath("app1").build());

//when
final SApplicationWithIcon retrievedApp = repository.getById(SApplicationWithIcon.class, application2.getId(),
DEFAULT_TENANT_ID);
final SApplicationWithIcon retrievedApp = repository.getById(SApplicationWithIcon.class, application2.getId());

//then
assertThat(retrievedApp).isEqualTo(application2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class JdbcRowMapper implements RowMapper<Map<String, Object>> {
"oracle", new OracleValueConverter());

public JdbcRowMapper() {
log.info("Detected DB vendor: {}", dbVendor);
log.debug("Detected DB vendor: {}", dbVendor);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ public <T extends PersistentObject> T getById(final Class<? extends PersistentOb
new PersistentObjectId(id, tenantId));
}

@SuppressWarnings("unchecked")
public <T extends PlatformPersistentObject> T getById(final Class<? extends PlatformPersistentObject> clazz,
long id) {
return (T) getSession().get(clazz, id);
}

public Long selectCount(String queryName, Pair... parameters) {
Query namedQuery = getNamedQuery(queryName);
setParameters(namedQuery, parameters);
Expand Down
126 changes: 66 additions & 60 deletions platform/platform-resources/src/main/resources/sql/h2/createTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,53 @@ CREATE TABLE processsupervisor (
PRIMARY KEY (tenantid, id)
);

CREATE TABLE business_app (
CREATE TABLE page (
id BIGINT NOT NULL,
name VARCHAR(255) NOT NULL,
displayName VARCHAR(255) NOT NULL,
description LONGVARCHAR,
installationDate BIGINT NOT NULL,
installedBy BIGINT NOT NULL,
provided BOOLEAN,
editable BOOLEAN,
removable BOOLEAN,
lastModificationDate BIGINT NOT NULL,
lastUpdatedBy BIGINT NOT NULL,
contentName VARCHAR(280) NOT NULL,
content LONGBLOB,
contentType VARCHAR(50) NOT NULL,
processDefinitionId BIGINT NOT NULL,
pageHash VARCHAR(32),
CONSTRAINT pk_page PRIMARY KEY (id),
CONSTRAINT uk_page_name_processdefinitionid UNIQUE (name, processDefinitionId)
);

CREATE TABLE profile (
id BIGINT NOT NULL,
isDefault BOOLEAN NOT NULL,
name VARCHAR(50) NOT NULL,
description LONGVARCHAR,
creationDate BIGINT NOT NULL,
createdBy BIGINT NOT NULL,
lastUpdateDate BIGINT NOT NULL,
lastUpdatedBy BIGINT NOT NULL,
CONSTRAINT uk_profile_name UNIQUE (name),
CONSTRAINT pk_profile PRIMARY KEY (id)
);

CREATE TABLE profilemember (
tenantId BIGINT NOT NULL,
id BIGINT NOT NULL,
profileId BIGINT NOT NULL,
userId BIGINT NOT NULL,
groupId BIGINT NOT NULL,
roleId BIGINT NOT NULL,
UNIQUE (tenantId, profileId, userId, groupId, roleId),
PRIMARY KEY (tenantId, id)
);
ALTER TABLE profilemember ADD CONSTRAINT fk_profilemember_profileid FOREIGN KEY (profileId) REFERENCES profile(id);

CREATE TABLE business_app (
id BIGINT NOT NULL,
token VARCHAR(50) NOT NULL,
version VARCHAR(50) NOT NULL,
Expand All @@ -523,41 +568,48 @@ CREATE TABLE business_app (
displayName VARCHAR(255) NOT NULL,
editable BOOLEAN,
internalProfile VARCHAR(255),
isLink BOOLEAN DEFAULT FALSE
isLink BOOLEAN DEFAULT FALSE,
CONSTRAINT pk_business_app PRIMARY KEY (id),
CONSTRAINT uk_business_app_token_version UNIQUE (token, version)
);

ALTER TABLE business_app ADD CONSTRAINT pk_business_app PRIMARY KEY (tenantid, id);
ALTER TABLE business_app ADD CONSTRAINT uk_app_token_version UNIQUE (tenantId, token, version);
ALTER TABLE business_app ADD CONSTRAINT fk_business_app_profileid FOREIGN KEY (profileId) REFERENCES profile (id);
ALTER TABLE business_app ADD CONSTRAINT fk_business_app_layoutid FOREIGN KEY (layoutId) REFERENCES page (id);
ALTER TABLE business_app ADD CONSTRAINT fk_business_app_themeid FOREIGN KEY (themeId) REFERENCES page (id);

CREATE INDEX idx_app_token ON business_app (token);
CREATE INDEX idx_app_profile ON business_app (profileId);
CREATE INDEX idx_app_homepage ON business_app (homePageId);

CREATE TABLE business_app_page (
tenantId BIGINT NOT NULL,
id BIGINT NOT NULL,
applicationId BIGINT NOT NULL,
pageId BIGINT NOT NULL,
token VARCHAR(255) NOT NULL
token VARCHAR(255) NOT NULL,
CONSTRAINT pk_business_app_page PRIMARY KEY (id),
CONSTRAINT uk_business_app_page_applicationid_token UNIQUE (applicationId, token)
);

ALTER TABLE business_app_page ADD CONSTRAINT pk_business_app_page PRIMARY KEY (tenantid, id);
ALTER TABLE business_app_page ADD CONSTRAINT uk_app_page_appId_token UNIQUE (tenantId, applicationId, token);
ALTER TABLE business_app_page ADD CONSTRAINT fk_business_app_page_applicationid FOREIGN KEY (applicationId) REFERENCES business_app (id) ON DELETE CASCADE;
ALTER TABLE business_app_page ADD CONSTRAINT fk_business_app_page_pageid FOREIGN KEY (pageId) REFERENCES page (id);

CREATE INDEX idx_app_page_token ON business_app_page (applicationId, token);
CREATE INDEX idx_app_page_pageId ON business_app_page (pageId);

CREATE TABLE business_app_menu (
tenantId BIGINT NOT NULL,
id BIGINT NOT NULL,
displayName VARCHAR(255) NOT NULL,
applicationId BIGINT NOT NULL,
applicationPageId BIGINT,
parentId BIGINT,
index_ BIGINT
index_ BIGINT,
CONSTRAINT pk_business_app_menu PRIMARY KEY (id)
);

ALTER TABLE business_app_menu ADD CONSTRAINT pk_business_app_menu PRIMARY KEY (tenantid, id);
-- cannot have both fk_business_app_menu_applicationid and fk_business_app_menu_applicationpageid because this create to path for deletion of business_app_menu elements:
-- business_app -> business_app_menu
-- business_app -> business_app_page -> business_app_menu
-- this is not allowed in SQL Server
ALTER TABLE business_app_menu ADD CONSTRAINT fk_business_app_menu_applicationid FOREIGN KEY (applicationId) REFERENCES business_app (id);
ALTER TABLE business_app_menu ADD CONSTRAINT fk_business_app_menu_applicationpageid FOREIGN KEY (applicationPageId) REFERENCES business_app_page (id);
ALTER TABLE business_app_menu ADD CONSTRAINT fk_business_app_menu_parentid FOREIGN KEY (parentId) REFERENCES business_app_menu (id);

CREATE INDEX idx_app_menu_app ON business_app_menu (applicationId);
CREATE INDEX idx_app_menu_page ON business_app_menu (applicationPageId);
Expand Down Expand Up @@ -823,28 +875,6 @@ CREATE TABLE queriable_log (
PRIMARY KEY (tenantid, id)
);

CREATE TABLE page (
tenantId BIGINT NOT NULL,
id BIGINT NOT NULL,
name VARCHAR(255) NOT NULL,
displayName VARCHAR(255) NOT NULL,
description LONGVARCHAR,
installationDate BIGINT NOT NULL,
installedBy BIGINT NOT NULL,
provided BOOLEAN,
editable BOOLEAN,
removable BOOLEAN,
lastModificationDate BIGINT NOT NULL,
lastUpdatedBy BIGINT NOT NULL,
contentName VARCHAR(280) NOT NULL,
content LONGBLOB,
contentType VARCHAR(50) NOT NULL,
processDefinitionId BIGINT NOT NULL,
pageHash VARCHAR(32)
);
ALTER TABLE page ADD CONSTRAINT pk_page PRIMARY KEY (tenantid, id);
ALTER TABLE page ADD CONSTRAINT uk_page UNIQUE (tenantId, name, processDefinitionId);

CREATE TABLE sequence (
tenantid BIGINT NOT NULL,
id BIGINT NOT NULL,
Expand Down Expand Up @@ -883,30 +913,6 @@ CREATE TABLE platformCommand (
description LONGVARCHAR,
IMPLEMENTATION VARCHAR(100) NOT NULL
);
CREATE TABLE profile (
tenantId BIGINT NOT NULL,
id BIGINT NOT NULL,
isDefault BOOLEAN NOT NULL,
name VARCHAR(50) NOT NULL,
description LONGVARCHAR,
creationDate BIGINT NOT NULL,
createdBy BIGINT NOT NULL,
lastUpdateDate BIGINT NOT NULL,
lastUpdatedBy BIGINT NOT NULL,
UNIQUE (tenantId, name),
PRIMARY KEY (tenantId, id)
);

CREATE TABLE profilemember (
tenantId BIGINT NOT NULL,
id BIGINT NOT NULL,
profileId BIGINT NOT NULL,
userId BIGINT NOT NULL,
groupId BIGINT NOT NULL,
roleId BIGINT NOT NULL,
UNIQUE (tenantId, profileId, userId, groupId, roleId),
PRIMARY KEY (tenantId, id)
);
CREATE TABLE job_desc (
tenantid BIGINT NOT NULL,
id BIGINT NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ ALTER TABLE process_comment ADD CONSTRAINT fk_process_comment_tenantId FOREIGN K
ALTER TABLE process_definition ADD CONSTRAINT fk_process_definition_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id);
ALTER TABLE process_definition ADD CONSTRAINT fk_process_definition_content FOREIGN KEY (content_tenantid, content_id) REFERENCES process_content(tenantid, id);
ALTER TABLE processsupervisor ADD CONSTRAINT fk_processsupervisor_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id);
ALTER TABLE profile ADD CONSTRAINT fk_profile_tenantId FOREIGN KEY (tenantId) REFERENCES tenant(id);
ALTER TABLE profilemember ADD CONSTRAINT fk_profilemember_tenantId FOREIGN KEY (tenantId) REFERENCES tenant(id);
ALTER TABLE multi_biz_data ADD CONSTRAINT fk_multi_biz_data_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id);
ALTER TABLE ref_biz_data_inst ADD CONSTRAINT fk_ref_biz_data_inst_tenantId FOREIGN KEY (tenantId) REFERENCES tenant(id);
Expand All @@ -32,28 +31,8 @@ ALTER TABLE user_ ADD CONSTRAINT fk_user__tenantId FOREIGN KEY (tenantid) REFERE
ALTER TABLE user_membership ADD CONSTRAINT fk_user_membership_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id);
ALTER TABLE waiting_event ADD CONSTRAINT fk_waiting_event_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id);

ALTER TABLE profilemember ADD CONSTRAINT fk_profilemember_profileId FOREIGN KEY (tenantId, profileId) REFERENCES profile(tenantId, id);
-- ALTER TABLE process_comment ADD CONSTRAINT fk_process_comment_process_instanceId FOREIGN KEY (processInstanceId) REFERENCES process_instance(id);

-- business application
ALTER TABLE business_app ADD CONSTRAINT fk_app_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id);
ALTER TABLE business_app ADD CONSTRAINT fk_app_profileId FOREIGN KEY (tenantid, profileId) REFERENCES profile (tenantid, id);
ALTER TABLE business_app ADD CONSTRAINT fk_app_layoutId FOREIGN KEY (tenantid, layoutId) REFERENCES page (tenantid, id);
ALTER TABLE business_app ADD CONSTRAINT fk_app_themeId FOREIGN KEY (tenantid, themeId) REFERENCES page (tenantid, id);
ALTER TABLE business_app_page ADD CONSTRAINT fk_app_page_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id);
ALTER TABLE business_app_page ADD CONSTRAINT fk_bus_app_id FOREIGN KEY (tenantid, applicationId) REFERENCES business_app (tenantid, id) ON DELETE CASCADE;
ALTER TABLE business_app_page ADD CONSTRAINT fk_page_id FOREIGN KEY (tenantid, pageId) REFERENCES page (tenantid, id);

ALTER TABLE business_app_menu ADD CONSTRAINT fk_app_menu_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id);

-- cannot have both fk_app_menu_appId and fk_app_menu_pageId because this create to path for deletion of business_app_menu elements:
-- business_app -> business_app_menu
-- business_app -> business_app_page -> business_app_menu
-- this is not allowed in SQL Server
ALTER TABLE business_app_menu ADD CONSTRAINT fk_app_menu_appId FOREIGN KEY (tenantid, applicationId) REFERENCES business_app (tenantid, id);
ALTER TABLE business_app_menu ADD CONSTRAINT fk_app_menu_pageId FOREIGN KEY (tenantid, applicationPageId) REFERENCES business_app_page (tenantid, id);
ALTER TABLE business_app_menu ADD CONSTRAINT fk_app_menu_parentId FOREIGN KEY (tenantid, parentId) REFERENCES business_app_menu (tenantid, id);

-- ------------------------ Foreign Keys to disable if archiving is on another BD ------------------
ALTER TABLE arch_document_mapping ADD CONSTRAINT fk_arch_document_mapping_tenantId FOREIGN KEY (tenantid) REFERENCES tenant(id);
ALTER TABLE arch_document_mapping ADD CONSTRAINT fk_archdocmap_docid FOREIGN KEY (tenantid, documentid) REFERENCES document(tenantid, id) ON DELETE CASCADE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ ALTER TABLE user_ DROP CONSTRAINT fk_user__tenantId;
ALTER TABLE user_membership DROP CONSTRAINT fk_user_membership_tenantId;
ALTER TABLE waiting_event DROP CONSTRAINT fk_waiting_event_tenantId;

ALTER TABLE profilemember DROP CONSTRAINT fk_profilemember_profileId;
ALTER TABLE profilemember DROP CONSTRAINT fk_profilemember_profileid;
-- ALTER TABLE process_comment DROP CONSTRAINT fk_process_comment_process_instanceId;

-- business application
ALTER TABLE business_app_menu DROP CONSTRAINT fk_app_menu_tenantId;
ALTER TABLE business_app_menu DROP CONSTRAINT fk_app_menu_appId;
ALTER TABLE business_app_menu DROP CONSTRAINT fk_app_menu_pageId;
ALTER TABLE business_app_menu DROP CONSTRAINT fk_app_menu_parentId;
ALTER TABLE business_app_menu DROP CONSTRAINT fk_business_app_menu_applicationid;
ALTER TABLE business_app_menu DROP CONSTRAINT fk_business_app_menu_applicationpageid;
ALTER TABLE business_app_menu DROP CONSTRAINT fk_business_app_menu_parentid;
ALTER TABLE business_app_page DROP CONSTRAINT fk_app_page_tenantId;
ALTER TABLE business_app_page DROP CONSTRAINT fk_bus_app_id;
ALTER TABLE business_app_page DROP CONSTRAINT fk_page_id;
ALTER TABLE business_app DROP CONSTRAINT fk_app_profileId;
ALTER TABLE business_app_page DROP CONSTRAINT fk_business_app_page_applicationid;
ALTER TABLE business_app_page DROP CONSTRAINT fk_business_app_page_pageid;
ALTER TABLE business_app DROP CONSTRAINT fk_business_app_profileid;
ALTER TABLE business_app DROP CONSTRAINT fk_app_tenantId;
ALTER TABLE business_app DROP CONSTRAINT fk_app_layoutId;
ALTER TABLE business_app DROP CONSTRAINT fk_app_themeId;
ALTER TABLE business_app DROP CONSTRAINT fk_business_app_layoutid;
ALTER TABLE business_app DROP CONSTRAINT fk_business_app_themeid;



Expand Down
Loading

0 comments on commit 64a2df3

Please sign in to comment.