Skip to content

Commit dc50673

Browse files
committed
- Adjust code to handle c8Key is string instead of long
- Change `C8_KEY` column from `BIGINT` to `VARCHAR(255)`.
1 parent fb50d52 commit dc50673

File tree

13 files changed

+73
-24
lines changed

13 files changed

+73
-24
lines changed

data-migrator/core/src/main/java/io/camunda/migration/data/RuntimeMigrator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected void migrate() {
8484
if (skipReason == null && shouldStartProcessInstance(c7ProcessInstanceId)) {
8585
startProcessInstance(c7ProcessInstanceId, createTime);
8686
} else if (isUnknown(c7ProcessInstanceId)) {
87-
dbClient.insert(c7ProcessInstanceId, null, createTime, TYPE.RUNTIME_PROCESS_INSTANCE, skipReason);
87+
dbClient.insert(c7ProcessInstanceId, (Long) null, createTime, TYPE.RUNTIME_PROCESS_INSTANCE, skipReason);
8888
} else {
8989
dbClient.updateSkipReason(c7ProcessInstanceId, TYPE.RUNTIME_PROCESS_INSTANCE, skipReason);
9090
}
@@ -131,7 +131,7 @@ protected void handleVariableInterceptorException(VariableInterceptorException e
131131
RuntimeMigratorLogs.stacktrace(e);
132132

133133
if (MIGRATE.equals(mode)) {
134-
dbClient.insert(c7ProcessInstanceId, null, createTime, TYPE.RUNTIME_PROCESS_INSTANCE, e.getMessage());
134+
dbClient.insert(c7ProcessInstanceId, (Long) null, createTime, TYPE.RUNTIME_PROCESS_INSTANCE, e.getMessage());
135135
} else if (RETRY_SKIPPED.equals(mode)) {
136136
dbClient.updateSkipReason(c7ProcessInstanceId, TYPE.RUNTIME_PROCESS_INSTANCE, e.getMessage());
137137
}

data-migrator/core/src/main/java/io/camunda/migration/data/impl/clients/DbClient.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ public List<String> findAllC7Ids() {
9999
* Updates a record by setting the key for an existing ID and type.
100100
*/
101101
public void updateC8KeyByC7IdAndType(String c7Id, Long c8Key, TYPE type) {
102+
updateC8KeyByC7IdAndType(c7Id, (c8Key == null) ? null : c8Key.toString(), type);
103+
}
104+
105+
/**
106+
* Updates a record by setting the key for an existing ID and type.
107+
*/
108+
public void updateC8KeyByC7IdAndType(String c7Id, String c8Key, TYPE type) {
102109
DbClientLogs.updatingC8KeyForC7Id(c7Id, c8Key);
103110
var model = createIdKeyDbModel(c7Id, null, c8Key, type);
104111
callApi(() -> idKeyMapper.updateC8KeyByC7IdAndType(model), FAILED_TO_UPDATE_KEY + c8Key);
@@ -132,6 +139,13 @@ public void insert(String c7Id, Long c8Key, TYPE type) {
132139
* Inserts a new process instance record into the mapping table.
133140
*/
134141
public void insert(String c7Id, Long c8Key, Date createTime, TYPE type, String skipReason) {
142+
insert(c7Id, (c8Key == null) ? null : c8Key.toString(), createTime, type, skipReason);
143+
}
144+
145+
/**
146+
* Inserts a new process instance record into the mapping table.
147+
*/
148+
public void insert(String c7Id, String c8Key, Date createTime, TYPE type, String skipReason) {
135149
String finalSkipReason = properties.getSaveSkipReason() ? skipReason : null;
136150
DbClientLogs.insertingRecord(c7Id, createTime, null, finalSkipReason);
137151
var model = createIdKeyDbModel(c7Id, createTime, c8Key, type, finalSkipReason);
@@ -201,7 +215,7 @@ protected void deleteByC7Id(String c7Id) {
201215
/**
202216
* Creates a new IdKeyDbModel instance with the provided parameters including skip reason.
203217
*/
204-
protected IdKeyDbModel createIdKeyDbModel(String c7Id, Date createTime, Long c8Key, TYPE type, String skipReason) {
218+
protected IdKeyDbModel createIdKeyDbModel(String c7Id, Date createTime, String c8Key, TYPE type, String skipReason) {
205219
var keyIdDbModel = new IdKeyDbModel();
206220
keyIdDbModel.setC7Id(c7Id);
207221
keyIdDbModel.setCreateTime(createTime);
@@ -214,7 +228,7 @@ protected IdKeyDbModel createIdKeyDbModel(String c7Id, Date createTime, Long c8K
214228
/**
215229
* Creates a new IdKeyDbModel instance with the provided parameters.
216230
*/
217-
protected IdKeyDbModel createIdKeyDbModel(String c7Id, Date createTime, Long c8Key, TYPE type) {
231+
protected IdKeyDbModel createIdKeyDbModel(String c7Id, Date createTime, String c8Key, TYPE type) {
218232
return createIdKeyDbModel(c7Id, createTime, c8Key, type, null);
219233
}
220234
}

data-migrator/core/src/main/java/io/camunda/migration/data/impl/history/AuditLogMigrator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99

1010
import static io.camunda.migration.data.MigratorMode.RETRY_SKIPPED;
1111
import static io.camunda.migration.data.impl.logging.HistoryMigratorLogs.SKIP_REASON_BELONGS_TO_SKIPPED_TASK;
12+
import static io.camunda.migration.data.constants.MigratorConstants.C7_HISTORY_PARTITION_ID;
1213
import static io.camunda.migration.data.impl.logging.HistoryMigratorLogs.SKIP_REASON_MISSING_PROCESS_DEFINITION;
1314
import static io.camunda.migration.data.impl.logging.HistoryMigratorLogs.SKIP_REASON_MISSING_PROCESS_INSTANCE;
1415
import static io.camunda.migration.data.impl.logging.HistoryMigratorLogs.SKIP_REASON_MISSING_ROOT_PROCESS_INSTANCE;
1516
import static io.camunda.migration.data.impl.persistence.IdKeyMapper.TYPE.HISTORY_AUDIT_LOG;
1617
import static io.camunda.migration.data.impl.persistence.IdKeyMapper.TYPE.HISTORY_PROCESS_DEFINITION;
1718
import static io.camunda.migration.data.impl.persistence.IdKeyMapper.TYPE.HISTORY_PROCESS_INSTANCE;
1819
import static io.camunda.migration.data.impl.persistence.IdKeyMapper.TYPE.HISTORY_USER_TASK;
20+
import static io.camunda.migration.data.impl.util.ConverterUtil.getNextKey;
1921

2022
import io.camunda.db.rdbms.write.domain.AuditLogDbModel;
2123
import io.camunda.migration.data.exception.EntityInterceptorException;
@@ -96,8 +98,8 @@ public void migrateOne(UserOperationLogEntry c7AuditLog) {
9698
protected AuditLogDbModel.Builder configureAuditLogBuilder(UserOperationLogEntry c7AuditLog) {
9799
AuditLogDbModel.Builder builder = new AuditLogDbModel.Builder();
98100

99-
String auditLogKey = c7AuditLog.getId();
100-
builder.auditLogKey(auditLogKey);
101+
String key = String.format("%s-%s", C7_HISTORY_PARTITION_ID, getNextKey());
102+
builder.auditLogKey(key);
101103

102104
resolveProcessInstanceAndDefinitionKeys(builder, c7AuditLog);
103105

@@ -183,9 +185,7 @@ protected void validateDependenciesAndInsert(
183185
*/
184186
protected void insertAuditLog(UserOperationLogEntry c7AuditLog, AuditLogDbModel dbModel, String c7AuditLogId) {
185187
c8Client.insertAuditLog(dbModel);
186-
// Use hash code of the audit log key as the Long value for tracking
187-
Long trackingKey = (long) dbModel.auditLogKey().hashCode(); // TODO
188-
markMigrated(c7AuditLogId, trackingKey, c7AuditLog.getTimestamp(), HISTORY_AUDIT_LOG);
188+
markMigrated(c7AuditLogId, dbModel.auditLogKey(), c7AuditLog.getTimestamp(), HISTORY_AUDIT_LOG);
189189
HistoryMigratorLogs.migratingHistoricAuditLogCompleted(c7AuditLogId);
190190
}
191191

data-migrator/core/src/main/java/io/camunda/migration/data/impl/history/BaseMigrator.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import static io.camunda.migration.data.impl.persistence.IdKeyMapper.TYPE.HISTORY_FLOW_NODE;
1515
import static io.camunda.migration.data.impl.persistence.IdKeyMapper.TYPE.HISTORY_PROCESS_INSTANCE;
1616
import static io.camunda.migration.data.impl.util.ConverterUtil.convertDate;
17+
import static io.camunda.search.entities.DecisionInstanceEntity.DecisionDefinitionType;
1718

1819
import io.camunda.db.rdbms.read.domain.DecisionDefinitionDbQuery;
1920
import io.camunda.db.rdbms.read.domain.DecisionInstanceDbQuery;
@@ -43,7 +44,6 @@
4344
import java.util.List;
4445
import java.util.Optional;
4546
import org.camunda.bpm.engine.ProcessEngine;
46-
import org.camunda.bpm.engine.impl.util.ClockUtil;
4747
import org.camunda.bpm.model.dmn.DmnModelInstance;
4848
import org.camunda.bpm.model.dmn.instance.Decision;
4949
import org.camunda.bpm.model.dmn.instance.LiteralExpression;
@@ -202,6 +202,14 @@ protected boolean shouldMigrate(String id, TYPE type) {
202202
return !dbClient.checkExistsByC7IdAndType(id, type);
203203
}
204204

205+
protected void markMigrated(String c7Id, String c8Key, Date createTime, TYPE type) {
206+
if (RETRY_SKIPPED.equals(mode)) {
207+
dbClient.updateC8KeyByC7IdAndType(c7Id, c8Key, type);
208+
} else if (MIGRATE.equals(mode)) {
209+
dbClient.insert(c7Id, c8Key, createTime, type, null);
210+
}
211+
}
212+
205213
protected void markMigrated(String c7Id, Long c8Key, Date createTime, TYPE type) {
206214
saveRecord(c7Id, c8Key, type, createTime, null);
207215
}
@@ -241,9 +249,9 @@ protected DecisionInstanceEntity.DecisionDefinitionType determineDecisionType(Dm
241249
}
242250

243251
if (decision.getExpression() instanceof LiteralExpression) {
244-
return DecisionInstanceEntity.DecisionDefinitionType.LITERAL_EXPRESSION;
252+
return DecisionDefinitionType.LITERAL_EXPRESSION;
245253
} else {
246-
return DecisionInstanceEntity.DecisionDefinitionType.DECISION_TABLE;
254+
return DecisionDefinitionType.DECISION_TABLE;
247255
}
248256
}
249257

data-migrator/core/src/main/java/io/camunda/migration/data/impl/logging/DbClientLogs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class DbClientLogs {
4242
public static final String FAILED_TO_DELETE = "Failed to delete mapping for C7 ID: ";
4343
public static final String FAILED_TO_DROP_MIGRATION_TABLE = "Failed to drop migration mapping table";
4444

45-
public static void updatingC8KeyForC7Id(String c7Id, Long c8Key) {
45+
public static void updatingC8KeyForC7Id(String c7Id, String c8Key) {
4646
LOGGER.debug(UPDATING_KEY_FOR_C7_ID, c7Id, c8Key);
4747
}
4848

data-migrator/core/src/main/java/io/camunda/migration/data/impl/persistence/IdKeyDbModel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public class IdKeyDbModel {
1515

1616
protected String c7Id;
17-
protected Long c8Key;
17+
protected String c8Key;
1818
protected TYPE type;
1919
protected Date createTime;
2020
protected String skipReason;
@@ -27,7 +27,7 @@ public IdKeyDbModel(String c7Id, Date createTime) {
2727
this.createTime = createTime;
2828
}
2929

30-
public Long getC8Key() {
30+
public String getC8Key() {
3131
return c8Key;
3232
}
3333

@@ -47,7 +47,7 @@ public String getSkipReason() {
4747
return skipReason;
4848
}
4949

50-
public void setC8Key(Long c8Key) {
50+
public void setC8Key(String c8Key) {
5151
this.c8Key = c8Key;
5252
}
5353

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
4+
~ one or more contributor license agreements. See the NOTICE file distributed
5+
~ with this work for additional information regarding copyright ownership.
6+
~ Licensed under the Camunda License 1.0. You may not use this file
7+
~ except in compliance with the Camunda License 1.0.
8+
-->
9+
<databaseChangeLog
10+
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
11+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
12+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
13+
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
14+
15+
<changeSet id="tag_before_modify_c8_key_column" author="Camunda">
16+
<tagDatabase tag="tag_before_modify_c8_key_column"/>
17+
</changeSet>
18+
19+
<changeSet id="modify_c8_key_column_to_varchar" author="Camunda">
20+
<modifyDataType tableName="${prefix}MIGRATION_MAPPING"
21+
columnName="C8_KEY"
22+
newDataType="VARCHAR(255)"/>
23+
</changeSet>
24+
25+
</databaseChangeLog>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
databaseChangeLog:
22
- include:
33
file: db/changelog/migrator/db.0.1.0.xml
4+
- include:
5+
file: db/changelog/migrator/db.0.3.0.xml

data-migrator/core/src/main/resources/mapper/IdKey.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<resultMap id="idKeyResultMap" type="io.camunda.migration.data.impl.persistence.IdKeyDbModel">
1313
<id property="c7Id" column="C7_ID" jdbcType="VARCHAR"/>
14-
<result property="c8Key" column="C8_KEY" jdbcType="BIGINT"/>
14+
<result property="c8Key" column="C8_KEY" jdbcType="VARCHAR"/>
1515
<result property="createTime" column="CREATE_TIME" jdbcType="TIMESTAMP"/>
1616
<result property="type" column="TYPE" jdbcType="VARCHAR"/>
1717
<result property="skipReason" column="SKIP_REASON" jdbcType="VARCHAR"/>
@@ -58,7 +58,7 @@
5858

5959
<update id="updateC8KeyByC7IdAndType" parameterType="io.camunda.migration.data.impl.persistence.IdKeyDbModel">
6060
UPDATE ${prefix}MIGRATION_MAPPING
61-
SET C8_KEY = #{c8Key, jdbcType=BIGINT}
61+
SET C8_KEY = #{c8Key, jdbcType=VARCHAR}
6262
WHERE C7_ID = #{c7Id, jdbcType=VARCHAR} AND TYPE = #{type, jdbcType=VARCHAR}
6363
</update>
6464

@@ -100,7 +100,7 @@
100100
parameterType="io.camunda.migration.data.impl.persistence.IdKeyDbModel"
101101
flushCache="true">
102102
INSERT INTO ${prefix}MIGRATION_MAPPING (C7_ID, C8_KEY, CREATE_TIME, TYPE, SKIP_REASON)
103-
VALUES (#{c7Id, jdbcType=VARCHAR}, #{c8Key, jdbcType=BIGINT}, #{createTime, jdbcType=TIMESTAMP}, #{type, jdbcType=VARCHAR}, #{skipReason, jdbcType=VARCHAR})
103+
VALUES (#{c7Id, jdbcType=VARCHAR}, #{c8Key, jdbcType=VARCHAR}, #{createTime, jdbcType=TIMESTAMP}, #{type, jdbcType=VARCHAR}, #{skipReason, jdbcType=VARCHAR})
104104
</insert>
105105

106106
<delete id="deleteByC7Id">

data-migrator/plugins/cockpit/src/test/java/io/camunda/migration/data/plugin/cockpit/resources/MigratorResourceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected void assertIdKeyDbModelListsEqual(List<IdKeyDbModel> expected, List<Id
160160
protected IdKeyDbModel createExpectedMigratedModel(String c7Id) {
161161
IdKeyDbModel model = new IdKeyDbModel();
162162
model.setC7Id(c7Id);
163-
model.setC8Key(getNextKey());
163+
model.setC8Key(String.valueOf(getNextKey()));
164164
model.setType(IdKeyMapper.TYPE.RUNTIME_PROCESS_INSTANCE);
165165
return model;
166166
}
@@ -184,7 +184,7 @@ protected static void insertTestData(IdKeyDbModel idKeyDbModel) {
184184
if (idKeyDbModel.getC8Key() == null) {
185185
stmt.setNull(2, java.sql.Types.BIGINT);
186186
} else {
187-
stmt.setLong(2, idKeyDbModel.getC8Key());
187+
stmt.setString(2, idKeyDbModel.getC8Key());
188188
}
189189
stmt.executeUpdate();
190190
}

0 commit comments

Comments
 (0)