Skip to content

Commit

Permalink
1276039 - Postgres upgrade script (bpms-6.0-to-6.1.sql): null value in
Browse files Browse the repository at this point in the history
column "id" violates not-null constraint
 - added fixes + test for postgres and oracle
  • Loading branch information
krisv committed Oct 29, 2015
1 parent b5b410e commit e77d9c5
Show file tree
Hide file tree
Showing 8 changed files with 484 additions and 47 deletions.
4 changes: 2 additions & 2 deletions jbpm-installer/db/upgrade-scripts/oracle/bpms-6.0-to-6.1.sql
Expand Up @@ -56,8 +56,8 @@ update Task t set name = (select shortText from I18NText where Task_Names_Id = t
update Task t set subject = (select shortText from I18NText where Task_Subjects_Id = t.id);
update Task t set description = (select shortText from I18NText where Task_Descriptions_Id = t.id);

INSERT INTO AuditTaskImpl (activationTime, actualOwner, createdBy, createdOn, deploymentId, description, dueDate, name, parentId, priority, processId, processInstanceId, processSessionId, status, taskId)
SELECT activationTime, actualOwner_id, createdBy_id, createdOn, deploymentId, description, expirationTime, name, parentId, priority,processId, processInstanceId, processSessionId, status, id
INSERT INTO AuditTaskImpl (id, activationTime, actualOwner, createdBy, createdOn, deploymentId, description, dueDate, name, parentId, priority, processId, processInstanceId, processSessionId, status, taskId)
SELECT AUDIT_ID_SEQ.nextval, activationTime, actualOwner_id, createdBy_id, createdOn, deploymentId, description, expirationTime, name, parentId, priority,processId, processInstanceId, processSessionId, status, id
FROM Task;

alter table TaskEvent add workItemId number(19,0);
Expand Down
80 changes: 40 additions & 40 deletions jbpm-installer/db/upgrade-scripts/oracle/jbpm-6.1-to-6.2.sql
@@ -1,41 +1,41 @@
alter table SessionInfo modify ( id number(19,0) );
alter table AuditTaskImpl modify ( processSessionId number(19,0) );
alter table AuditTaskImpl modify ( activationTime timestamp );
alter table AuditTaskImpl modify ( createdOn timestamp );
alter table AuditTaskImpl modify ( dueDate timestamp );
alter table ContextMappingInfo modify ( KSESSION_ID number(19,0) );
alter table Task modify ( processSessionId number(19,0) );

create table DeploymentStore (
id number(19,0) not null,
attributes varchar2(255 char),
DEPLOYMENT_ID varchar2(255 char),
deploymentUnit clob,
state number(10,0),
updateDate timestamp,
primary key (id)
);
alter table DeploymentStore add constraint UK_DeploymentStore_1 unique (DEPLOYMENT_ID);
create sequence DEPLOY_STORE_ID_SEQ;

alter table ProcessInstanceLog add processInstanceDescription varchar2(255 char);
alter table RequestInfo add owner varchar2(255 char);
alter table Task add (
description varchar2(255 char),
name varchar2(255 char),
subject varchar2(255 char)
);

-- update all tasks with its name, subject and description
update Task t set name = (select shortText from I18NText where Task_Names_Id = t.id);
update Task t set subject = (select shortText from I18NText where Task_Subjects_Id = t.id);
update Task t set description = (select shortText from I18NText where Task_Descriptions_Id = t.id);

INSERT INTO AuditTaskImpl (activationTime, actualOwner, createdBy, createdOn, deploymentId, description, dueDate, name, parentId, priority, processId, processInstanceId, processSessionId, status, taskId)
SELECT activationTime, actualOwner_id, createdBy_id, createdOn, deploymentId, description, expirationTime, name, parentId, priority,processId, processInstanceId, processSessionId, status, id
FROM Task;

alter table TaskEvent add workItemId number(19,0);
alter table TaskEvent add processInstanceId number(19,0);
update TaskEvent t set workItemId = (select workItemId from Task where id = t.taskId);
alter table SessionInfo modify ( id number(19,0) );
alter table AuditTaskImpl modify ( processSessionId number(19,0) );
alter table AuditTaskImpl modify ( activationTime timestamp );
alter table AuditTaskImpl modify ( createdOn timestamp );
alter table AuditTaskImpl modify ( dueDate timestamp );
alter table ContextMappingInfo modify ( KSESSION_ID number(19,0) );
alter table Task modify ( processSessionId number(19,0) );
create table DeploymentStore (
id number(19,0) not null,
attributes varchar2(255 char),
DEPLOYMENT_ID varchar2(255 char),
deploymentUnit clob,
state number(10,0),
updateDate timestamp,
primary key (id)
);
alter table DeploymentStore add constraint UK_DeploymentStore_1 unique (DEPLOYMENT_ID);
create sequence DEPLOY_STORE_ID_SEQ;
alter table ProcessInstanceLog add processInstanceDescription varchar2(255 char);
alter table RequestInfo add owner varchar2(255 char);
alter table Task add (
description varchar2(255 char),
name varchar2(255 char),
subject varchar2(255 char)
);
-- update all tasks with its name, subject and description
update Task t set name = (select shortText from I18NText where Task_Names_Id = t.id);
update Task t set subject = (select shortText from I18NText where Task_Subjects_Id = t.id);
update Task t set description = (select shortText from I18NText where Task_Descriptions_Id = t.id);
INSERT INTO AuditTaskImpl (id, activationTime, actualOwner, createdBy, createdOn, deploymentId, description, dueDate, name, parentId, priority, processId, processInstanceId, processSessionId, status, taskId)
SELECT AUDIT_ID_SEQ.nextval, activationTime, actualOwner_id, createdBy_id, createdOn, deploymentId, description, expirationTime, name, parentId, priority,processId, processInstanceId, processSessionId, status, id
FROM Task;
alter table TaskEvent add workItemId number(19,0);
alter table TaskEvent add processInstanceId number(19,0);
update TaskEvent t set workItemId = (select workItemId from Task where id = t.taskId);
update TaskEvent t set processInstanceId = (select processInstanceId from Task where id = t.taskId);
Expand Up @@ -55,8 +55,8 @@ UPDATE Task t SET name = (SELECT shortText FROM I18NText WHERE Task_Names_Id = t
UPDATE Task t SET subject = (SELECT shortText FROM I18NText WHERE Task_Subjects_Id = t.id);
UPDATE Task t SET description = (SELECT shortText FROM I18NText WHERE Task_Descriptions_Id = t.id);

INSERT INTO AuditTaskImpl (activationTime, actualOwner, createdBy, createdOn, deploymentId, description, dueDate, name, parentId, priority, processId, processInstanceId, processSessionId, status, taskId)
SELECT activationTime, actualOwner_id, createdBy_id, createdOn, deploymentId, description, expirationTime, name, parentId, priority,processId, processInstanceId, processSessionId, status, id
INSERT INTO AuditTaskImpl (id, activationTime, actualOwner, createdBy, createdOn, deploymentId, description, dueDate, name, parentId, priority, processId, processInstanceId, processSessionId, status, taskId)
SELECT nextval('AUDIT_ID_SEQ'), activationTime, actualOwner_id, createdBy_id, createdOn, deploymentId, description, expirationTime, name, parentId, priority,processId, processInstanceId, processSessionId, status, id
FROM Task;

ALTER TABLE TaskEvent ADD COLUMN workItemId bigint;
Expand Down
Expand Up @@ -30,8 +30,8 @@ UPDATE Task t SET name = (SELECT shortText FROM I18NText WHERE Task_Names_Id = t
UPDATE Task t SET subject = (SELECT shortText FROM I18NText WHERE Task_Subjects_Id = t.id);
UPDATE Task t SET description = (SELECT shortText FROM I18NText WHERE Task_Descriptions_Id = t.id);

INSERT INTO AuditTaskImpl (activationTime, actualOwner, createdBy, createdOn, deploymentId, description, dueDate, name, parentId, priority, processId, processInstanceId, processSessionId, status, taskId)
SELECT activationTime, actualOwner_id, createdBy_id, createdOn, deploymentId, description, expirationTime, name, parentId, priority,processId, processInstanceId, processSessionId, status, id
INSERT INTO AuditTaskImpl (id, activationTime, actualOwner, createdBy, createdOn, deploymentId, description, dueDate, name, parentId, priority, processId, processInstanceId, processSessionId, status, taskId)
SELECT nextval('AUDIT_ID_SEQ'), activationTime, actualOwner_id, createdBy_id, createdOn, deploymentId, description, expirationTime, name, parentId, priority,processId, processInstanceId, processSessionId, status, id
FROM Task;

ALTER TABLE TaskEvent ADD COLUMN workItemId bigint;
Expand Down
Expand Up @@ -11,6 +11,22 @@

<class>org.jbpm.persistence.scripts.oldentities.ProcessInstanceInfo</class>
<class>org.jbpm.persistence.scripts.oldentities.SessionInfo</class>
<class>org.jbpm.persistence.scripts.oldentities.TaskImpl</class>
<class>org.jbpm.services.task.impl.model.AttachmentImpl</class>
<class>org.jbpm.services.task.impl.model.BooleanExpressionImpl</class>
<class>org.jbpm.services.task.impl.model.CommentImpl</class>
<class>org.jbpm.services.task.impl.model.ContentImpl</class>
<class>org.jbpm.services.task.impl.model.DeadlineImpl</class>
<class>org.jbpm.services.task.impl.model.EmailNotificationHeaderImpl</class>
<class>org.jbpm.services.task.impl.model.EmailNotificationImpl</class>
<class>org.jbpm.services.task.impl.model.EscalationImpl</class>
<class>org.jbpm.services.task.impl.model.GroupImpl</class>
<class>org.jbpm.services.task.impl.model.I18NTextImpl</class>
<class>org.jbpm.services.task.impl.model.NotificationImpl</class>
<class>org.jbpm.services.task.impl.model.OrganizationalEntityImpl</class>
<class>org.jbpm.services.task.impl.model.ReassignmentImpl</class>
<class>org.jbpm.services.task.impl.model.TaskDefImpl</class>
<class>org.jbpm.services.task.impl.model.UserImpl</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.max_fetch_depth" value="3"/>
Expand Down
Expand Up @@ -8,6 +8,7 @@
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -17,23 +18,32 @@
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import bitronix.tm.resource.jdbc.PoolingDataSource;
import org.drools.core.impl.KnowledgeBaseImpl;
import org.drools.persistence.jta.JtaTransactionManager;
import org.jbpm.persistence.map.impl.ProcessCreatorForHelp;
import org.jbpm.persistence.scripts.oldentities.ProcessInstanceInfo;
import org.jbpm.persistence.scripts.oldentities.SessionInfo;
import org.jbpm.persistence.scripts.oldentities.TaskImpl;
import org.jbpm.persistence.scripts.util.SQLCommandUtil;
import org.jbpm.persistence.scripts.util.SQLScriptUtil;
import org.jbpm.persistence.scripts.util.TestsUtil;
import org.jbpm.persistence.util.PersistenceUtil;
import org.kie.api.KieBase;
import org.kie.api.runtime.Environment;
import org.kie.api.runtime.EnvironmentName;
import org.kie.api.task.model.I18NText;
import org.kie.api.task.model.OrganizationalEntity;
import org.kie.internal.KnowledgeBase;
import org.kie.internal.KnowledgeBaseFactory;
import org.kie.internal.persistence.jpa.JPAKnowledgeService;
import org.kie.internal.runtime.StatefulKnowledgeSession;
import org.kie.internal.task.api.TaskModelProvider;
import org.kie.internal.task.api.model.InternalI18NText;
import org.kie.internal.task.api.model.InternalOrganizationalEntity;
import org.kie.internal.task.api.model.InternalPeopleAssignments;
import org.kie.internal.task.api.model.InternalTaskData;

import bitronix.tm.resource.jdbc.PoolingDataSource;

/**
* Central context that hides persistence from tests, so there is no need to work with persistence in the tests
Expand Down Expand Up @@ -132,6 +142,47 @@ public void startAndPersistSomeProcess(final String processId) {
session = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, environment);
session.startProcess(processId);
}

public void createSomeTask() {
testIsInitialized();
TaskImpl task = new TaskImpl();
InternalI18NText name = (InternalI18NText) TaskModelProvider.getFactory().newI18NText();
name.setText("Some Task");
List<I18NText> names = new ArrayList<I18NText>();
names.add(name);
task.setNames(names);
InternalTaskData taskData = (InternalTaskData) TaskModelProvider.getFactory().newTaskData();
taskData.setWorkItemId(12);
taskData.setProcessInstanceId(1);
taskData.setProcessId("someprocess");
taskData.setDeploymentId("org.jbpm.test:someprocess:1.0");
taskData.setProcessSessionId(1);
task.setTaskData(taskData);
InternalPeopleAssignments peopleAssignments =
(InternalPeopleAssignments) TaskModelProvider.getFactory().newPeopleAssignments();
peopleAssignments.setPotentialOwners(new ArrayList<OrganizationalEntity>());
peopleAssignments.setBusinessAdministrators(new ArrayList<OrganizationalEntity>());
peopleAssignments.setExcludedOwners(new ArrayList<OrganizationalEntity>());
peopleAssignments.setRecipients(new ArrayList<OrganizationalEntity>());
peopleAssignments.setTaskStakeholders(new ArrayList<OrganizationalEntity>());
InternalOrganizationalEntity jdoe =
(InternalOrganizationalEntity) TaskModelProvider.getFactory().newUser();
jdoe.setId("jdoe");
peopleAssignments.getPotentialOwners().add(jdoe);
peopleAssignments.getBusinessAdministrators().add(jdoe);
task.setPeopleAssignments(peopleAssignments);
final boolean txOwner = transactionManager.begin();
try {
EntityManager em = entityManagerFactory.createEntityManager();
em.persist(jdoe);
em.persist(task);
transactionManager.commit(txOwner);
} catch (Exception ex) {
ex.printStackTrace();
transactionManager.rollback(txOwner);
throw new RuntimeException(ex.getMessage(), ex);
}
}

/**
* Loads persisted session from database.
Expand Down
Expand Up @@ -78,6 +78,7 @@ public void testPersistedProcess(String type) throws IOException, ParseException
// Prepare 6.0. schema
scriptRunnerContext.executeScripts(new File(getClass().getResource("/ddl60").getFile()));
scriptRunnerContext.persistOldProcessAndSession(TEST_SESSION_ID, TEST_PROCESS_ID, TEST_PROCESS_INSTANCE_ID);
scriptRunnerContext.createSomeTask();
// Execute upgrade scripts.
scriptRunnerContext.executeScripts(new File(getClass().getResource("/upgrade-scripts").getFile()), type);
} finally {
Expand Down

0 comments on commit e77d9c5

Please sign in to comment.