Browse Source

Fix/2012 Migration bug fixes (#2053)

* chore: add migration to convert column types

re #2012

Signed-off-by: Pranav C <pranavxc@gmail.com>

* fix: handle null case

Signed-off-by: Pranav C <pranavxc@gmail.com>

* fix: skip if viewColumn not found

Signed-off-by: Pranav C <pranavxc@gmail.com>

* fix: handle null case in sort or filter migration

Signed-off-by: Pranav C <pranavxc@gmail.com>

* refactor: limit help text to 254 chars

Signed-off-by: Pranav C <pranavxc@gmail.com>

* refactor: migration filename correction

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/2068/head
Pranav C 3 years ago committed by GitHub
parent
commit
1d1535905c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      packages/nocodb/src/lib/noco/common/XcMigrationSourcev2.ts
  2. 66
      packages/nocodb/src/lib/noco/migrationsv2/nc_014_alter_column_data_types.ts
  3. 30
      packages/nocodb/src/lib/noco/upgrader/jobs/ncProjectUpgraderV2_0090000.ts

6
packages/nocodb/src/lib/noco/common/XcMigrationSourcev2.ts

@ -1,6 +1,7 @@
import * as nc_011 from '../migrationsv2/nc_011';
import * as nc_012_alter_column_data_types from '../migrationsv2/nc_012_alter_column_data_types';
import * as nc_013_sync_source from '../migrationsv2/nc_013_sync_source';
import * as nc_014_alter_column_data_types from '../migrationsv2/nc_014_alter_column_data_types';
// Create a custom migration source class
export default class XcMigrationSourcev2 {
@ -12,7 +13,8 @@ export default class XcMigrationSourcev2 {
return Promise.resolve([
'nc_011',
'nc_012_alter_column_data_types',
'nc_013_sync_source'
'nc_013_sync_source',
'nc_014_alter_column_data_types'
]);
}
@ -28,6 +30,8 @@ export default class XcMigrationSourcev2 {
return nc_012_alter_column_data_types;
case 'nc_013_sync_source':
return nc_013_sync_source;
case 'nc_014_alter_column_data_types':
return nc_014_alter_column_data_types;
}
}
}

66
packages/nocodb/src/lib/noco/migrationsv2/nc_014_alter_column_data_types.ts

@ -0,0 +1,66 @@
import Knex from 'knex';
import { MetaTable } from '../../utils/globals';
const up = async (knex: Knex) => {
if (knex.client.config.client !== 'sqlite3') {
await knex.schema.alterTable(MetaTable.FORM_VIEW, table => {
table.text('success_msg').alter();
});
await knex.schema.alterTable(MetaTable.FORM_VIEW, table => {
table.text('redirect_url').alter();
});
await knex.schema.alterTable(MetaTable.FORM_VIEW, table => {
table.text('banner_image_url').alter();
});
await knex.schema.alterTable(MetaTable.FORM_VIEW, table => {
table.text('logo_url').alter();
});
await knex.schema.alterTable(MetaTable.FORM_VIEW_COLUMNS, table => {
table.text('description').alter();
});
}
};
const down = async knex => {
if (knex.client.config.client !== 'sqlite3') {
await knex.schema.alterTable(MetaTable.FORM_VIEW, table => {
table.string('success_msg').alter();
});
await knex.schema.alterTable(MetaTable.FORM_VIEW, table => {
table.string('redirect_url').alter();
});
await knex.schema.alterTable(MetaTable.FORM_VIEW, table => {
table.string('banner_image_url').alter();
});
await knex.schema.alterTable(MetaTable.FORM_VIEW, table => {
table.string('logo_url').alter();
});
await knex.schema.alterTable(MetaTable.FORM_VIEW_COLUMNS, table => {
table.string('description').alter();
});
}
};
export { up, down };
/**
* @copyright Copyright (c) 2022, Xgene Cloud Ltd
*
* @author Wing-Kam Wong <wingkwong.code@gmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

30
packages/nocodb/src/lib/noco/upgrader/jobs/ncProjectUpgraderV2_0090000.ts

@ -777,8 +777,12 @@ async function migrateProjectModels(
});
let orderCount = 1;
for (const [_cn, column] of aliasColArr) {
const viewColumn = viewColumns.find(
c => column.id === c.fk_column_id
);
if (!viewColumn) continue;
await GridViewColumn.update(
viewColumns.find(c => column.id === c.fk_column_id).id,
viewColumn.id,
{
order: orderCount++,
show: queryParams?.showFields
@ -947,7 +951,7 @@ async function migrateProjectModelViews(
await FormViewColumn.update(
viewColumn.id,
{
help: columnParams?.help,
help: columnParams?.help?.slice(0, 254),
label: columnParams?.label,
required: columnParams?.required,
description: columnParams?.description,
@ -957,8 +961,10 @@ async function migrateProjectModelViews(
ncMeta
);
} else if (viewData.show_as === 'grid') {
const viewColumn = viewColumns.find(c => column.id === c.fk_column_id);
if (!viewColumn) continue;
await GridViewColumn.update(
viewColumns.find(c => column.id === c.fk_column_id).id,
viewColumn.id,
{
order,
show,
@ -1025,9 +1031,9 @@ async function migrateViewsParams(
{
fk_column_id: sort.field
? (
objModelColumnAliasRef[projectId][tn][sort.field] ||
objModelColumnRef[projectId][tn][sort.field]
).id
objModelColumnAliasRef[projectId]?.[tn]?.[sort.field] ||
objModelColumnRef[projectId]?.[tn]?.[sort.field]
)?.id || null
: null,
fk_view_id: view.id,
direction: sort.order === '-' ? 'desc' : 'asc'
@ -1041,7 +1047,10 @@ async function migrateViewsParams(
await Filter.insert(
{
fk_column_id: filter.field
? objModelColumnAliasRef[projectId][tn][filter.field].id
? (
objModelColumnAliasRef?.[projectId]?.[tn]?.[filter.field] ||
objModelColumnRef?.[projectId]?.[tn]?.[filter.field]
)?.id || null
: null,
fk_view_id: view.id,
comparison_op: filterV1toV2CompOpMap[filter.op],
@ -1071,7 +1080,7 @@ async function migrateUIAcl(ctx: MigrateCtxV1, ncMeta: any) {
for (const acl of uiAclList) {
// if missing model name skip the view acl migration
if (!acl.title) continue;
if (!acl?.title) continue;
let fk_view_id;
if (acl.type === 'vtable') {
@ -1231,7 +1240,10 @@ async function migrateWebhooks(ctx: MigrateCtxV1, ncMeta: any) {
}> = await ncMeta.metaList(null, null, 'nc_hooks');
for (const hookMeta of hooks) {
if (!hookMeta.project_id) {
if (
!hookMeta.project_id ||
!ctx.objModelRef[hookMeta?.project_id]?.[hookMeta?.tn]
) {
continue;
}
const hook = await Hook.insert(

Loading…
Cancel
Save