Browse Source

feat: update last modified time when updating

pull/7304/head
Pranav C 11 months ago
parent
commit
08b867ad22
  1. 89
      packages/nocodb/src/db/BaseModelSqlv2.ts

89
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));
}

Loading…
Cancel
Save