Browse Source

fix: handle missing display value in upgrader

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/5141/head
mertmit 2 years ago
parent
commit
95f357d2bf
  1. 44
      packages/nocodb/src/lib/version-upgrader/ncStickyColumnUpgrader.ts

44
packages/nocodb/src/lib/version-upgrader/ncStickyColumnUpgrader.ts

@ -38,6 +38,50 @@ export default async function ({ ncMeta }: NcUpgraderCtx) {
view_columns_meta.push(col_meta);
}
// if no display value column is set
if (!view_columns_meta.some((column) => column.pv)) {
const pkIndex = view_columns_meta.findIndex((column) => column.pk)
// if PK is at the end of table
if (pkIndex === view_columns_meta.length - 1) {
if (pkIndex > 0) {
await ncMeta.metaUpdate(
null,
null,
MetaTable.COLUMNS,
{ pv: true },
view_columns_meta[pkIndex - 1].id
);
} else if (view_columns_meta.length > 0) {
await ncMeta.metaUpdate(
null,
null,
MetaTable.COLUMNS,
{ pv: true },
view_columns_meta[0].id
);
}
// pk is not at the end of table
} else if (pkIndex > -1) {
await ncMeta.metaUpdate(
null,
null,
MetaTable.COLUMNS,
{ pv: true },
view_columns_meta[pkIndex + 1].id
);
// no pk at all
} else if (view_columns_meta.length > 0) {
await ncMeta.metaUpdate(
null,
null,
MetaTable.COLUMNS,
{ pv: true },
view_columns_meta[0].id
);
}
}
const primary_value_column_meta = view_columns_meta.find((col) => col.pv);
if (primary_value_column_meta) {

Loading…
Cancel
Save