Browse Source

fix: Upgrader - remove trigger(pg) and remove default value

pull/7304/head
Pranav C 11 months ago
parent
commit
cd06461951
  1. 39
      packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedTimeUpgrader.ts

39
packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedTimeUpgrader.ts

@ -17,6 +17,26 @@ import { Altered } from '~/services/columns.service';
const logger = new Logger('ncXcdbCreatedAndUpdatedTimeUpgrader'); const logger = new Logger('ncXcdbCreatedAndUpdatedTimeUpgrader');
async function deletePgTrigger({
column,
ncMeta,
model,
}: {
ncMeta: MetaService;
column: Column;
model: Model;
}) {
// delete pg trigger
const triggerFnName = `xc_au_${model.table_name}_${column.column_name}`;
const triggerName = `xc_trigger_${model.table_name}_${column.column_name}`;
await ncMeta.knex.raw(`DROP TRIGGER IF EXISTS ?? ON ??;`, [
triggerName,
model.table_name,
]);
await ncMeta.knex.raw(`DROP FUNCTION IF EXISTS ??()`, [triggerFnName]);
}
async function upgradeModels({ async function upgradeModels({
ncMeta, ncMeta,
source, source,
@ -35,6 +55,7 @@ async function upgradeModels({
await Promise.all( await Promise.all(
models.map(async (model: any) => { models.map(async (model: any) => {
const columns = await model.getColumns(ncMeta); const columns = await model.getColumns(ncMeta);
const oldColumns = columns.map((c) => ({ ...c, cn: c.column_name }));
let isCreatedTimeExists = false; let isCreatedTimeExists = false;
let isLastModifiedTimeExists = false; let isLastModifiedTimeExists = false;
for (const column of columns) { for (const column of columns) {
@ -49,14 +70,27 @@ async function upgradeModels({
}, },
ncMeta, ncMeta,
); );
if (source.type === 'pg') {
// delete pg trigger if exists
await deletePgTrigger({ column, ncMeta, model });
}
} }
if (column.uidt === 'updated_at') { if (column.uidt === 'updated_at') {
isLastModifiedTimeExists = true; isLastModifiedTimeExists = true;
Object.assign(column, {
uidt: UITypes.LastModifiedTime,
system: true,
cdf: '',
au: false,
});
await Column.update( await Column.update(
column.id, column.id,
{ {
uidt: UITypes.LastModifiedTime, uidt: UITypes.LastModifiedTime,
system: true, system: true,
cdf: '',
au: false,
}, },
ncMeta, ncMeta,
); );
@ -103,10 +137,7 @@ async function upgradeModels({
const tableUpdateBody = { const tableUpdateBody = {
...model, ...model,
tn: model.table_name, tn: model.table_name,
originalColumns: model.columns.map((c) => ({ originalColumns: oldColumns,
...c,
cn: c.column_name,
})),
columns: [ columns: [
...columns.map((c) => ({ ...c, cn: c.column_name })), ...columns.map((c) => ({ ...c, cn: c.column_name })),
...newColumns, ...newColumns,

Loading…
Cancel
Save