Browse Source

fix: avoid setting updated_at when inserting record

pull/7304/head
Pranav C 9 months ago
parent
commit
ae052c99a0
  1. 15
      packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue
  2. 3
      packages/nc-gui/components/smartsheet/toolbar/FilterInput.vue
  3. 2
      packages/nc-gui/utils/cell.ts
  4. 65
      packages/nc-gui/utils/filterUtils.ts
  5. 6
      packages/nocodb-sdk/src/lib/sqlUi/MssqlUi.ts
  6. 5
      packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts
  7. 8
      packages/nocodb-sdk/src/lib/sqlUi/PgUi.ts
  8. 7
      packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts
  9. 6
      packages/nocodb-sdk/src/lib/sqlUi/SqliteUi.ts
  10. 6
      packages/nocodb/src/db/BaseModelSqlv2.ts
  11. 6
      packages/nocodb/src/db/conditionV2.ts

15
packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue

@ -143,7 +143,7 @@ const filterUpdateCondition = (filter: FilterType, i: number) => {
// hence remove the previous value
filter.value = null
filter.comparison_sub_op = null
} else if ([UITypes.Date, UITypes.DateTime].includes(col.uidt as UITypes)) {
} else if (isDateType(col.uidt as UITypes)) {
// for date / datetime,
// the input type could be decimal or datepicker / datetime picker
// hence remove the previous value
@ -241,10 +241,7 @@ const selectFilterField = (filter: Filter, index: number) => {
isComparisonOpAllowed(filter, compOp),
)?.value as FilterType['comparison_op']
if (
[UITypes.Date, UITypes.DateTime, UITypes.CreatedTime, UITypes.LastModifiedTime].includes(col.uidt as UITypes) &&
!['blank', 'notblank'].includes(filter.comparison_op!)
) {
if (isDateType(col.uidt as UITypes) && !['blank', 'notblank'].includes(filter.comparison_op!)) {
if (filter.comparison_op === 'isWithin') {
filter.comparison_sub_op = 'pastNumberOfDays'
} else {
@ -338,6 +335,10 @@ onMounted(async () => {
onBeforeUnmount(() => {
if (parentId.value) delete allFilters.value[parentId.value]
})
function isDateType(uidt: UITypes) {
return [UITypes.Date, UITypes.DateTime, UITypes.CreatedTime, UITypes.LastModifiedTime].includes(uidt)
}
</script>
<template>
@ -480,7 +481,7 @@ onBeforeUnmount(() => {
<div v-if="['blank', 'notblank'].includes(filter.comparison_op)" class="flex flex-grow"></div>
<NcSelect
v-else-if="[UITypes.Date, UITypes.DateTime].includes(getColumn(filter)?.uidt)"
v-else-if="isDateType(getColumn(filter)?.uidt)"
v-model:value="filter.comparison_sub_op"
v-e="['c:filter:sub-comparison-op:select']"
:dropdown-match-select-width="false"
@ -530,7 +531,7 @@ onBeforeUnmount(() => {
@update-filter-value="(value) => updateFilterValue(value, filter, i)"
@click.stop
/>
<div v-else-if="![UITypes.Date, UITypes.DateTime].includes(getColumn(filter)?.uidt)" class="flex-grow"></div>
<div v-else-if="!isDateType(getColumn(filter)?.uidt)" class="flex-grow"></div>
<NcButton
v-if="!filter.readOnly"

3
packages/nc-gui/components/smartsheet/toolbar/FilterInput.vue

@ -11,6 +11,7 @@ import {
isCurrency,
isDate,
isDateTime,
isReadonlyDateTime,
isDecimal,
isDuration,
isFloat,
@ -80,6 +81,7 @@ const checkTypeFunctions = {
isPercent,
isCurrency,
isDecimal,
isReadonlyDateTime,
isInt,
isFloat,
isTextArea,
@ -142,6 +144,7 @@ const componentMap: Partial<Record<FilterType, any>> = computed(() => {
isDate: renderDateFilterInput(props.filter.comparison_sub_op!),
isYear: YearPicker,
isDateTime: renderDateFilterInput(props.filter.comparison_sub_op!),
isReadonlyDateTime: renderDateFilterInput(props.filter.comparison_sub_op!),
isTime: TimePicker,
isRating: Rating,
isDuration: Duration,

2
packages/nc-gui/utils/cell.ts

@ -15,6 +15,8 @@ export const isYear = (column: ColumnType, abstractType: any) => abstractType ==
export const isTime = (column: ColumnType, abstractType: any) => abstractType === 'time' || column.uidt === UITypes.Time
export const isDateTime = (column: ColumnType, abstractType: any) =>
abstractType === 'datetime' || column.uidt === UITypes.DateTime
export const isReadonlyDateTime = (column: ColumnType, _abstractType: any) =>
column.uidt === UITypes.CreatedTime || column.uidt === UITypes.LastModifiedTime
export const isJSON = (column: ColumnType) => column.uidt === UITypes.JSON
export const isEnum = (column: ColumnType) => column.uidt === UITypes.SingleSelect
export const isSingleSelect = (column: ColumnType) => column.uidt === UITypes.SingleSelect

65
packages/nc-gui/utils/filterUtils.ts

@ -239,19 +239,40 @@ export const comparisonOpList = (
text: getGtText(fieldUiType),
value: 'gt',
ignoreVal: false,
includedTypes: [...numericUITypes, UITypes.Date, UITypes.DateTime, UITypes.Time],
includedTypes: [
...numericUITypes,
UITypes.Date,
UITypes.DateTime,
UITypes.LastModifiedTime,
UITypes.CreatedTime,
UITypes.Time,
],
},
{
text: getLtText(fieldUiType),
value: 'lt',
ignoreVal: false,
includedTypes: [...numericUITypes, UITypes.Date, UITypes.DateTime, UITypes.Time],
includedTypes: [
...numericUITypes,
UITypes.Date,
UITypes.DateTime,
UITypes.LastModifiedTime,
UITypes.CreatedTime,
UITypes.Time,
],
},
{
text: getGteText(fieldUiType),
value: 'gte',
ignoreVal: false,
includedTypes: [...numericUITypes, UITypes.Date, UITypes.DateTime, UITypes.Time],
includedTypes: [
...numericUITypes,
UITypes.Date,
UITypes.DateTime,
UITypes.LastModifiedTime,
UITypes.CreatedTime,
UITypes.Time,
],
},
{
text: getLteText(fieldUiType),
@ -263,7 +284,7 @@ export const comparisonOpList = (
text: 'is within',
value: 'isWithin',
ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime],
includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
},
{
text: 'is blank',
@ -298,49 +319,49 @@ export const comparisonSubOpList = (
text: 'the past week',
value: 'pastWeek',
ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime],
includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
},
{
text: 'the past month',
value: 'pastMonth',
ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime],
includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
},
{
text: 'the past year',
value: 'pastYear',
ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime],
includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
},
{
text: 'the next week',
value: 'nextWeek',
ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime],
includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
},
{
text: 'the next month',
value: 'nextMonth',
ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime],
includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
},
{
text: 'the next year',
value: 'nextYear',
ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime],
includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
},
{
text: 'the next number of days',
value: 'nextNumberOfDays',
ignoreVal: false,
includedTypes: [UITypes.Date, UITypes.DateTime],
includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
},
{
text: 'the past number of days',
value: 'pastNumberOfDays',
ignoreVal: false,
includedTypes: [UITypes.Date, UITypes.DateTime],
includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
},
]
}
@ -349,61 +370,61 @@ export const comparisonSubOpList = (
text: 'today',
value: 'today',
ignoreVal: true,
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])],
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime])],
},
{
text: 'tomorrow',
value: 'tomorrow',
ignoreVal: true,
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])],
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime])],
},
{
text: 'yesterday',
value: 'yesterday',
ignoreVal: true,
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])],
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTim, UITypes.LastModifiedTime, UITypes.CreatedTimee])],
},
{
text: 'one week ago',
value: 'oneWeekAgo',
ignoreVal: true,
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])],
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime])],
},
{
text: 'one week from now',
value: 'oneWeekFromNow',
ignoreVal: true,
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])],
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime])],
},
{
text: 'one month ago',
value: 'oneMonthAgo',
ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime],
includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
},
{
text: 'one month from now',
value: 'oneMonthFromNow',
ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime],
includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
},
{
text: 'number of days ago',
value: 'daysAgo',
ignoreVal: false,
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])],
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime])],
},
{
text: 'number of days from now',
value: 'daysFromNow',
ignoreVal: false,
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])],
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime])],
},
{
text: isDateMonth ? 'exact month' : 'exact date',
value: 'exactDate',
ignoreVal: false,
includedTypes: [UITypes.Date, UITypes.DateTime],
includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
},
]
}

6
packages/nocodb-sdk/src/lib/sqlUi/MssqlUi.ts

@ -93,7 +93,7 @@ export class MssqlUi {
title: 'CreatedAt',
dt: 'datetime',
dtx: 'specificType',
ct: 'varchar(45)',
ct: 'datetime',
nrqd: true,
rqd: false,
ck: false,
@ -117,7 +117,7 @@ export class MssqlUi {
title: 'UpdatedAt',
dt: 'datetime',
dtx: 'specificType',
ct: 'varchar(45)',
ct: 'datetime',
nrqd: true,
rqd: false,
ck: false,
@ -125,7 +125,6 @@ export class MssqlUi {
un: false,
ai: false,
au: true,
cdf: 'GETDATE()',
clen: 45,
np: null,
ns: null,
@ -741,7 +740,6 @@ export class MssqlUi {
break;
case 'LastModifiedTime':
colProp.dt = 'datetime';
colProp.cdf = 'GETDATE()';
break;
case 'AutoNumber':
colProp.dt = 'int';

5
packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts

@ -97,7 +97,7 @@ export class MysqlUi {
title: 'CreatedAt',
dt: 'timestamp',
dtx: 'specificType',
ct: 'varchar(45)',
ct: 'timestamp',
nrqd: true,
rqd: false,
ck: false,
@ -121,14 +121,13 @@ export class MysqlUi {
title: 'UpdatedAt',
dt: 'timestamp',
dtx: 'specificType',
ct: 'varchar(45)',
ct: 'timestamp',
nrqd: true,
rqd: false,
ck: false,
pk: false,
un: false,
ai: false,
cdf: 'CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP',
clen: 45,
np: null,
ns: null,

8
packages/nocodb-sdk/src/lib/sqlUi/PgUi.ts

@ -156,7 +156,7 @@ export class PgUi {
title: 'CreatedAt',
dt: 'timestamp',
dtx: 'specificType',
ct: 'varchar(45)',
ct: 'timestamp',
nrqd: true,
rqd: false,
ck: false,
@ -180,15 +180,13 @@ export class PgUi {
title: 'UpdatedAt',
dt: 'timestamp',
dtx: 'specificType',
ct: 'varchar(45)',
ct: 'timestamp',
nrqd: true,
rqd: false,
ck: false,
pk: false,
un: false,
ai: false,
au: true,
cdf: 'now()',
clen: 45,
np: null,
ns: null,
@ -1693,8 +1691,6 @@ export class PgUi {
break;
case 'LastModifiedTime':
colProp.dt = 'timestamp';
colProp.cdf = 'now()';
colProp.au = true;
break;
case 'AutoNumber':
colProp.dt = 'int';

7
packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts

@ -92,7 +92,7 @@ export class SnowflakeUi {
title: 'CreatedAt',
dt: 'timestamp',
dtx: 'specificType',
ct: 'varchar(45)',
ct: 'timestamp',
nrqd: true,
rqd: false,
ck: false,
@ -116,15 +116,13 @@ export class SnowflakeUi {
title: 'UpdatedAt',
dt: 'timestamp',
dtx: 'specificType',
ct: 'varchar(45)',
ct: 'timestamp',
nrqd: true,
rqd: false,
ck: false,
pk: false,
un: false,
ai: false,
au: true,
cdf: 'current_timestamp()',
clen: 45,
np: null,
ns: null,
@ -784,7 +782,6 @@ export class SnowflakeUi {
break;
case 'LastModifiedTime':
colProp.dt = 'TIMESTAMP';
colProp.cdf = 'current_timestamp()';
break;
case 'AutoNumber':
colProp.dt = 'INT';

6
packages/nocodb-sdk/src/lib/sqlUi/SqliteUi.ts

@ -80,7 +80,7 @@ export class SqliteUi {
title: 'CreatedAt',
dt: 'datetime',
dtx: 'specificType',
ct: 'varchar',
ct: 'datetime',
nrqd: true,
rqd: false,
ck: false,
@ -104,14 +104,13 @@ export class SqliteUi {
title: 'UpdatedAt',
dt: 'datetime',
dtx: 'specificType',
ct: 'varchar',
ct: 'datetime',
nrqd: true,
rqd: false,
ck: false,
pk: false,
un: false,
ai: false,
cdf: 'CURRENT_TIMESTAMP',
clen: 45,
np: null,
ns: null,
@ -634,7 +633,6 @@ export class SqliteUi {
break;
case 'LastModifiedTime':
colProp.dt = 'datetime';
colProp.cdf = 'CURRENT_TIMESTAMP';
break;
case 'AutoNumber':
colProp.dt = 'integer';

6
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -5662,7 +5662,11 @@ class BaseModelSqlv2 {
) {
data[column.column_name] = Noco.ncMeta.now();
}
if (column.uidt === UITypes.LastModifiedTime && column.system) {
if (
!isInsertData &&
column.uidt === UITypes.LastModifiedTime &&
column.system
) {
data[column.column_name] = Noco.ncMeta.now();
}
if (column.uidt === UITypes.Attachment) {

6
packages/nocodb/src/db/conditionV2.ts

@ -130,6 +130,8 @@ const parseConditionV2 = async (
(filter.comparison_op as any) === 'gb_eq' ||
(filter.comparison_op as any) === 'gb_null'
) {
(filter as any).groupby = true;
const column = await getRefColumnIfAlias(await filter.getColumn());
if (
@ -682,7 +684,9 @@ const parseConditionV2 = async (
].includes(column.uidt)
) {
if (qb.client.config.client === 'pg') {
qb = qb.where(knex.raw('??::timestamp = ?', [field, val]));
if ((filter as any).groupby)
qb = qb.where(knex.raw('??::timestamp = ?', [field, val]));
else qb = qb.where(knex.raw('??::date = ?', [field, val]));
} else {
qb = qb.where(knex.raw('DATE(??) = DATE(?)', [field, val]));
}

Loading…
Cancel
Save