-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[2.0] fix(glossary): include cardinality on default term relation types #33554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gh-bot-collate
wants to merge
1
commit into
2.0
Choose a base branch
from
backport/2.0/pr-28376
base: 2.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
bootstrap/sql/migrations/native/2.0.3/mysql/postDataMigrationSQLScript.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- Post data migration script for OpenMetadata 2.0.3 | ||
| -- Backfill for glossaryTermRelationSettings cardinality runs in the Java migration step. |
2 changes: 2 additions & 0 deletions
2
bootstrap/sql/migrations/native/2.0.3/mysql/schemaChanges.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- Schema changes for OpenMetadata 2.0.3 | ||
| -- No DDL changes; data backfill runs in the Java migration step. |
2 changes: 2 additions & 0 deletions
2
bootstrap/sql/migrations/native/2.0.3/postgres/postDataMigrationSQLScript.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- Post data migration script for OpenMetadata 2.0.3 | ||
| -- Backfill for glossaryTermRelationSettings cardinality runs in the Java migration step. |
2 changes: 2 additions & 0 deletions
2
bootstrap/sql/migrations/native/2.0.3/postgres/schemaChanges.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| -- Schema changes for OpenMetadata 2.0.3 | ||
| -- No DDL changes; data backfill runs in the Java migration step. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...tadata-service/src/main/java/org/openmetadata/service/migration/mysql/v203/Migration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package org.openmetadata.service.migration.mysql.v203; | ||
|
|
||
| import lombok.SneakyThrows; | ||
| import org.openmetadata.service.migration.api.MigrationProcessImpl; | ||
| import org.openmetadata.service.migration.utils.MigrationFile; | ||
| import org.openmetadata.service.migration.utils.v203.MigrationUtil; | ||
|
|
||
| public class Migration extends MigrationProcessImpl { | ||
|
|
||
| public Migration(MigrationFile migrationFile) { | ||
| super(migrationFile); | ||
| } | ||
|
|
||
| @Override | ||
| @SneakyThrows | ||
| public void runDataMigration() { | ||
| MigrationUtil migrationUtil = new MigrationUtil(handle); | ||
| migrationUtil.backfillGlossaryTermRelationCardinality(); | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
...ata-service/src/main/java/org/openmetadata/service/migration/postgres/v203/Migration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package org.openmetadata.service.migration.postgres.v203; | ||
|
|
||
| import lombok.SneakyThrows; | ||
| import org.openmetadata.service.migration.api.MigrationProcessImpl; | ||
| import org.openmetadata.service.migration.utils.MigrationFile; | ||
| import org.openmetadata.service.migration.utils.v203.MigrationUtil; | ||
|
|
||
| public class Migration extends MigrationProcessImpl { | ||
|
|
||
| public Migration(MigrationFile migrationFile) { | ||
| super(migrationFile); | ||
| } | ||
|
|
||
| @Override | ||
| @SneakyThrows | ||
| public void runDataMigration() { | ||
| MigrationUtil migrationUtil = new MigrationUtil(handle); | ||
| migrationUtil.backfillGlossaryTermRelationCardinality(); | ||
| } | ||
| } |
84 changes: 84 additions & 0 deletions
84
...ta-service/src/main/java/org/openmetadata/service/migration/utils/v203/MigrationUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package org.openmetadata.service.migration.utils.v203; | ||
|
|
||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.jdbi.v3.core.Handle; | ||
| import org.openmetadata.schema.configuration.GlossaryTermRelationSettings; | ||
| import org.openmetadata.schema.configuration.GlossaryTermRelationType; | ||
| import org.openmetadata.schema.configuration.RelationCardinality; | ||
| import org.openmetadata.schema.utils.JsonUtils; | ||
| import org.openmetadata.service.resources.databases.DatasourceConfig; | ||
| import org.openmetadata.service.util.GlossaryTermRelationSettingsUtil; | ||
|
|
||
| @Slf4j | ||
| public class MigrationUtil { | ||
|
|
||
| private static final String GLOSSARY_TERM_RELATION_SETTINGS = "glossaryTermRelationSettings"; | ||
|
|
||
| // Postgres stores the settings column as jsonb and won't implicitly cast a bound string | ||
| // (::jsonb is required); MySQL's JSON column parses the string directly. | ||
| private static final String UPDATE_MYSQL = | ||
| "UPDATE openmetadata_settings SET json = :json WHERE configType = :configType"; | ||
| private static final String UPDATE_POSTGRES = | ||
| "UPDATE openmetadata_settings SET json = :json::jsonb WHERE configType = :configType"; | ||
|
|
||
| private final Handle handle; | ||
|
|
||
| public MigrationUtil(Handle handle) { | ||
| this.handle = handle; | ||
| } | ||
|
|
||
| /** | ||
| * Older installs seeded the system glossary relation types before the cardinality field existed, | ||
| * so GET returned {@code cardinality: null} and the UI fell back to MANY_TO_MANY. Persist that | ||
| * same MANY_TO_MANY on the system defaults whose cardinality is still null. Bounds are derived by | ||
| * the canonical normalizer (the settings PUT path), leaving these relations unbounded - metadata | ||
| * only, no new enforcement. | ||
| */ | ||
| public void backfillGlossaryTermRelationCardinality() { | ||
| GlossaryTermRelationSettings settings = loadSettings(); | ||
| if (settings == null || settings.getRelationTypes() == null) { | ||
| return; | ||
| } | ||
|
|
||
| boolean changed = false; | ||
| for (GlossaryTermRelationType relationType : settings.getRelationTypes()) { | ||
| if (relationType != null | ||
| && Boolean.TRUE.equals(relationType.getIsSystemDefined()) | ||
| && relationType.getCardinality() == null) { | ||
| relationType.setCardinality(RelationCardinality.MANY_TO_MANY); | ||
| GlossaryTermRelationSettingsUtil.normalize(relationType); | ||
| changed = true; | ||
| LOG.info( | ||
| "Backfilled MANY_TO_MANY cardinality on system relation '{}'", relationType.getName()); | ||
| } | ||
| } | ||
|
|
||
| if (changed) { | ||
| persist(settings); | ||
| } | ||
| } | ||
|
|
||
| private GlossaryTermRelationSettings loadSettings() { | ||
| String json = | ||
| handle | ||
| .createQuery("SELECT json FROM openmetadata_settings WHERE configType = :configType") | ||
| .bind("configType", GLOSSARY_TERM_RELATION_SETTINGS) | ||
| .mapTo(String.class) | ||
| .findOne() | ||
| .orElse(null); | ||
| if (json == null) { | ||
| LOG.info("No glossaryTermRelationSettings row found; skipping cardinality backfill"); | ||
| return null; | ||
| } | ||
| return JsonUtils.readValue(json, GlossaryTermRelationSettings.class); | ||
| } | ||
|
|
||
| private void persist(GlossaryTermRelationSettings settings) { | ||
| boolean isMySQL = Boolean.TRUE.equals(DatasourceConfig.getInstance().isMySQL()); | ||
| handle | ||
| .createUpdate(isMySQL ? UPDATE_MYSQL : UPDATE_POSTGRES) | ||
| .bind("configType", GLOSSARY_TERM_RELATION_SETTINGS) | ||
| .bind("json", JsonUtils.pojoToJson(settings)) | ||
| .execute(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new backfill method combines loading, filtering, mutation, normalization, logging, and persistence in roughly 25 lines, and it exits through an early guard. The repository’s Java guide requires focused methods of about 15 lines or fewer and one trailing return per method.
loadSettingsalso introduces an early return, and the new integration-test method exceeds the method-size guideline. This repository requirement must be satisfied before merging.Context Used: AGENTS.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!