Browse Source

fix: handle partially upgraded case

pull/7373/head
mertmit 11 months ago
parent
commit
ce13caa757
  1. 28
      packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedSystemFieldsUpgrader.ts

28
packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedSystemFieldsUpgrader.ts

@ -260,6 +260,19 @@ async function upgradeModels({
}
if (!isCreatedByExists) {
const columnName = getUniqueColumnName(columns, 'created_by');
const dbColumn = dbColumns.find((c) => c.cn === columnName);
// if column already exist in db but not in meta, just update the meta (partial upgraded case)
if (dbColumn) {
existingDbColumns.push({
uidt: UITypes.CreatedBy,
...dbColumn,
column_name: columnName,
title: getUniqueColumnAliasName(columns, 'nc_created_by'),
system: true,
});
} else {
newColumns.push({
...(await getColumnPropsFromUIDT(
{
@ -277,8 +290,22 @@ async function upgradeModels({
altered: Altered.NEW_COLUMN,
});
}
}
if (!isLastModifiedByExists) {
const columnName = getUniqueColumnName(columns, 'updated_by');
const dbColumn = dbColumns.find((c) => c.cn === columnName);
// if column already exist in db but not in meta, just update the meta (partial upgraded case)
if (dbColumn) {
existingDbColumns.push({
uidt: UITypes.LastModifiedBy,
...dbColumn,
column_name: columnName,
title: getUniqueColumnAliasName(columns, 'nc_updated_by'),
system: true,
});
} else {
newColumns.push({
...(await getColumnPropsFromUIDT(
{
@ -296,6 +323,7 @@ async function upgradeModels({
altered: Altered.NEW_COLUMN,
});
}
}
// alter table and add new columns if any
if (newColumns.length) {

Loading…
Cancel
Save