Browse Source

fix: avoid setting updated_at when inserting record

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

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

@ -11,6 +11,7 @@ import {
isCurrency, isCurrency,
isDate, isDate,
isDateTime, isDateTime,
isReadonlyDateTime,
isDecimal, isDecimal,
isDuration, isDuration,
isFloat, isFloat,
@ -80,6 +81,7 @@ const checkTypeFunctions = {
isPercent, isPercent,
isCurrency, isCurrency,
isDecimal, isDecimal,
isReadonlyDateTime,
isInt, isInt,
isFloat, isFloat,
isTextArea, isTextArea,
@ -142,6 +144,7 @@ const componentMap: Partial<Record<FilterType, any>> = computed(() => {
isDate: renderDateFilterInput(props.filter.comparison_sub_op!), isDate: renderDateFilterInput(props.filter.comparison_sub_op!),
isYear: YearPicker, isYear: YearPicker,
isDateTime: renderDateFilterInput(props.filter.comparison_sub_op!), isDateTime: renderDateFilterInput(props.filter.comparison_sub_op!),
isReadonlyDateTime: renderDateFilterInput(props.filter.comparison_sub_op!),
isTime: TimePicker, isTime: TimePicker,
isRating: Rating, isRating: Rating,
isDuration: Duration, 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 isTime = (column: ColumnType, abstractType: any) => abstractType === 'time' || column.uidt === UITypes.Time
export const isDateTime = (column: ColumnType, abstractType: any) => export const isDateTime = (column: ColumnType, abstractType: any) =>
abstractType === 'datetime' || column.uidt === UITypes.DateTime 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 isJSON = (column: ColumnType) => column.uidt === UITypes.JSON
export const isEnum = (column: ColumnType) => column.uidt === UITypes.SingleSelect export const isEnum = (column: ColumnType) => column.uidt === UITypes.SingleSelect
export const isSingleSelect = (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), text: getGtText(fieldUiType),
value: 'gt', value: 'gt',
ignoreVal: false, 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), text: getLtText(fieldUiType),
value: 'lt', value: 'lt',
ignoreVal: false, 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), text: getGteText(fieldUiType),
value: 'gte', value: 'gte',
ignoreVal: false, 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), text: getLteText(fieldUiType),
@ -263,7 +284,7 @@ export const comparisonOpList = (
text: 'is within', text: 'is within',
value: 'isWithin', value: 'isWithin',
ignoreVal: true, ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
}, },
{ {
text: 'is blank', text: 'is blank',
@ -298,49 +319,49 @@ export const comparisonSubOpList = (
text: 'the past week', text: 'the past week',
value: 'pastWeek', value: 'pastWeek',
ignoreVal: true, ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
}, },
{ {
text: 'the past month', text: 'the past month',
value: 'pastMonth', value: 'pastMonth',
ignoreVal: true, ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
}, },
{ {
text: 'the past year', text: 'the past year',
value: 'pastYear', value: 'pastYear',
ignoreVal: true, ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
}, },
{ {
text: 'the next week', text: 'the next week',
value: 'nextWeek', value: 'nextWeek',
ignoreVal: true, ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
}, },
{ {
text: 'the next month', text: 'the next month',
value: 'nextMonth', value: 'nextMonth',
ignoreVal: true, ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
}, },
{ {
text: 'the next year', text: 'the next year',
value: 'nextYear', value: 'nextYear',
ignoreVal: true, ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
}, },
{ {
text: 'the next number of days', text: 'the next number of days',
value: 'nextNumberOfDays', value: 'nextNumberOfDays',
ignoreVal: false, ignoreVal: false,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
}, },
{ {
text: 'the past number of days', text: 'the past number of days',
value: 'pastNumberOfDays', value: 'pastNumberOfDays',
ignoreVal: false, 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', text: 'today',
value: 'today', value: 'today',
ignoreVal: true, ignoreVal: true,
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])], includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime])],
}, },
{ {
text: 'tomorrow', text: 'tomorrow',
value: 'tomorrow', value: 'tomorrow',
ignoreVal: true, ignoreVal: true,
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])], includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime])],
}, },
{ {
text: 'yesterday', text: 'yesterday',
value: 'yesterday', value: 'yesterday',
ignoreVal: true, ignoreVal: true,
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])], includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTim, UITypes.LastModifiedTime, UITypes.CreatedTimee])],
}, },
{ {
text: 'one week ago', text: 'one week ago',
value: 'oneWeekAgo', value: 'oneWeekAgo',
ignoreVal: true, ignoreVal: true,
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])], includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime])],
}, },
{ {
text: 'one week from now', text: 'one week from now',
value: 'oneWeekFromNow', value: 'oneWeekFromNow',
ignoreVal: true, ignoreVal: true,
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])], includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime])],
}, },
{ {
text: 'one month ago', text: 'one month ago',
value: 'oneMonthAgo', value: 'oneMonthAgo',
ignoreVal: true, ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
}, },
{ {
text: 'one month from now', text: 'one month from now',
value: 'oneMonthFromNow', value: 'oneMonthFromNow',
ignoreVal: true, ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime],
}, },
{ {
text: 'number of days ago', text: 'number of days ago',
value: 'daysAgo', value: 'daysAgo',
ignoreVal: false, ignoreVal: false,
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])], includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime])],
}, },
{ {
text: 'number of days from now', text: 'number of days from now',
value: 'daysFromNow', value: 'daysFromNow',
ignoreVal: false, ignoreVal: false,
includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])], includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime, UITypes.LastModifiedTime, UITypes.CreatedTime])],
}, },
{ {
text: isDateMonth ? 'exact month' : 'exact date', text: isDateMonth ? 'exact month' : 'exact date',
value: 'exactDate', value: 'exactDate',
ignoreVal: false, 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', title: 'CreatedAt',
dt: 'datetime', dt: 'datetime',
dtx: 'specificType', dtx: 'specificType',
ct: 'varchar(45)', ct: 'datetime',
nrqd: true, nrqd: true,
rqd: false, rqd: false,
ck: false, ck: false,
@ -117,7 +117,7 @@ export class MssqlUi {
title: 'UpdatedAt', title: 'UpdatedAt',
dt: 'datetime', dt: 'datetime',
dtx: 'specificType', dtx: 'specificType',
ct: 'varchar(45)', ct: 'datetime',
nrqd: true, nrqd: true,
rqd: false, rqd: false,
ck: false, ck: false,
@ -125,7 +125,6 @@ export class MssqlUi {
un: false, un: false,
ai: false, ai: false,
au: true, au: true,
cdf: 'GETDATE()',
clen: 45, clen: 45,
np: null, np: null,
ns: null, ns: null,
@ -741,7 +740,6 @@ export class MssqlUi {
break; break;
case 'LastModifiedTime': case 'LastModifiedTime':
colProp.dt = 'datetime'; colProp.dt = 'datetime';
colProp.cdf = 'GETDATE()';
break; break;
case 'AutoNumber': case 'AutoNumber':
colProp.dt = 'int'; colProp.dt = 'int';

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

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

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

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

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

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

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

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

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

@ -5662,7 +5662,11 @@ class BaseModelSqlv2 {
) { ) {
data[column.column_name] = Noco.ncMeta.now(); 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(); data[column.column_name] = Noco.ncMeta.now();
} }
if (column.uidt === UITypes.Attachment) { 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_eq' ||
(filter.comparison_op as any) === 'gb_null' (filter.comparison_op as any) === 'gb_null'
) { ) {
(filter as any).groupby = true;
const column = await getRefColumnIfAlias(await filter.getColumn()); const column = await getRefColumnIfAlias(await filter.getColumn());
if ( if (
@ -682,7 +684,9 @@ const parseConditionV2 = async (
].includes(column.uidt) ].includes(column.uidt)
) { ) {
if (qb.client.config.client === 'pg') { 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 { } else {
qb = qb.where(knex.raw('DATE(??) = DATE(?)', [field, val])); qb = qb.where(knex.raw('DATE(??) = DATE(?)', [field, val]));
} }

Loading…
Cancel
Save