From 64a2df326a46805c777e0fcecf049506a6b7eff8 Mon Sep 17 00:00:00 2001 From: "emmanuel.duchastenier@bonitasoft.com" Date: Fri, 20 Dec 2024 10:24:06 +0100 Subject: [PATCH] chore(MTR): remove tenantid from application and related objects (#3293) 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 --- .../application/ApplicationQueriesTest.java | 7 +- .../test/persistence/jdbc/JdbcRowMapper.java | 2 +- .../repository/TestRepository.java | 6 + .../main/resources/sql/h2/createTables.sql | 126 +++++++++-------- .../resources/sql/h2/postCreateStructure.sql | 21 --- .../resources/sql/h2/preDropStructure.sql | 18 +-- .../resources/sql/postgres/createTables.sql | 131 +++++++++--------- .../sql/postgres/postCreateStructure.sql | 22 --- .../sql/postgres/preDropStructure.sql | 18 +-- .../model/AbstractSApplication.java | 9 +- .../application/model/SApplicationMenu.java | 9 +- .../application/model/SApplicationPage.java | 9 +- .../bonitasoft/engine/page/AbstractSPage.java | 9 +- .../engine/page/impl/SPageImplAssert.java | 24 ---- .../engine/page/impl/SPageImplTest.java | 3 +- .../engine/profile/model/SProfile.java | 14 +- 16 files changed, 174 insertions(+), 254 deletions(-) diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/application/ApplicationQueriesTest.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/application/ApplicationQueriesTest.java index 6d46a53427e..71b6decd07a 100755 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/application/ApplicationQueriesTest.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/application/ApplicationQueriesTest.java @@ -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; @@ -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 @@ -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); diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/jdbc/JdbcRowMapper.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/jdbc/JdbcRowMapper.java index fc86a561f15..23816b00525 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/jdbc/JdbcRowMapper.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/jdbc/JdbcRowMapper.java @@ -53,7 +53,7 @@ public class JdbcRowMapper implements RowMapper> { "oracle", new OracleValueConverter()); public JdbcRowMapper() { - log.info("Detected DB vendor: {}", dbVendor); + log.debug("Detected DB vendor: {}", dbVendor); } /** diff --git a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/repository/TestRepository.java b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/repository/TestRepository.java index 1e6a328927d..b003d0d806f 100644 --- a/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/repository/TestRepository.java +++ b/bonita-integration-tests/bonita-query-tests/src/test/java/org/bonitasoft/engine/test/persistence/repository/TestRepository.java @@ -68,6 +68,12 @@ public T getById(final Class T getById(final Class clazz, + long id) { + return (T) getSession().get(clazz, id); + } + public Long selectCount(String queryName, Pair... parameters) { Query namedQuery = getNamedQuery(queryName); setParameters(namedQuery, parameters); diff --git a/platform/platform-resources/src/main/resources/sql/h2/createTables.sql b/platform/platform-resources/src/main/resources/sql/h2/createTables.sql index 8432ec15470..3da2d8ad9e2 100644 --- a/platform/platform-resources/src/main/resources/sql/h2/createTables.sql +++ b/platform/platform-resources/src/main/resources/sql/h2/createTables.sql @@ -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, @@ -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); @@ -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, @@ -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, diff --git a/platform/platform-resources/src/main/resources/sql/h2/postCreateStructure.sql b/platform/platform-resources/src/main/resources/sql/h2/postCreateStructure.sql index 3211dc2e2a5..82a0805924d 100644 --- a/platform/platform-resources/src/main/resources/sql/h2/postCreateStructure.sql +++ b/platform/platform-resources/src/main/resources/sql/h2/postCreateStructure.sql @@ -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); @@ -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; diff --git a/platform/platform-resources/src/main/resources/sql/h2/preDropStructure.sql b/platform/platform-resources/src/main/resources/sql/h2/preDropStructure.sql index 3c9d3054fe2..4af463880ef 100644 --- a/platform/platform-resources/src/main/resources/sql/h2/preDropStructure.sql +++ b/platform/platform-resources/src/main/resources/sql/h2/preDropStructure.sql @@ -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; diff --git a/platform/platform-resources/src/main/resources/sql/postgres/createTables.sql b/platform/platform-resources/src/main/resources/sql/postgres/createTables.sql index 85b7c280ad2..346d7646fa8 100644 --- a/platform/platform-resources/src/main/resources/sql/postgres/createTables.sql +++ b/platform/platform-resources/src/main/resources/sql/postgres/createTables.sql @@ -503,8 +503,53 @@ CREATE TABLE processsupervisor ( PRIMARY KEY (tenantid, id) ); -CREATE TABLE business_app ( +CREATE TABLE page ( + id INT8 NOT NULL, + name VARCHAR(255) NOT NULL, + displayName VARCHAR(255) NOT NULL, + description TEXT, + installationDate INT8 NOT NULL, + installedBy INT8 NOT NULL, + provided BOOLEAN, + editable BOOLEAN, + removable BOOLEAN, + lastModificationDate INT8 NOT NULL, + lastUpdatedBy INT8 NOT NULL, + contentName VARCHAR(280) NOT NULL, + content BYTEA, + contentType VARCHAR(50) NOT NULL, + processDefinitionId INT8 NOT NULL, + pageHash VARCHAR(32), + CONSTRAINT pk_page PRIMARY KEY (id), + CONSTRAINT uk_page_name_processdefinitionid UNIQUE (name, processDefinitionId) +); + +CREATE TABLE profile ( + id INT8 NOT NULL, + isDefault BOOLEAN NOT NULL, + name VARCHAR(50) NOT NULL, + description TEXT, + creationDate INT8 NOT NULL, + createdBy INT8 NOT NULL, + lastUpdateDate INT8 NOT NULL, + lastUpdatedBy INT8 NOT NULL, + CONSTRAINT uk_profile_name UNIQUE (name), + CONSTRAINT pk_profile PRIMARY KEY (id) +); + +CREATE TABLE profilemember ( tenantId INT8 NOT NULL, + id INT8 NOT NULL, + profileId INT8 NOT NULL, + userId INT8 NOT NULL, + groupId INT8 NOT NULL, + roleId INT8 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 INT8 NOT NULL, token VARCHAR(50) NOT NULL, version VARCHAR(50) NOT NULL, @@ -524,45 +569,49 @@ 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); - 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); +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 TABLE business_app_page ( - tenantId INT8 NOT NULL, id INT8 NOT NULL, applicationId INT8 NOT NULL, pageId INT8 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); - CREATE INDEX idx_app_page_token ON business_app_page (applicationId, token); CREATE INDEX idx_app_page_pageId ON business_app_page (pageId); +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 TABLE business_app_menu ( - tenantId INT8 NOT NULL, id INT8 NOT NULL, displayName VARCHAR(255) NOT NULL, applicationId INT8 NOT NULL, applicationPageId INT8, parentId INT8, - index_ INT8 + index_ INT8, + CONSTRAINT pk_business_app_menu PRIMARY KEY (id) ); - -ALTER TABLE business_app_menu ADD CONSTRAINT pk_business_app_menu PRIMARY KEY (tenantid, id); - CREATE INDEX idx_app_menu_app ON business_app_menu (applicationId); CREATE INDEX idx_app_menu_page ON business_app_menu (applicationPageId); CREATE INDEX idx_app_menu_parent ON business_app_menu (parentId); +-- 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 TABLE command ( tenantid INT8 NOT NULL, @@ -824,30 +873,6 @@ CREATE TABLE queriable_log ( PRIMARY KEY (tenantid, id) ); -CREATE TABLE page ( - tenantId INT8 NOT NULL, - id INT8 NOT NULL, - name VARCHAR(255) NOT NULL, - displayName VARCHAR(255) NOT NULL, - description TEXT, - installationDate INT8 NOT NULL, - installedBy INT8 NOT NULL, - provided BOOLEAN, - editable BOOLEAN, - removable BOOLEAN, - lastModificationDate INT8 NOT NULL, - lastUpdatedBy INT8 NOT NULL, - contentName VARCHAR(280) NOT NULL, - content BYTEA, - contentType VARCHAR(50) NOT NULL, - processDefinitionId INT8 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 INT8 NOT NULL, id INT8 NOT NULL, @@ -886,30 +911,6 @@ CREATE TABLE platformCommand ( description TEXT, IMPLEMENTATION VARCHAR(100) NOT NULL ); -CREATE TABLE profile ( - tenantId INT8 NOT NULL, - id INT8 NOT NULL, - isDefault BOOLEAN NOT NULL, - name VARCHAR(50) NOT NULL, - description TEXT, - creationDate INT8 NOT NULL, - createdBy INT8 NOT NULL, - lastUpdateDate INT8 NOT NULL, - lastUpdatedBy INT8 NOT NULL, - UNIQUE (tenantId, name), - PRIMARY KEY (tenantId, id) -); - -CREATE TABLE profilemember ( - tenantId INT8 NOT NULL, - id INT8 NOT NULL, - profileId INT8 NOT NULL, - userId INT8 NOT NULL, - groupId INT8 NOT NULL, - roleId INT8 NOT NULL, - UNIQUE (tenantId, profileId, userId, groupId, roleId), - PRIMARY KEY (tenantId, id) -); CREATE TABLE job_desc ( tenantid INT8 NOT NULL, id INT8 NOT NULL, diff --git a/platform/platform-resources/src/main/resources/sql/postgres/postCreateStructure.sql b/platform/platform-resources/src/main/resources/sql/postgres/postCreateStructure.sql index dd3e967489d..82a0805924d 100644 --- a/platform/platform-resources/src/main/resources/sql/postgres/postCreateStructure.sql +++ b/platform/platform-resources/src/main/resources/sql/postgres/postCreateStructure.sql @@ -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); @@ -32,29 +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; diff --git a/platform/platform-resources/src/main/resources/sql/postgres/preDropStructure.sql b/platform/platform-resources/src/main/resources/sql/postgres/preDropStructure.sql index 21228489065..9807ebbefa3 100644 --- a/platform/platform-resources/src/main/resources/sql/postgres/preDropStructure.sql +++ b/platform/platform-resources/src/main/resources/sql/postgres/preDropStructure.sql @@ -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; -- ------------------------ Foreign Keys to disable if archiving is on another BD ------------------ diff --git a/services/bonita-business-application/src/main/java/org/bonitasoft/engine/business/application/model/AbstractSApplication.java b/services/bonita-business-application/src/main/java/org/bonitasoft/engine/business/application/model/AbstractSApplication.java index f17c0787e42..0d0ead07e35 100644 --- a/services/bonita-business-application/src/main/java/org/bonitasoft/engine/business/application/model/AbstractSApplication.java +++ b/services/bonita-business-application/src/main/java/org/bonitasoft/engine/business/application/model/AbstractSApplication.java @@ -15,19 +15,16 @@ import javax.persistence.Column; import javax.persistence.Id; -import javax.persistence.IdClass; import javax.persistence.MappedSuperclass; import lombok.Data; import lombok.NoArgsConstructor; -import org.bonitasoft.engine.persistence.PersistentObject; -import org.bonitasoft.engine.persistence.PersistentObjectId; +import org.bonitasoft.engine.persistence.PlatformPersistentObject; @Data @NoArgsConstructor @MappedSuperclass -@IdClass(PersistentObjectId.class) -public abstract class AbstractSApplication implements PersistentObject { +public abstract class AbstractSApplication implements PlatformPersistentObject { public static final String ID = "id"; public static final String TOKEN = "token"; @@ -49,8 +46,6 @@ public abstract class AbstractSApplication implements PersistentObject { public static final String INTERNAL_PROFILE = "internalProfile"; public static final String LINK = "isLink"; - @Id - private long tenantId; @Id private long id; diff --git a/services/bonita-business-application/src/main/java/org/bonitasoft/engine/business/application/model/SApplicationMenu.java b/services/bonita-business-application/src/main/java/org/bonitasoft/engine/business/application/model/SApplicationMenu.java index 02a9e02f413..793020b1f73 100755 --- a/services/bonita-business-application/src/main/java/org/bonitasoft/engine/business/application/model/SApplicationMenu.java +++ b/services/bonita-business-application/src/main/java/org/bonitasoft/engine/business/application/model/SApplicationMenu.java @@ -16,15 +16,13 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; -import javax.persistence.IdClass; import javax.persistence.Table; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import org.bonitasoft.engine.persistence.PersistentObject; -import org.bonitasoft.engine.persistence.PersistentObjectId; +import org.bonitasoft.engine.persistence.PlatformPersistentObject; @Data @NoArgsConstructor @@ -32,8 +30,7 @@ @Builder @Entity @Table(name = "business_app_menu") -@IdClass(PersistentObjectId.class) -public class SApplicationMenu implements PersistentObject { +public class SApplicationMenu implements PlatformPersistentObject { public static String ID = "id"; public static String DISPLAY_NAME = "displayName"; @@ -43,8 +40,6 @@ public class SApplicationMenu implements PersistentObject { public static String INDEX = "index"; @Id private long id; - @Id - private long tenantId; @Column private String displayName; @Column diff --git a/services/bonita-business-application/src/main/java/org/bonitasoft/engine/business/application/model/SApplicationPage.java b/services/bonita-business-application/src/main/java/org/bonitasoft/engine/business/application/model/SApplicationPage.java index e284ab17ab5..d3b6f95a354 100755 --- a/services/bonita-business-application/src/main/java/org/bonitasoft/engine/business/application/model/SApplicationPage.java +++ b/services/bonita-business-application/src/main/java/org/bonitasoft/engine/business/application/model/SApplicationPage.java @@ -17,15 +17,13 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; -import javax.persistence.IdClass; import javax.persistence.Table; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import org.bonitasoft.engine.persistence.PersistentObject; -import org.bonitasoft.engine.persistence.PersistentObjectId; +import org.bonitasoft.engine.persistence.PlatformPersistentObject; /** * @author Elias Ricken de Medeiros @@ -36,9 +34,8 @@ @Builder @Entity @Table(name = "business_app_page") -@IdClass(PersistentObjectId.class) @Cacheable(false) -public class SApplicationPage implements PersistentObject { +public class SApplicationPage implements PlatformPersistentObject { public static final String ID = "id"; public static final String TOKEN = "token"; @@ -46,8 +43,6 @@ public class SApplicationPage implements PersistentObject { public static final String APPLICATION_ID = "applicationId"; @Id private long id; - @Id - private long tenantId; @Column private long applicationId; @Column diff --git a/services/bonita-page/src/main/java/org/bonitasoft/engine/page/AbstractSPage.java b/services/bonita-page/src/main/java/org/bonitasoft/engine/page/AbstractSPage.java index e193d3f65bc..0103ced326d 100644 --- a/services/bonita-page/src/main/java/org/bonitasoft/engine/page/AbstractSPage.java +++ b/services/bonita-page/src/main/java/org/bonitasoft/engine/page/AbstractSPage.java @@ -14,25 +14,20 @@ package org.bonitasoft.engine.page; import javax.persistence.Id; -import javax.persistence.IdClass; import javax.persistence.MappedSuperclass; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; -import org.bonitasoft.engine.persistence.PersistentObject; -import org.bonitasoft.engine.persistence.PersistentObjectId; +import org.bonitasoft.engine.persistence.PlatformPersistentObject; @Data @SuperBuilder @NoArgsConstructor @MappedSuperclass -@IdClass(PersistentObjectId.class) -public class AbstractSPage implements PersistentObject { +public class AbstractSPage implements PlatformPersistentObject { - @Id - private long tenantId; @Id private long id; diff --git a/services/bonita-page/src/test/java/org/bonitasoft/engine/page/impl/SPageImplAssert.java b/services/bonita-page/src/test/java/org/bonitasoft/engine/page/impl/SPageImplAssert.java index 4fe4f59e9c8..387e242ea9e 100644 --- a/services/bonita-page/src/test/java/org/bonitasoft/engine/page/impl/SPageImplAssert.java +++ b/services/bonita-page/src/test/java/org/bonitasoft/engine/page/impl/SPageImplAssert.java @@ -352,28 +352,4 @@ public SPageImplAssert isNotProvided() { return this; } - /** - * Verifies that the actual SPageImpl's tenantId is equal to the given one. - * - * @param tenantId the given tenantId to compare the actual SPageImpl's tenantId to. - * @return this assertion object. - * @throws AssertionError - if the actual SPageImpl's tenantId is not equal to the given one. - */ - public SPageImplAssert hasTenantId(long tenantId) { - // check that actual SPageImpl we want to make assertions on is not null. - isNotNull(); - - // we overrides the default error message with a more explicit one - String errorMessage = format("\nExpected <%s> tenantId to be:\n <%s>\n but was:\n <%s>", actual, tenantId, - actual.getTenantId()); - - // check - if (actual.getTenantId() != tenantId) { - throw new AssertionError(errorMessage); - } - - // return the current assertion for method chaining - return this; - } - } diff --git a/services/bonita-page/src/test/java/org/bonitasoft/engine/page/impl/SPageImplTest.java b/services/bonita-page/src/test/java/org/bonitasoft/engine/page/impl/SPageImplTest.java index e2abc317970..f49ee5b407d 100644 --- a/services/bonita-page/src/test/java/org/bonitasoft/engine/page/impl/SPageImplTest.java +++ b/services/bonita-page/src/test/java/org/bonitasoft/engine/page/impl/SPageImplTest.java @@ -61,8 +61,7 @@ public void should_set_all_fields() { .hasContentType(SContentType.PAGE) .hasLastUpdatedBy(LAST_UPDATED_BY) .hasInstalledBy(INSTALLED_BY) - .hasId(ID) - .hasTenantId(TENANT_ID); + .hasId(ID); } diff --git a/services/bonita-profile/src/main/java/org/bonitasoft/engine/profile/model/SProfile.java b/services/bonita-profile/src/main/java/org/bonitasoft/engine/profile/model/SProfile.java index bf4219279b7..bd09e5ce290 100644 --- a/services/bonita-profile/src/main/java/org/bonitasoft/engine/profile/model/SProfile.java +++ b/services/bonita-profile/src/main/java/org/bonitasoft/engine/profile/model/SProfile.java @@ -13,14 +13,16 @@ **/ package org.bonitasoft.engine.profile.model; -import javax.persistence.*; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import org.bonitasoft.engine.persistence.PersistentObject; -import org.bonitasoft.engine.persistence.PersistentObjectId; +import org.bonitasoft.engine.persistence.PlatformPersistentObject; @Data @NoArgsConstructor @@ -28,8 +30,7 @@ @Builder(toBuilder = true) @Entity @Table(name = "profile") -@IdClass(PersistentObjectId.class) -public class SProfile implements PersistentObject { +public class SProfile implements PlatformPersistentObject { public static final String PROFILE_IDS = "profileIds"; public static final String ICON_PATH = "iconPath"; @@ -43,8 +44,6 @@ public class SProfile implements PersistentObject { public static final String LAST_UPDATED_BY = "lastUpdatedBy"; @Id private long id; - @Id - private long tenantId; @Column private boolean isDefault; @Column @@ -62,7 +61,6 @@ public class SProfile implements PersistentObject { public SProfile(final SProfile profile) { super(); - tenantId = profile.getTenantId(); id = profile.getId(); isDefault = profile.isDefault(); name = profile.getName();