From 08b867ad2260cbd1e719801970a0b28b1f5bd287 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 4 Jan 2024 13:19:20 +0000 Subject: [PATCH] feat: update last modified time when updating --- packages/nocodb/src/db/BaseModelSqlv2.ts | 89 +++++++++++++++++++++++- 1 file changed, 86 insertions(+), 3 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 7d6ff370d3..ddee9ba865 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -3974,6 +3974,15 @@ class BaseModelSqlv2 { { raw: true }, ); } + + await this.updateLastModifiedTime({ + model: parentTable, + rowIds: [childId], + }); + await this.updateLastModifiedTime({ + model: childTable, + rowIds: [rowId], + }); } break; case RelationTypes.HAS_MANY: @@ -3993,6 +4002,11 @@ class BaseModelSqlv2 { null, { raw: true }, ); + + await this.updateLastModifiedTime({ + model: parentTable, + rowIds: [rowId], + }); } break; case RelationTypes.BELONGS_TO: @@ -4012,6 +4026,11 @@ class BaseModelSqlv2 { null, { raw: true }, ); + + await this.updateLastModifiedTime({ + model: parentTable, + rowIds: [childId], + }); } break; } @@ -4105,6 +4124,15 @@ class BaseModelSqlv2 { null, { raw: true }, ); + + await this.updateLastModifiedTime({ + model: parentTable, + rowIds: [childId], + }); + await this.updateLastModifiedTime({ + model: childTable, + rowIds: [rowId], + }); } break; case RelationTypes.HAS_MANY: @@ -4122,6 +4150,11 @@ class BaseModelSqlv2 { null, { raw: true }, ); + + await this.updateLastModifiedTime({ + model: parentTable, + rowIds: [rowId], + }); } break; case RelationTypes.BELONGS_TO: @@ -4139,6 +4172,11 @@ class BaseModelSqlv2 { null, { raw: true }, ); + + await this.updateLastModifiedTime({ + model: parentTable, + rowIds: [childId], + }); } break; } @@ -5048,6 +5086,15 @@ class BaseModelSqlv2 { await this.execAndParse(this.dbDriver(vTn).insert(insertData), null, { raw: true, }); + + await this.updateLastModifiedTime({ + model: parentTable, + rowIds: childIds, + }); + await this.updateLastModifiedTime({ + model: childTable, + rowIds: [rowId], + }); } break; case RelationTypes.HAS_MANY: @@ -5122,6 +5169,11 @@ class BaseModelSqlv2 { ); } await this.execAndParse(updateQb, null, { raw: true }); + + await this.updateLastModifiedTime({ + model: parentTable, + rowIds: [rowId], + }); } break; case RelationTypes.BELONGS_TO: @@ -5164,6 +5216,11 @@ class BaseModelSqlv2 { null, { raw: true }, ); + + await this.updateLastModifiedTime({ + model: parentTable, + rowIds: [rowId], + }); } break; } @@ -5305,6 +5362,15 @@ class BaseModelSqlv2 { : childIds, ); await this.execAndParse(delQb, null, { raw: true }); + + await this.updateLastModifiedTime({ + model: parentTable, + rowIds: childIds, + }); + await this.updateLastModifiedTime({ + model: childTable, + rowIds: [rowId], + }); } break; case RelationTypes.HAS_MANY: @@ -5385,6 +5451,11 @@ class BaseModelSqlv2 { null, { raw: true }, ); + + await this.updateLastModifiedTime({ + model: parentTable, + rowIds: [rowId], + }); } break; case RelationTypes.BELONGS_TO: @@ -5430,6 +5501,11 @@ class BaseModelSqlv2 { null, { raw: true }, ); + + await this.updateLastModifiedTime({ + model: parentTable, + rowIds: [childIds[0]], + }); } break; } @@ -5515,14 +5591,21 @@ class BaseModelSqlv2 { } } - async updateLastModifiedTime({ rowIds }: { rowIds: any | any[] }) { + async updateLastModifiedTime({ + rowIds, + model = this.model, + knex = this.dbDriver, + }: { + rowIds: any | any[]; + model?: Model; + }) { const columnName = 'updated_at'; - const qb = this.dbDriver(this.tnPath).update({ + const qb = knex(model.table_name).update({ [columnName]: this.dbDriver.fn.now(), }); - for(const rowId of rowIds) { + for (const rowId of Array.isArray(rowIds) ? rowIds : [rowIds]) { qb.orWhere(await this._wherePk(rowId)); }