Skip to content

Commit

Permalink
catalog-model: Remove target from EntityRelation type.
Browse files Browse the repository at this point in the history
Signed-off-by: Johan Haals <johan.haals@gmail.com>
  • Loading branch information
jhaals authored and freben committed Mar 10, 2022
1 parent 165cabf commit d3e9ec4
Show file tree
Hide file tree
Showing 40 changed files with 135 additions and 375 deletions.
127 changes: 127 additions & 0 deletions .changeset/weak-fans-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
'@backstage/plugin-api-docs': patch
'@backstage/plugin-auth-backend': patch
'@backstage/plugin-catalog': patch
'@backstage/plugin-catalog-backend': patch
'@backstage/plugin-catalog-graph': patch
'@backstage/plugin-catalog-react': patch
'@backstage/plugin-fossa': patch
'@backstage/plugin-org': patch
'@backstage/plugin-tech-insights-backend': patch
'@backstage/plugin-techdocs': patch
'@backstage/app-defaults': patch
'@backstage/backend-common': patch
'@backstage/backend-tasks': patch
'@backstage/backend-test-utils': patch
'@backstage/catalog-client': patch
'@backstage/cli': patch
'@backstage/cli-common': patch
'@backstage/codemods': patch
'@backstage/config': patch
'@backstage/config-loader': patch
'@backstage/core-app-api': patch
'@backstage/core-components': patch
'@backstage/core-plugin-api': patch
'@backstage/create-app': patch
'@backstage/dev-utils': patch
'@backstage/errors': patch
'@backstage/integration': patch
'@backstage/integration-react': patch
'@backstage/release-manifests': patch
'@backstage/search-common': patch
'@techdocs/cli': patch
'techdocs-cli-embedded-app': patch
'@backstage/techdocs-common': patch
'@backstage/test-utils': patch
'@backstage/theme': patch
'@backstage/types': patch
'@backstage/version-bridge': patch
'@backstage/plugin-airbrake': patch
'@backstage/plugin-airbrake-backend': patch
'@backstage/plugin-allure': patch
'@backstage/plugin-analytics-module-ga': patch
'@backstage/plugin-apache-airflow': patch
'@backstage/plugin-app-backend': patch
'@backstage/plugin-auth-node': patch
'@backstage/plugin-azure-devops': patch
'@backstage/plugin-azure-devops-backend': patch
'@backstage/plugin-azure-devops-common': patch
'@backstage/plugin-badges': patch
'@backstage/plugin-badges-backend': patch
'@backstage/plugin-bazaar': patch
'@backstage/plugin-bazaar-backend': patch
'@backstage/plugin-bitrise': patch
'@backstage/plugin-catalog-backend-module-aws': patch
'@backstage/plugin-catalog-backend-module-ldap': patch
'@backstage/plugin-catalog-backend-module-msgraph': patch
'@backstage/plugin-catalog-common': patch
'@backstage/plugin-catalog-graphql': patch
'@backstage/plugin-catalog-import': patch
'@backstage/plugin-cicd-statistics': patch
'@backstage/plugin-circleci': patch
'@backstage/plugin-cloudbuild': patch
'@backstage/plugin-code-climate': patch
'@backstage/plugin-code-coverage': patch
'@backstage/plugin-code-coverage-backend': patch
'@backstage/plugin-config-schema': patch
'@backstage/plugin-cost-insights': patch
'@backstage/plugin-explore': patch
'@backstage/plugin-explore-react': patch
'@backstage/plugin-firehydrant': patch
'@backstage/plugin-gcp-projects': patch
'@backstage/plugin-git-release-manager': patch
'@backstage/plugin-github-actions': patch
'@backstage/plugin-github-deployments': patch
'@backstage/plugin-gitops-profiles': patch
'@backstage/plugin-gocd': patch
'@backstage/plugin-graphiql': patch
'@backstage/plugin-graphql-backend': patch
'@backstage/plugin-home': patch
'@backstage/plugin-ilert': patch
'@backstage/plugin-jenkins': patch
'@backstage/plugin-jenkins-backend': patch
'@backstage/plugin-jenkins-common': patch
'@backstage/plugin-kafka': patch
'@backstage/plugin-kafka-backend': patch
'@backstage/plugin-kubernetes': patch
'@backstage/plugin-kubernetes-backend': patch
'@backstage/plugin-kubernetes-common': patch
'@backstage/plugin-lighthouse': patch
'@backstage/plugin-newrelic': patch
'@backstage/plugin-newrelic-dashboard': patch
'@backstage/plugin-pagerduty': patch
'@backstage/plugin-permission-backend': patch
'@backstage/plugin-permission-common': patch
'@backstage/plugin-permission-node': patch
'@backstage/plugin-permission-react': patch
'@backstage/plugin-proxy-backend': patch
'@backstage/plugin-rollbar': patch
'@backstage/plugin-rollbar-backend': patch
'@backstage/plugin-scaffolder': patch
'@backstage/plugin-scaffolder-backend': patch
'@backstage/plugin-scaffolder-backend-module-cookiecutter': patch
'@backstage/plugin-scaffolder-backend-module-rails': patch
'@backstage/plugin-scaffolder-backend-module-yeoman': patch
'@backstage/plugin-scaffolder-common': patch
'@backstage/plugin-search': patch
'@backstage/plugin-search-backend': patch
'@backstage/plugin-search-backend-module-elasticsearch': patch
'@backstage/plugin-search-backend-module-pg': patch
'@backstage/plugin-search-backend-node': patch
'@backstage/plugin-sentry': patch
'@backstage/plugin-shortcuts': patch
'@backstage/plugin-sonarqube': patch
'@backstage/plugin-splunk-on-call': patch
'@backstage/plugin-tech-insights': patch
'@backstage/plugin-tech-insights-backend-module-jsonfc': patch
'@backstage/plugin-tech-insights-common': patch
'@backstage/plugin-tech-insights-node': patch
'@backstage/plugin-tech-radar': patch
'@backstage/plugin-techdocs-backend': patch
'@backstage/plugin-todo': patch
'@backstage/plugin-todo-backend': patch
'@backstage/plugin-user-settings': patch
'@backstage/plugin-xcmetrics': patch
---

Removed usage of `target` for `EntityRelation`s.
7 changes: 7 additions & 0 deletions .changeset/yellow-shirts-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@backstage/catalog-model': minor
---

**BREAKING**: Removed the `target` property from `EntityRelation`, use `targetRef` instead.

This means `target: { name: 'team-a', kind: 'group', namespace: 'default' }` is now replaced with `targetRef: 'group:default/team-a'` in entity relations.
8 changes: 0 additions & 8 deletions packages/catalog-model/src/entity/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import { JsonObject } from '@backstage/types';
import { CompoundEntityRef } from '../types';
import { EntityStatus } from './EntityStatus';

/**
Expand Down Expand Up @@ -185,13 +184,6 @@ export type EntityRelation = {
*/
type: string;

/**
* The target entity of this relation.
*
* @deprecated use targetRef instead
*/
target: CompoundEntityRef;

/**
* The entity ref of the target of this relation.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ describe('<ConsumedApisCard />', () => {
},
relations: [
{
target: {
kind: 'api',
namespace: 'my-namespace',
name: 'target-name',
},
targetRef: 'api:my-namespace/target-name',
type: RELATION_CONSUMES_API,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ describe('<HasApisCard />', () => {
},
relations: [
{
target: {
kind: 'api',
namespace: 'my-namespace',
name: 'target-name',
},
targetRef: 'api:my-namespace/target-name',
type: RELATION_HAS_PART,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ describe('<ProvidedApisCard />', () => {
},
relations: [
{
target: {
kind: 'api',
namespace: 'my-namespace',
name: 'target-name',
},
targetRef: 'api:my-namespace/target-name',
type: RELATION_PROVIDES_API,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ describe('<ConsumingComponentsCard />', () => {
},
relations: [
{
target: {
kind: 'component',
namespace: 'my-namespace',
name: 'target-name',
},
targetRef: 'component:my-namespace/target-name',
type: RELATION_API_CONSUMED_BY,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ describe('<ProvidingComponentsCard />', () => {
},
relations: [
{
target: {
kind: 'component',
namespace: 'my-namespace',
name: 'target-name',
},
targetRef: 'component:my-namespace/target-name',
type: RELATION_API_PROVIDED_BY,
},
Expand Down
10 changes: 0 additions & 10 deletions plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ describe('CatalogIdentityClient', () => {
{
type: RELATION_MEMBER_OF,
targetRef: 'group:default/team-a',
target: {
kind: 'group',
namespace: 'default',
name: 'team-a',
},
},
],
},
Expand All @@ -102,11 +97,6 @@ describe('CatalogIdentityClient', () => {
{
type: RELATION_MEMBER_OF,
targetRef: 'group:reality/screen-actors-guild',
target: {
kind: 'group',
namespace: 'reality',
name: 'screen-actors-guild',
},
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ describe('isEntityOwner', () => {
{
type: 'ownedBy',
targetRef: 'user:default/spiderman',
target: {
kind: 'user',
namespace: 'default',
name: 'spiderman',
},
},
],
};
Expand All @@ -54,11 +49,6 @@ describe('isEntityOwner', () => {
{
type: 'ownedBy',
targetRef: 'user:default/green-goblin',
target: {
kind: 'user',
namespace: 'default',
name: 'green-goblin',
},
},
],
};
Expand Down
27 changes: 1 addition & 26 deletions plugins/catalog-backend/src/service/DefaultEntitiesCatalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
* limitations under the License.
*/

import {
Entity,
parseEntityRef,
stringifyEntityRef,
} from '@backstage/catalog-model';
import { Entity, stringifyEntityRef } from '@backstage/catalog-model';
import { InputError, NotFoundError } from '@backstage/errors';
import { Knex } from 'knex';
import lodash from 'lodash';
Expand Down Expand Up @@ -204,27 +200,6 @@ export class DefaultEntitiesCatalog implements EntitiesCatalog {
entities = entities.map(e => request.fields!(e));
}

// TODO(freben): This is added as a compatibility guarantee, until we can be
// sure that all adopters have re-stitched their entities so that the new
// targetRef field is present on them, and that they have stopped consuming
// the now-removed old field
for (const entity of entities) {
if (entity.relations) {
for (const relation of entity.relations) {
if (!relation.targetRef && relation.target) {
// This is the case where an old-form entity, not yet stitched with
// the updated code, was in the database
relation.targetRef = stringifyEntityRef(relation.target);
} else if (!relation.target && relation.targetRef) {
// This is the case where a new-form entity, stitched with the
// updated code, was in the database but we still want to produce
// the old data shape as well for compatibility reasons
relation.target = parseEntityRef(relation.targetRef);
}
}
}
}

return {
entities,
pageInfo,
Expand Down
3 changes: 0 additions & 3 deletions plugins/catalog-backend/src/stitching/Stitcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import { ENTITY_STATUS_CATALOG_PROCESSING_TYPE } from '@backstage/catalog-client';
import {
AlphaEntity,
parseEntityRef,
EntityRelation,
EntityStatusItem,
} from '@backstage/catalog-model';
Expand Down Expand Up @@ -186,8 +185,6 @@ export class Stitcher {
.filter(row => row.relationType /* exclude null row, if relevant */)
.map<EntityRelation>(row => ({
type: row.relationType!,
// TODO(freben): This field is deprecated and should be removed in a future release
target: parseEntityRef(row.relationTarget!),
targetRef: row.relationTarget!,
}));
if (statusItems.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,10 @@ describe('buildEntitySearch', () => {
{
type: 't1',
targetRef: 'k:ns/a',
target: { kind: 'k', namespace: 'ns', name: 'a' },
},
{
type: 't2',
targetRef: 'k:ns/b',
target: { kind: 'k', namespace: 'ns', name: 'b' },
},
],
apiVersion: 'a',
Expand Down Expand Up @@ -192,12 +190,10 @@ describe('buildEntitySearch', () => {
{
type: 'dup',
targetRef: 'k:ns/a',
target: { kind: 'k', namespace: 'ns', name: 'a' },
},
{
type: 'DUP',
targetRef: 'k:ns/b',
target: { kind: 'k', namespace: 'ns', name: 'b' },
},
],
apiVersion: 'a',
Expand Down

0 comments on commit d3e9ec4

Please sign in to comment.