Browse Source

Merge pull request #3937 from nocodb/fix/at-various

fix: at import failing if more than 64 select options provided
pull/4137/head
աɨռɢӄաօռɢ 2 years ago committed by GitHub
parent
commit
dd9834d359
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts
  2. 123
      packages/nocodb/src/lib/meta/api/columnApis.ts
  3. 16
      packages/nocodb/src/lib/meta/api/sync/helpers/job.ts

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

@ -944,7 +944,7 @@ export class MysqlUi {
}
}
static getDataTypeForUiType(col: { uidt: UITypes }, idType?: IDType) {
static getDataTypeForUiType(col: { uidt: UITypes, dtxp?: string, colOptions?: any }, idType?: IDType) {
const colProp: any = {};
switch (col.uidt) {
case 'ID':
@ -977,6 +977,9 @@ export class MysqlUi {
break;
case 'MultiSelect':
colProp.dt = 'set';
if (col.colOptions?.options.length > 64 || col.dtxp?.split(',').length > 64) {
colProp.dt = 'text';
}
break;
case 'SingleSelect':
colProp.dt = 'enum';

123
packages/nocodb/src/lib/meta/api/columnApis.ts

@ -605,6 +605,12 @@ export async function columnAdd(req: Request, res: Response<TableType>) {
) {
colBody.dtxp = "''";
}
if (colBody.dt === 'set') {
if (colBody.colOptions?.options.length > 64) {
colBody.dt = 'text';
}
}
}
}
@ -901,6 +907,12 @@ export async function columnUpdate(req: Request, res: Response<TableType>) {
) {
colBody.dtxp = "''";
}
if (colBody.dt === 'set') {
if (colBody.colOptions?.options.length > 64) {
colBody.dt = 'text';
}
}
}
// Handle option delete
@ -935,17 +947,30 @@ export async function columnUpdate(req: Request, res: Response<TableType>) {
}
} else if (column.uidt === UITypes.MultiSelect) {
if (driverType === 'mysql' || driverType === 'mysql2') {
await dbDriver.raw(
`UPDATE ?? SET ?? = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', ??, ','), CONCAT(',', ?, ','), ',')) WHERE FIND_IN_SET(?, ??)`,
[
table.table_name,
column.column_name,
column.column_name,
option.title,
option.title,
column.column_name,
]
);
if (colBody.dt === 'set') {
await dbDriver.raw(
`UPDATE ?? SET ?? = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', ??, ','), CONCAT(',', ?, ','), ',')) WHERE FIND_IN_SET(?, ??)`,
[
table.table_name,
column.column_name,
column.column_name,
option.title,
option.title,
column.column_name,
]
);
} else {
await dbDriver.raw(
`UPDATE ?? SET ?? = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', ??, ','), CONCAT(',', ?, ','), ','))`,
[
table.table_name,
column.column_name,
column.column_name,
option.title,
]
);
}
} else if (driverType === 'pg') {
await dbDriver.raw(
`UPDATE ?? SET ?? = array_to_string(array_remove(string_to_array(??, ','), ?), ',')`,
@ -1101,18 +1126,31 @@ export async function columnUpdate(req: Request, res: Response<TableType>) {
}
} else if (column.uidt === UITypes.MultiSelect) {
if (driverType === 'mysql' || driverType === 'mysql2') {
await dbDriver.raw(
`UPDATE ?? SET ?? = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', ??, ','), CONCAT(',', ?, ','), CONCAT(',', ?, ','))) WHERE FIND_IN_SET(?, ??)`,
[
table.table_name,
column.column_name,
column.column_name,
option.title,
newOp.title,
option.title,
column.column_name,
]
);
if (colBody.dt === 'set') {
await dbDriver.raw(
`UPDATE ?? SET ?? = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', ??, ','), CONCAT(',', ?, ','), CONCAT(',', ?, ','))) WHERE FIND_IN_SET(?, ??)`,
[
table.table_name,
column.column_name,
column.column_name,
option.title,
newOp.title,
option.title,
column.column_name,
]
);
} else {
await dbDriver.raw(
`UPDATE ?? SET ?? = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', ??, ','), CONCAT(',', ?, ','), CONCAT(',', ?, ',')))`,
[
table.table_name,
column.column_name,
column.column_name,
option.title,
newOp.title,
]
);
}
} else if (driverType === 'pg') {
await dbDriver.raw(
`UPDATE ?? SET ?? = array_to_string(array_replace(string_to_array(??, ','), ?, ?), ',')`,
@ -1174,18 +1212,33 @@ export async function columnUpdate(req: Request, res: Response<TableType>) {
}
} else if (column.uidt === UITypes.MultiSelect) {
if (driverType === 'mysql' || driverType === 'mysql2') {
await dbDriver.raw(
`UPDATE ?? SET ?? = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', ??, ','), CONCAT(',', ?, ','), CONCAT(',', ?, ','))) WHERE FIND_IN_SET(?, ??)`,
[
table.table_name,
column.column_name,
column.column_name,
ch.temp_title,
newOp.title,
ch.temp_title,
column.column_name,
]
);
if (colBody.dt === 'set') {
await dbDriver.raw(
`UPDATE ?? SET ?? = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', ??, ','), CONCAT(',', ?, ','), CONCAT(',', ?, ','))) WHERE FIND_IN_SET(?, ??)`,
[
table.table_name,
column.column_name,
column.column_name,
ch.temp_title,
newOp.title,
ch.temp_title,
column.column_name,
]
);
} else {
await dbDriver.raw(
`UPDATE ?? SET ?? = TRIM(BOTH ',' FROM REPLACE(CONCAT(',', ??, ','), CONCAT(',', ?, ','), CONCAT(',', ?, ',')))`,
[
table.table_name,
column.column_name,
column.column_name,
ch.temp_title,
newOp.title,
ch.temp_title,
column.column_name,
]
);
}
} else if (driverType === 'pg') {
await dbDriver.raw(
`UPDATE ?? SET ?? = array_to_string(array_replace(string_to_array(??, ','), ?, ?), ',')`,

16
packages/nocodb/src/lib/meta/api/sync/helpers/job.ts

@ -446,7 +446,7 @@ export default async (
// TODO fix record mapping (this causes every record to map first option, we can't handle them using data api as they don't provide option id within data we might instead get the correct mapping from schema file )
let dupNo = 1;
const defaultName = (value as any).name;
while (options.find((el) => el.title === (value as any).name)) {
while (options.find((el) => el.title.toLowerCase() === (value as any).name.toLowerCase())) {
(value as any).name = `${defaultName}_${dupNo++}`;
}
options.push({
@ -577,11 +577,15 @@ export default async (
ncCol.colOptions = {
options: [...colOptions.data],
};
// if options are empty, configure '' as default option
ncCol.dtxp =
colOptions.data
.map((el) => `'${el.title.replace(/'/gi, "''")}'`)
.join(',') || "''";
if (['mysql', 'mysql2'].includes(getRootDbType())) {
// if options are empty, configure '' as an option
ncCol.dtxp =
colOptions.data
.map((el) => `'${el.title.replace(/'/gi, "''")}'`)
.join(',') || "''";
}
break;
case undefined:
break;

Loading…
Cancel
Save