fix: handle postgres migration error (#13844)

* fix: handle postgres migration error

* fix: removed MySQL comment
This commit is contained in:
Teddy 2023-11-03 15:03:03 +01:00 committed by GitHub
parent 9d58b56a1c
commit 9d238d142a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,7 +13,9 @@ import org.openmetadata.service.Entity;
import org.openmetadata.service.jdbi3.CollectionDAO;
import org.openmetadata.service.jdbi3.GlossaryTermRepository;
import org.openmetadata.service.jdbi3.QueryRepository;
import org.openmetadata.service.resources.databases.DatasourceConfig;
import org.openmetadata.service.util.JsonUtils;
import org.postgresql.util.PGobject;
@Slf4j
public class MigrationUtil {
@ -136,7 +138,15 @@ public class MigrationUtil {
.mapToMap()
.forEach(
row -> {
GlossaryTerm term = JsonUtils.readValue((String) row.get("json"), GlossaryTerm.class);
String jsonRow;
if (Boolean.TRUE.equals(DatasourceConfig.getInstance().isMySQL())) {
jsonRow = (String) row.get("json");
} else {
// Postgres stores JSON as a JSONB, so we can't just cast it as a string
PGobject pgObject = (PGobject) row.get("json");
jsonRow = pgObject.getValue();
}
GlossaryTerm term = JsonUtils.readValue(jsonRow, GlossaryTerm.class);
if (term.getStatus() == GlossaryTerm.Status.DRAFT) {
term.setStatus(GlossaryTerm.Status.APPROVED);
collectionDAO.glossaryTermDAO().update(term);