oh vale, how i love thee

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-02-19 13:46:45 +01:00
parent 919cf2f836
commit 78e1bb7fd1
4 changed files with 38 additions and 3 deletions
+2
View File
@@ -278,6 +278,8 @@ sqlite
squidfunk
src
stdout
stringify
stringified
subcomponent
subcomponents
subkey
@@ -0,0 +1,31 @@
/*
* Copyright 2021 The Backstage Authors
*
* 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.
*/
// @ts-check
/**
* @param {import('knex').Knex} knex
*/
exports.up = async function up(knex) {
// Make sure to reprocess everything, to make sure that relations have a targetRef produced
await knex('refresh_state').update({
result_hash: '',
next_update_at: knex.fn.now(),
});
await knex('final_entities').update({ hash: '' });
};
exports.down = async function down() {};
@@ -211,11 +211,11 @@ export class DefaultEntitiesCatalog implements EntitiesCatalog {
for (const entity of entities) {
if (entity.relations) {
for (const relation of entity.relations) {
if (!relation.targetRef) {
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) {
} 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
@@ -18,6 +18,7 @@ import { ENTITY_STATUS_CATALOG_PROCESSING_TYPE } from '@backstage/catalog-client
import {
AlphaEntity,
parseEntityRef,
EntityRelation,
EntityStatusItem,
} from '@backstage/catalog-model';
import { SerializedError, stringifyError } from '@backstage/errors';
@@ -183,8 +184,9 @@ export class Stitcher {
);
entity.relations = uniqueRelationRows
.filter(row => row.relationType /* exclude null row, if relevant */)
.map(row => ({
.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!,
}));