diff --git a/packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts b/packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts index 2d17336b59..912e6770bc 100644 --- a/packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts +++ b/packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts @@ -779,11 +779,7 @@ class KnexClient extends SqlClient { let max1 = 10000; let searchFrom = 0; - let foundIndex = findIndex( - tableObj.columns, - { ck: 'UNI' }, - searchFrom - ); + let foundIndex = findIndex(tableObj.columns, { ck: 'UNI' }, searchFrom); while (foundIndex !== -1) { const col = tableObj.columns[foundIndex]; @@ -799,11 +795,7 @@ class KnexClient extends SqlClient { } searchFrom = foundIndex; - foundIndex = findIndex( - tableObj.columns, - { ck: 'UNI' }, - searchFrom + 1 - ); + foundIndex = findIndex(tableObj.columns, { ck: 'UNI' }, searchFrom + 1); } let max2 = 10000; @@ -824,11 +816,7 @@ class KnexClient extends SqlClient { } searchFrom = foundIndex; - foundIndex = findIndex( - tableObj.columns, - { ck: 'MUL' }, - searchFrom + 1 - ); + foundIndex = findIndex(tableObj.columns, { ck: 'MUL' }, searchFrom + 1); } // console.log('min of: ', max, max1, max2, maxy); diff --git a/packages/nocodb/src/lib/db/sql-client/lib/mysql/MysqlClient.ts b/packages/nocodb/src/lib/db/sql-client/lib/mysql/MysqlClient.ts index bb5c56e338..6c8501c302 100644 --- a/packages/nocodb/src/lib/db/sql-client/lib/mysql/MysqlClient.ts +++ b/packages/nocodb/src/lib/db/sql-client/lib/mysql/MysqlClient.ts @@ -622,9 +622,7 @@ class MysqlClient extends KnexClient { for (let i = 0; i < response[0].length; ++i) { const column: any = {}; - response[0][i] = mapKeys(response[0][i], (_v, k) => - k.toLowerCase() - ); + response[0][i] = mapKeys(response[0][i], (_v, k) => k.toLowerCase()); if (this._version.key === '57' || this._version.key === '80') { column.dp = response[0][i].dp; diff --git a/packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts b/packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts index 2e77a44df0..115e5e7d03 100644 --- a/packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts +++ b/packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts @@ -1548,7 +1548,11 @@ class SqliteClient extends KnexClient { } } - const pkQuery = this.alterTablePK(args.columns, args.originalColumns, upQuery); + const pkQuery = this.alterTablePK( + args.columns, + args.originalColumns, + upQuery + ); await this.sqlClient.raw('PRAGMA foreign_keys = OFF;'); await this.sqlClient.raw('PRAGMA legacy_alter_table = ON;'); @@ -1565,14 +1569,16 @@ class SqliteClient extends KnexClient { if (pkQuery) { await trx.schema.alterTable(args.table, (table) => { - for (const pk of pkQuery.oldPks.filter((el) => !pkQuery.newPks.includes(el))) { + for (const pk of pkQuery.oldPks.filter( + (el) => !pkQuery.newPks.includes(el) + )) { table.dropPrimary(pk); } - + for (const pk of pkQuery.dropPks) { table.dropColumn(pk); } - + if (pkQuery.newPks.length) { table.primary(pkQuery.newPks); } @@ -1947,7 +1953,7 @@ class SqliteClient extends KnexClient { newPks, oldPks, dropPks, - } + }; } else { return false; } @@ -2003,34 +2009,50 @@ class SqliteClient extends KnexClient { [t, o.cn, `${o.cno}_nc_${suffix}`], shouldSanitize ); - - let addNewColumnQuery = '' - addNewColumnQuery += this.genQuery(` ADD ?? ${n.dt}`, [n.cn], shouldSanitize); + + let addNewColumnQuery = ''; + addNewColumnQuery += this.genQuery( + ` ADD ?? ${n.dt}`, + [n.cn], + shouldSanitize + ); addNewColumnQuery += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : ''; - addNewColumnQuery += n.cdf ? ` DEFAULT ${n.cdf}` : !n.rqd ? ' ' : ` DEFAULT ''`; + addNewColumnQuery += n.cdf + ? ` DEFAULT ${n.cdf}` + : !n.rqd + ? ' ' + : ` DEFAULT ''`; addNewColumnQuery += n.rqd ? ` NOT NULL` : ' '; - addNewColumnQuery = this.genQuery(`ALTER TABLE ?? ${addNewColumnQuery};`, [t], shouldSanitize); + addNewColumnQuery = this.genQuery( + `ALTER TABLE ?? ${addNewColumnQuery};`, + [t], + shouldSanitize + ); - let updateNewColumnQuery = this.genQuery(`UPDATE ?? SET ?? = ??;`, [t, n.cn, `${o.cno}_nc_${suffix}`], shouldSanitize); + let updateNewColumnQuery = this.genQuery( + `UPDATE ?? SET ?? = ??;`, + [t, n.cn, `${o.cno}_nc_${suffix}`], + shouldSanitize + ); - let dropOldColumnQuery = this.genQuery(`ALTER TABLE ?? DROP COLUMN ??;`, [t, `${o.cno}_nc_${suffix}`], shouldSanitize); + let dropOldColumnQuery = this.genQuery( + `ALTER TABLE ?? DROP COLUMN ??;`, + [t, `${o.cno}_nc_${suffix}`], + shouldSanitize + ); query = `${backupOldColumnQuery}${addNewColumnQuery}${updateNewColumnQuery}${dropOldColumnQuery}`; } else if (change === 0) { query = existingQuery ? ',' : ''; query += this.genQuery(`?? ${n.dt}`, [n.cn], shouldSanitize); query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : ''; - query += n.cdf - ? ` DEFAULT ${n.cdf}` - : ' '; + query += n.cdf ? ` DEFAULT ${n.cdf}` : ' '; query += n.rqd ? ` NOT NULL` : ' '; } else if (change === 1) { shouldSanitize = true; query += this.genQuery(` ADD ?? ${n.dt}`, [n.cn], shouldSanitize); query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : ''; - query += n.cdf - ? ` DEFAULT ${n.cdf}` - : !n.rqd ? ' ' : ` DEFAULT ''`; + query += n.cdf ? ` DEFAULT ${n.cdf}` : !n.rqd ? ' ' : ` DEFAULT ''`; query += n.rqd ? ` NOT NULL` : ' '; query = this.genQuery(`ALTER TABLE ?? ${query};`, [t], shouldSanitize); } else { diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/mysql.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/mysql.ts index 1419ca36e9..ab1acb763b 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/mysql.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/mysql.ts @@ -36,7 +36,11 @@ const mysql2 = { MID: 'SUBSTR', FLOAT: (args: MapFnArgs) => { return args.knex - .raw(`CAST(CAST(${args.fn(args.pt.arguments[0])} as CHAR) AS DOUBLE)${args.colAlias}`) + .raw( + `CAST(CAST(${args.fn(args.pt.arguments[0])} as CHAR) AS DOUBLE)${ + args.colAlias + }` + ) .wrap('(', ')'); }, DATEADD: ({ fn, knex, pt, colAlias }: MapFnArgs) => { diff --git a/packages/nocodb/src/lib/meta/api/index.ts b/packages/nocodb/src/lib/meta/api/index.ts index 28ee746356..39085584db 100644 --- a/packages/nocodb/src/lib/meta/api/index.ts +++ b/packages/nocodb/src/lib/meta/api/index.ts @@ -141,11 +141,11 @@ export default function (router: Router, server) { }); socket.on('subscribe', (room) => { if (room in jobs) { - socket.join(room) - socket.emit('job') - socket.emit('progress', jobs[room].last_message) + socket.join(room); + socket.emit('job'); + socket.emit('progress', jobs[room].last_message); } - }) + }); }); importApis(router, io, jobs); diff --git a/packages/nocodb/src/lib/meta/api/sync/importApis.ts b/packages/nocodb/src/lib/meta/api/sync/importApis.ts index fd73736fa4..e1a56cf3a1 100644 --- a/packages/nocodb/src/lib/meta/api/sync/importApis.ts +++ b/packages/nocodb/src/lib/meta/api/sync/importApis.ts @@ -17,7 +17,11 @@ enum SyncStatus { FAILED = 'FAILED', } -export default (router: Router, sv: Server, jobs: { [id: string]: { last_message: any } }) => { +export default ( + router: Router, + sv: Server, + jobs: { [id: string]: { last_message: any } } +) => { // add importer job handler and progress notification job handler NocoJobs.jobsMgr.addJobWorker(AIRTABLE_IMPORT_JOB, job); NocoJobs.jobsMgr.addJobWorker( @@ -112,8 +116,8 @@ export default (router: Router, sv: Server, jobs: { [id: string]: { last_message }); jobs[req.params.syncId] = { last_message: { - msg: 'Sync started' - } + msg: 'Sync started', + }, }; res.json({}); }) diff --git a/packages/nocodb/src/lib/models/Column.ts b/packages/nocodb/src/lib/models/Column.ts index 76007e800a..ec1a872b9e 100644 --- a/packages/nocodb/src/lib/models/Column.ts +++ b/packages/nocodb/src/lib/models/Column.ts @@ -5,7 +5,12 @@ import RollupColumn from './RollupColumn'; import SelectOption from './SelectOption'; import Model from './Model'; import NocoCache from '../cache/NocoCache'; -import { ColumnReqType, AllowedColumnTypesForQrCode, ColumnType, UITypes } from 'nocodb-sdk'; +import { + ColumnReqType, + AllowedColumnTypesForQrCode, + ColumnType, + UITypes, +} from 'nocodb-sdk'; import { CacheDelDirection, CacheGetType, diff --git a/packages/nocodb/src/lib/v1-legacy/plugins/adapters/storage/Local.ts b/packages/nocodb/src/lib/v1-legacy/plugins/adapters/storage/Local.ts index 48b695b878..9796b00ae3 100644 --- a/packages/nocodb/src/lib/v1-legacy/plugins/adapters/storage/Local.ts +++ b/packages/nocodb/src/lib/v1-legacy/plugins/adapters/storage/Local.ts @@ -27,37 +27,43 @@ export default class Local implements IStorageAdapterV2 { async fileCreateByUrl(key: string, url: string): Promise { const destPath = path.join(NcConfigFactory.getToolDir(), ...key.split('/')); return new Promise((resolve, reject) => { - axios.get((url), { responseType: "stream", headers: { - "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", - "accept-language": "en-US,en;q=0.9", - "cache-control": "no-cache", - "pragma": "no-cache", - "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36", - "origin": "https://www.airtable.com/", - } }) - .then(response => { - mkdirp.sync(path.dirname(destPath)); - const file = fs.createWriteStream(destPath); - // close() is async, call cb after close completes - file.on('finish', () => { - file.close((err) => { - if (err) { - return reject(err); - } - resolve(null); + axios + .get(url, { + responseType: 'stream', + headers: { + accept: + 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', + 'accept-language': 'en-US,en;q=0.9', + 'cache-control': 'no-cache', + pragma: 'no-cache', + 'user-agent': + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36', + origin: 'https://www.airtable.com/', + }, + }) + .then((response) => { + mkdirp.sync(path.dirname(destPath)); + const file = fs.createWriteStream(destPath); + // close() is async, call cb after close completes + file.on('finish', () => { + file.close((err) => { + if (err) { + return reject(err); + } + resolve(null); + }); }); - }); - file.on('error', (err) => { - // Handle errors - fs.unlink(destPath, () => reject(err.message)); // delete the (partial) file and then return the error - }); + file.on('error', (err) => { + // Handle errors + fs.unlink(destPath, () => reject(err.message)); // delete the (partial) file and then return the error + }); - response.data.pipe(file); - }) - .catch((err) => { - reject(err.message) - }); + response.data.pipe(file); + }) + .catch((err) => { + reject(err.message); + }); }); }