From 1003f52b19a952cb5c298f7c39cfb8ba2bfeb3d4 Mon Sep 17 00:00:00 2001 From: iris Date: Mon, 12 Dec 2022 15:05:43 +0800 Subject: [PATCH] Change last_updated_at to dateTime Signed-off-by: iris --- .../20221201085245_add_last_updated_at_in_final_entities.js | 2 +- plugins/catalog-backend/src/database/tables.ts | 2 +- plugins/catalog-backend/src/stitching/Stitcher.ts | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/catalog-backend/migrations/20221201085245_add_last_updated_at_in_final_entities.js b/plugins/catalog-backend/migrations/20221201085245_add_last_updated_at_in_final_entities.js index d12d5bec3e..e34d45ade6 100644 --- a/plugins/catalog-backend/migrations/20221201085245_add_last_updated_at_in_final_entities.js +++ b/plugins/catalog-backend/migrations/20221201085245_add_last_updated_at_in_final_entities.js @@ -17,7 +17,7 @@ exports.up = async function up(knex) { await knex.schema.table('final_entities', table => { table - .bigint('last_updated_at') + .dateTime('last_updated_at') .nullable() .comment('The time when final_entity changed'); }); diff --git a/plugins/catalog-backend/src/database/tables.ts b/plugins/catalog-backend/src/database/tables.ts index 2778cf2fba..9d89b17d16 100644 --- a/plugins/catalog-backend/src/database/tables.ts +++ b/plugins/catalog-backend/src/database/tables.ts @@ -66,7 +66,7 @@ export type DbFinalEntitiesRow = { hash: string; stitch_ticket: string; final_entity?: string; - last_updated_at: string | null; + last_updated_at: string | Date; }; export type DbSearchRow = { diff --git a/plugins/catalog-backend/src/stitching/Stitcher.ts b/plugins/catalog-backend/src/stitching/Stitcher.ts index c3892244dd..4742c81933 100644 --- a/plugins/catalog-backend/src/stitching/Stitcher.ts +++ b/plugins/catalog-backend/src/stitching/Stitcher.ts @@ -23,7 +23,6 @@ import { import { SerializedError, stringifyError } from '@backstage/errors'; import { Knex } from 'knex'; import { v4 as uuid } from 'uuid'; -import { DateTime } from 'luxon'; import { Logger } from 'winston'; import { DbFinalEntitiesRow, @@ -208,12 +207,12 @@ export class Stitcher { .update({ final_entity: JSON.stringify(entity), hash, - last_updated_at: `${DateTime.now().toMillis()}`, + last_updated_at: this.database.fn.now(), }) .where('entity_id', entityId) .where('stitch_ticket', ticket) .onConflict('entity_id') - .merge(['final_entity', 'hash']); + .merge(['final_entity', 'hash', 'last_updated_at']); if (amountOfRowsChanged === 0) { this.logger.debug(