From a83322d9be602214e6eb1d906a744c3ca018a2aa Mon Sep 17 00:00:00 2001 From: Anton Gugiev Date: Wed, 28 Aug 2024 13:29:00 +0300 Subject: [PATCH] Added updated by fields to embeds model (#173) * CHARTS-10118 added updated by fields to model * Review fix: set updated_at values from created_at --- ...1143300_embeds_change_updated_by_to_not_null.ts | 14 ++++++++++++++ src/db/models/new/embed/index.ts | 4 ++++ .../joined-embed-embedding-secret/index.ts | 2 ++ 3 files changed, 20 insertions(+) create mode 100644 src/db/migrations/20240821143300_embeds_change_updated_by_to_not_null.ts diff --git a/src/db/migrations/20240821143300_embeds_change_updated_by_to_not_null.ts b/src/db/migrations/20240821143300_embeds_change_updated_by_to_not_null.ts new file mode 100644 index 00000000..7c141ae4 --- /dev/null +++ b/src/db/migrations/20240821143300_embeds_change_updated_by_to_not_null.ts @@ -0,0 +1,14 @@ +import {Knex} from 'knex'; + +export async function up(knex: Knex): Promise { + return knex.raw(` + UPDATE embeds SET updated_by = created_by, updated_at = created_at; + ALTER TABLE embeds ALTER COLUMN updated_by SET NOT NULL; + `); +} + +export async function down(knex: Knex): Promise { + return knex.raw(` + ALTER TABLE embeds ALTER COLUMN updated_by DROP NOT NULL; + `); +} diff --git a/src/db/models/new/embed/index.ts b/src/db/models/new/embed/index.ts index 4d205b42..29730e76 100644 --- a/src/db/models/new/embed/index.ts +++ b/src/db/models/new/embed/index.ts @@ -11,6 +11,8 @@ export const EmbedModelColumn = { PublicParamsMode: 'publicParamsMode', CreatedBy: 'createdBy', CreatedAt: 'createdAt', + UpdatedBy: 'updatedBy', + UpdatedAt: 'updatedAt', } as const; export class EmbedModel extends Model { @@ -32,4 +34,6 @@ export class EmbedModel extends Model { [EmbedModelColumn.PublicParamsMode]!: boolean; [EmbedModelColumn.CreatedBy]!: string; [EmbedModelColumn.CreatedAt]!: string; + [EmbedModelColumn.UpdatedBy]!: string; + [EmbedModelColumn.UpdatedAt]!: string; } diff --git a/src/db/presentations/joined-embed-embedding-secret/index.ts b/src/db/presentations/joined-embed-embedding-secret/index.ts index d670633b..bbd507b7 100644 --- a/src/db/presentations/joined-embed-embedding-secret/index.ts +++ b/src/db/presentations/joined-embed-embedding-secret/index.ts @@ -14,6 +14,8 @@ const selectedEmbedColumns = [ EmbedModelColumn.PublicParamsMode, EmbedModelColumn.CreatedBy, EmbedModelColumn.CreatedAt, + EmbedModelColumn.UpdatedBy, + EmbedModelColumn.UpdatedAt, ] as const; const selectedEmbeddingSecretsColumns = [EmbeddingSecretModelColumn.PublicKey] as const;