Merge pull request #16321 from szubster/techinsights-latest-fact-index

Add new index to techinsights
This commit is contained in:
Ben Lambert
2023-02-20 14:07:16 +01:00
committed by GitHub
2 changed files with 41 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-tech-insights-backend': patch
---
Add DB index to improve latency of latest fact query
@@ -0,0 +1,36 @@
/*
* Copyright 2023 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.
*/
const indexName = 'fact_id_entity_timestamp_idx';
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async knex => {
await knex.schema.alterTable('facts', table => {
table.index(['id', 'entity', 'timestamp'], indexName);
});
};
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async knex => {
await knex.schema.alterTable('facts', table => {
table.dropIndex(indexName);
});
};