Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/java-tests/impact-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,7 @@
],
"tests": [
"*Migration*IT",
"org/openmetadata/it/tests/migration/**",
"*SeedData*IT",
"*Operations*IT",
"*DbTune*IT"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# The 2.1.2 upgrade repairs relationship types a 2.1 save rejects

- **Status:** Accepted
- **Revisions:** v1 2026-12-04 (initial)
- **Deciders:** OpenMetadata maintainers
- **Guard:** RelationshipTypeRepairTest; RelationshipTypeRepairMigrationIT; RelationshipTypeResolverTest#requireLooksUpADottedNameAsOneQuotedSegment; LegacyRelationshipTypeSynchronizerTest#upsertFindsADottedNameUnderItsQuotedFqn; RelationshipTypeResourceIT#putUpdatesATypeWhoseNameHoldsADotInPlace
- **Related:** ADR:2026-12-04-upgrade-turns-free-text-relation-inverses-into-relationship-types; ADR:2026-11-11-a-data-migration-carries-its-own-logic

## Context

The released 2.1.0 data migration stored every 2.0 relation type as a `RelationshipType` without
the checks a 2.1 write runs (`RelationshipTypeValidator` and the unique predicate check). 2.0
accepted shapes 2.1 rejects, so after an upgrade that succeeded:

- saving such a type with no change fails: a symmetric type naming another type as its inverse, a
relative predicate, an incompatible characteristic pair, an asymmetric type that is its own
inverse, a functional type with no limit of one;
- two types share a predicate, so whichever is saved second fails, and a seed type whose predicate
a custom type holds is never created (each start logs "already governed by");
- glossary term links stored under a text that names no type (the inverse text of a type deleted
in 2.0) fail to read: the term page, the relations graph, search, PATCH and CSV export all error;
- links 2.1.0 could not resolve never got the type id and json fields 2.1 reads;
- a name holding a dot was stored under a hash no lookup computes.

Clusters already at 2.1.0 or 2.1.1 do not run the corrected 2.1.0 migration again, so the repair
is a 2.1.2 step, run once.

## Decision

In one transaction, each stored type is changed only as far as a 2.1 save requires:

1. The FQN is the quoted name and `fqnHash` its `buildHash`.
2. Both characteristics of an incompatible pair (symmetric/asymmetric, reflexive/irreflexive,
asymmetric/reflexive) are cleared; a functional type gets `sourceMax` 1 and an inverse
functional one `targetMax` 1; a symmetric type becomes its own inverse; an asymmetric type that
is its own inverse loses asymmetric. Inverse references are refreshed to their target's name.
3. Every type ends with an absolute predicate no other type holds. A seed type's predicate is
reserved for that seed. Otherwise one holder keeps a predicate: live before deleted, system
before custom, the type whose own default it is, then by name. Every other holder, and any type
with a relative predicate, gets its default predicate with a numeric suffix until free; its IRI
follows when it was unset or equal to the old predicate.
4. Each stored link text that names no type exactly moves to a live type named by it ignoring
case, else to a new associative type whose display name is the text; texts that differ only in
case share it. A display name is never matched, as 2.0 resolved link types by name only. A
blank text moves to `relatedTo`.
5. Every glossary term link's type id and json fields are set from its column, as 2.1.0 did for
the links it resolved.

The step works on rows and JSON trees, as every step after 2.1.0 does: the seed predicates it
reserves, a created type's shape and id, and the default predicate are its own constants, frozen
at the 2.1.2 seeds and formats. A type the repair does not need is not written, and a second run
changes nothing. Every runtime lookup of a type by name (the resolver, the settings synchronizer,
PUT `/relationshipTypes`) quotes the name, as the stored FQN is quoted.

## Consequences

Every upgraded type can be saved again, the seed types are created on the next start, and every
link reads under a stored type. Changes are logged per type. When the log reports changed
predicates or moved links, reindex the RDF store and the glossary term search index: search
documents carry each term's related terms with their relation type and are not rewritten here.

Left alone on purpose: names that differ only in case (2.1 allows them) and links of a
soft-deleted type, which 2.1 refuses until the type is restored. A cluster already on 2.1 whose 2.0
settings defined a name twice keeps the last definition, which can lack the inverse its partner
names, so a link saved from the higher term shows one label on both terms. It is not re-paired:
from the stored types a 2.0 type that never had an inverse looks the same, and pairing it would
reverse the links 2.0 stored from the higher term. A link 2.0 stored under another
type, as a symmetric type's inverse, keeps reading as that type: 2.0 kept no trace of the type it
was saved under. The deprecated `/system/settings` relation type endpoints still read the 2.0
settings row, which this step does not rewrite; a write through them maps that row again. The UI
no longer calls them.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# The 2.1 upgrade turns a free-text relation inverse into a relationship type

- **Status:** Accepted
- **Revisions:** v1 2026-12-04 (initial)
- **Deciders:** OpenMetadata maintainers
- **Guard:** OntologyMigrationTest#createsTheInverseTypeAFreeTextInverseNamed; OntologyMigrationTest#resolvesAnInverseThatNamesAnExistingTypeInAnotherCase; OntologyMigrationTest#anInverseMatchingOnlyAnotherTypesDisplayNameGetsItsOwnType; OntologyMigrationTest#generatedNameNeverCollidesWithAnExistingType; OntologyMigrationTest#aSymmetricTypesFreeTextInverseIsTheTypeItself; OntologyMigrationTest#aNameDefinedTwiceKeepsTheSystemDefinitionElseTheFirst; LegacyRelationshipTypeMapperTest#aNameWithASpaceGetsAnEncodedDefaultPredicate; LegacyRelationshipTypeMapperTest#aDottedNameIsStoredUnderTheQuotedFqnItIsLookedUpBy; OntologyInverseRepairMigrationIT
- **Related:** ADR:2026-11-19-relationship-type-references-carry-their-name; ADR:2026-12-04-upgrade-repairs-relationship-types-2-1-rejects

## Context

In 2.0 a glossary term relation type's `inverseRelation` was free text: the settings form did not
check it against the configured types. A link saved from the inverse end was stored with that text
as its `relationType`, because the canonical row is keyed by the smaller term id and takes the
inverse name when the link points the other way.

2.1 turns each configured type into a `RelationshipType` entity, and both the inverse reference
and every stored link must name one. An inverse that names no type made the 2.1.0 data migration
throw, which halted the upgrade, and the links stored under that text could not be read in 2.1
even if the migration got past it.

Dropping the inverse is not enough: the links stored under the text would still name no type.
Rewriting those links onto the base type in reverse would change rows the user saved without
saying so, and would discard the inverse label they chose.

## Decision

Before mapping the settings, the 2.1.0 data migration keeps one definition per name, since each
name becomes one stored type: the system-defined one, else the first. The others are dropped from
the settings row and logged. It then resolves every inverse that does not match a configured type
name exactly:

1. A blank inverse is removed.
2. A symmetric type's inverse points at the type itself, since a symmetric relation is its own
inverse; links stored under the text are renamed to the type.
3. An inverse that matches a configured type's name ignoring case points at that type. A display
name is never matched: 2.0 resolved an inverse by name only, so text equal to another type's
label (for example "Controlled By" on `regulates`, while `controlledBy` is the inverse of
`controls`) was never that type, and reusing it would leave a one-way pair.
4. Otherwise a type is added to the settings for it: the display name is the inverse text; the
name is that text in camelCase or, when that is not a valid name, `inverseOf<BaseName>`; a
numeric suffix makes it unique ignoring case, and it is capped at 60 characters, below the
64-character `relationType` column. It names the base type as its inverse, keeps the
base type's category and symmetric flags, and mirrors the directional ones (`sourceMax` and
`targetMax`, functional and inverse functional, domain and range, one-to-many and many-to-one).
Types that name the same missing inverse, ignoring case, share one added type.

Glossary term links stored under the old inverse text are renamed to the resolved name, in the
column and in `json.relationType`. Where the same pair already has a row under that name, the old
row is deleted instead. Links are renamed before the settings are written back, so an interrupted
run repeats the whole repair. A second run finds nothing to repair. On MySQL the stored text is
matched byte for byte, so a case-insensitive collation cannot merge two texts that differ in case.

The conversion into `relationship_type_entity` runs in one transaction and only when that table is
empty, and it only inserts. A changed 2.1.0 migration runs again on a cluster still at 2.1.0, and
by then the table holds the types as 2.1 edited, deleted or hard-deleted them; overwriting them
from the 2.0 settings would undo that. Each row's FQN is the quoted name and its `fqnHash` is
`FullyQualifiedName.buildHash` of it, the hash a lookup by name computes, so a name holding a dot
is one segment. A type with no predicate gets the default one with the name URL-encoded, so a name
holding a space yields a valid URI.

## Consequences

Upgrades from 2.0 no longer stop on an unmatched inverse, and every link saved in 2.0 is readable
in 2.1 under a type the administrator can see, rename or edit. The added types are not system
defined. The repair runs only inside the 2.1.0 data migration: settings saved later go through
the 2.1 relationship type API, which already requires an inverse to name a type.
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ public static GenericContainer<?> getFusekiContainer() {
}

/** The isolated metadata database, for scale resource sampling. */
public static GenericContainer<?> getDatabaseContainer() {
public static JdbcDatabaseContainer<?> getDatabaseContainer() {
return DATABASE_CONTAINER;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.nio.charset.StandardCharsets;
import java.util.Set;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.openmetadata.it.util.SdkClients;
Expand Down Expand Up @@ -78,6 +79,17 @@ private static CreateRelationshipType request(String name) {
.withPaletteKey(RelationshipPaletteKey.VIOLET);
}

@Test
void putUpdatesATypeWhoseNameHoldsADotInPlace(final TestNamespace ns) {
final CreateRelationshipType request = request(ns.prefix("part.of"));
final RelationshipType created = service().upsert(request);

final RelationshipType updated = service().upsert(request.withDescription("Updated by PUT"));

assertEquals(created.getId(), updated.getId());
assertEquals("Updated by PUT", updated.getDescription());
}

@Override
protected RelationshipType createEntity(CreateRelationshipType request) {
return service().create(request);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright 2026 Collate
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openmetadata.it.tests.migration;

import java.lang.reflect.Method;
import java.util.stream.Stream;
import org.jdbi.v3.core.Jdbi;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.InvocationInterceptor;
import org.junit.jupiter.api.extension.ReflectiveInvocationContext;
import org.openmetadata.it.util.ScratchDatabase;
import org.openmetadata.service.jdbi3.locator.ConnectionType;

/**
* Runs each test method against its own empty {@link ScratchDatabase}, dropped when the method
* returns, so SQL and migration tests that build their own schema neither share one nor outlive it.
* A test reads its database through {@link #jdbi()}, or receives it before the method runs when the
* test class implements {@link Target}.
*/
public final class ScratchDatabasePerTest implements InvocationInterceptor {
private static final ThreadLocal<Jdbi> CURRENT = new ThreadLocal<>();

/** A test class that prepares its schema before each method, where a {@code @BeforeEach} cannot. */
public interface Target {
void useScratchDatabase(Jdbi jdbi);
}

public static Jdbi jdbi() {
Jdbi jdbi = CURRENT.get();
if (jdbi == null) {
throw new IllegalStateException(
"No scratch database: add @ExtendWith(ScratchDatabasePerTest)");
}
return jdbi;
}

/** The dialect names a test parameterized over dialects runs: only the lane's. */
public static Stream<String> laneDialect() {
return Stream.of(ScratchDatabase.dialect() == ConnectionType.MYSQL ? "mysql" : "postgres");
}

@Override
public void interceptTestMethod(
Invocation<Void> invocation,
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext)
throws Throwable {
runOnScratchDatabase(invocation, extensionContext);
}

@Override
public void interceptTestTemplateMethod(
Invocation<Void> invocation,
ReflectiveInvocationContext<Method> invocationContext,
ExtensionContext extensionContext)
throws Throwable {
runOnScratchDatabase(invocation, extensionContext);
}

private static void runOnScratchDatabase(
Invocation<Void> invocation, ExtensionContext extensionContext) throws Throwable {
Throwable[] failure = new Throwable[1];
ScratchDatabase.withJdbi(
jdbi -> {
CURRENT.set(jdbi);
try {
if (extensionContext.getRequiredTestInstance() instanceof Target target) {
target.useScratchDatabase(jdbi);
}
invocation.proceed();
} catch (Throwable t) {
failure[0] = t;
} finally {
CURRENT.remove();
}
});
if (failure[0] != null) {
throw failure[0];
}
}
}
Loading
Loading