Browse Source

Merge pull request #4883 from nocodb/fix/mssql

fix: SQL server column alter and create bugs
pull/4922/head
Pranav C 2 years ago committed by GitHub
parent
commit
12f8993ea6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      .github/workflows/release-nightly-dev.yml
  2. 2
      packages/nc-gui/utils/parsers/ExcelTemplateAdapter.ts
  3. 2
      packages/nc-gui/utils/urlUtils.ts
  4. 138
      packages/nocodb-sdk/src/lib/sqlUi/MssqlUi.ts
  5. 73
      packages/nocodb/src/lib/db/sql-client/lib/mssql/MssqlClient.ts

14
.github/workflows/release-nightly-dev.yml

@ -54,13 +54,13 @@ jobs:
NPM_TOKEN: "${{ secrets.NPM_TOKEN }}" NPM_TOKEN: "${{ secrets.NPM_TOKEN }}"
# Build executables and publish to GitHub # Build executables and publish to GitHub
# release-executables: release-executables:
# needs: [set-tag, release-npm] needs: [set-tag, release-npm]
# uses: ./.github/workflows/release-timely-executables.yml uses: ./.github/workflows/release-timely-executables.yml
# with: with:
# tag: ${{ needs.set-tag.outputs.current_version }}-${{ needs.set-tag.outputs.nightly_build_tag }} tag: ${{ needs.set-tag.outputs.current_version }}-${{ needs.set-tag.outputs.nightly_build_tag }}
# secrets: secrets:
# NC_GITHUB_TOKEN: "${{ secrets.NC_GITHUB_TOKEN }}" NC_GITHUB_TOKEN: "${{ secrets.NC_GITHUB_TOKEN }}"
# Build docker image and push to docker hub # Build docker image and push to docker hub
release-docker: release-docker:

2
packages/nc-gui/utils/parsers/ExcelTemplateAdapter.ts

@ -257,6 +257,8 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
}) })
const cellObj = ws[cellId] const cellObj = ws[cellId]
rowData[table.columns[i].column_name] = (cellObj && cellObj.w) || row[i] rowData[table.columns[i].column_name] = (cellObj && cellObj.w) || row[i]
} else if (table.columns[i].uidt === UITypes.SingleLineText || table.columns[i].uidt === UITypes.LongText) {
rowData[table.columns[i].column_name] = row[i] === null || row[i] === undefined ? null : `${row[i]}`
} else { } else {
// TODO: do parsing if necessary based on type // TODO: do parsing if necessary based on type
rowData[table.columns[i].column_name] = row[i] rowData[table.columns[i].column_name] = row[i]

2
packages/nc-gui/utils/urlUtils.ts

@ -20,7 +20,7 @@ export const replaceUrlsWithLink = (text: string): boolean | string => {
} }
export const isValidURL = (str: string) => { export const isValidURL = (str: string) => {
return isURL(str) return isURL(`${str}`)
} }
export const openLink = (path: string, baseURL?: string, target = '_blank') => { export const openLink = (path: string, baseURL?: string, target = '_blank') => {

138
packages/nocodb-sdk/src/lib/sqlUi/MssqlUi.ts

@ -163,122 +163,6 @@ export class MssqlUi {
}; };
} }
// static getDefaultLengthForDatatype(type) {
// switch (type) {
// case "int":
// return 11;
// break;
// case "tinyint":
// return 1;
// break;
// case "smallint":
// return 5;
// break;
//
// case "mediumint":
// return 9;
// break;
// case "bigint":
// return 20;
// break;
// case "bit":
// return 64;
// break;
// case "boolean":
// return '';
// break;
// case "float":
// return 12;
// break;
// case "decimal":
// return 10;
// break;
// case "double":
// return 22;
// break;
// case "serial":
// return 20;
// break;
// case "date":
// return '';
// break;
// case "datetime":
// case "timestamp":
// return 6;
// break;
// case "time":
// return '';
// break;
// case "year":
// return '';
// break;
// case "char":
// return 255;
// break;
// case "varchar":
// return 45;
// break;
// case "nchar":
// return 255;
// break;
// case "text":
// return '';
// break;
// case "tinytext":
// return '';
// break;
// case "mediumtext":
// return '';
// break;
// case "longtext":
// return ''
// break;
// case "binary":
// return 255;
// break;
// case "varbinary":
// return 65500;
// break;
// case "blob":
// return '';
// break;
// case "tinyblob":
// return '';
// break;
// case "mediumblob":
// return '';
// break;
// case "longblob":
// return '';
// break;
// case "enum":
// return '\'a\',\'b\'';
// break;
// case "set":
// return '\'a\',\'b\'';
// break;
// case "geometry":
// return '';
// case "point":
// return '';
// case "linestring":
// return '';
// case "polygon":
// return '';
// case "multipoint":
// return '';
// case "multilinestring":
// return '';
// case "multipolygon":
// return '';
// case "json":
// return ''
// break;
//
// }
//
// }
static getDefaultLengthForDatatype(type) { static getDefaultLengthForDatatype(type) {
switch (type) { switch (type) {
case 'bigint': case 'bigint':
@ -306,7 +190,7 @@ export class MssqlUi {
return ''; return '';
case 'decimal': case 'decimal':
return ''; return 10;
case 'float': case 'float':
return ''; return '';
@ -394,8 +278,12 @@ export class MssqlUi {
static getDefaultLengthIsDisabled(type) { static getDefaultLengthIsDisabled(type) {
switch (type) { switch (type) {
case 'nvarchar': case 'nvarchar':
case 'numeric':
case 'decimal':
return false; return false;
case 'tinyint':
case 'float':
case 'int':
case 'bigint': case 'bigint':
case 'binary': case 'binary':
case 'bit': case 'bit':
@ -404,17 +292,13 @@ export class MssqlUi {
case 'datetime': case 'datetime':
case 'datetime2': case 'datetime2':
case 'datetimeoffset': case 'datetimeoffset':
case 'decimal':
case 'float':
case 'geography': case 'geography':
case 'geometry': case 'geometry':
case 'heirarchyid': case 'heirarchyid':
case 'image': case 'image':
case 'int':
case 'money': case 'money':
case 'nchar': case 'nchar':
case 'ntext': case 'ntext':
case 'numeric':
case 'real': case 'real':
case 'json': case 'json':
case 'smalldatetime': case 'smalldatetime':
@ -425,7 +309,6 @@ export class MssqlUi {
case 'text': case 'text':
case 'time': case 'time':
case 'timestamp': case 'timestamp':
case 'tinyint':
case 'uniqueidentifier': case 'uniqueidentifier':
case 'varbinary': case 'varbinary':
case 'xml': case 'xml':
@ -578,7 +461,7 @@ export class MssqlUi {
return ''; return '';
case 'decimal': case 'decimal':
return ''; return '2';
case 'float': case 'float':
return ''; return '';
@ -608,7 +491,7 @@ export class MssqlUi {
return ''; return '';
case 'numeric': case 'numeric':
return ''; return '2';
case 'nvarchar': case 'nvarchar':
return ''; return '';
@ -714,8 +597,8 @@ export class MssqlUi {
// } // }
} }
static showScale(_columnObj) { static showScale(columnObj) {
return false; return columnObj.dt === 'decimal' || columnObj.dt === 'numeric';
} }
static removeUnsigned(columns) { static removeUnsigned(columns) {
@ -1261,6 +1144,7 @@ export class MssqlUi {
'real', 'real',
'smallint', 'smallint',
'tinyint', 'tinyint',
'money',
]; ];
case 'Percent': case 'Percent':

73
packages/nocodb/src/lib/db/sql-client/lib/mssql/MssqlClient.ts

@ -2580,11 +2580,15 @@ class MssqlClient extends KnexClient {
const defaultValue = getDefaultValue(n); const defaultValue = getDefaultValue(n);
const shouldSanitize = true; const shouldSanitize = true;
const scaleAndPrecision =
!getDefaultLengthIsDisabled(n.dt) && n.dtxp
? `(${n.dtxp}${n.dtxs ? `,${n.dtxs}` : ''})`
: '';
if (change === 0) { if (change === 0) {
query = existingQuery ? ',' : ''; query = existingQuery ? ',' : '';
query += this.genQuery(`?? ${n.dt}`, [n.cn], shouldSanitize); query += this.genQuery(`?? ${n.dt}`, [n.cn], shouldSanitize);
query += !getDefaultLengthIsDisabled(n.dt) && n.dtxp ? `(${n.dtxp})` : ''; query += scaleAndPrecision;
query += n.rqd ? ' NOT NULL' : ' NULL'; query += n.rqd ? ' NOT NULL' : ' NULL';
query += n.ai ? ' IDENTITY(1,1)' : ' '; query += n.ai ? ' IDENTITY(1,1)' : ' ';
query += defaultValue query += defaultValue
@ -2599,7 +2603,7 @@ class MssqlClient extends KnexClient {
} }
} else if (change === 1) { } else if (change === 1) {
query += this.genQuery(` ADD ?? ${n.dt}`, [n.cn], shouldSanitize); query += this.genQuery(` ADD ?? ${n.dt}`, [n.cn], shouldSanitize);
query += !getDefaultLengthIsDisabled(n.dt) && n.dtxp ? `(${n.dtxp})` : ''; query += scaleAndPrecision;
query += n.rqd ? ' NOT NULL' : ' NULL'; query += n.rqd ? ' NOT NULL' : ' NULL';
query += n.ai ? ' IDENTITY(1,1)' : ' '; query += n.ai ? ' IDENTITY(1,1)' : ' ';
query += defaultValue query += defaultValue
@ -2629,43 +2633,17 @@ class MssqlClient extends KnexClient {
); );
} }
if (n.dtxp !== o.dtxp && !['text'].includes(n.dt)) { if (
query += this.genQuery( n.dtxp !== o.dtxp ||
`\nALTER TABLE ?? ALTER COLUMN ?? ${n.dt}(${n.dtxp});\n`, n.dtxs !== o.dtxs ||
[this.getTnPath(t), n.cn], n.dt !== o.dt ||
shouldSanitize n.rqd !== o.rqd
); ) {
} else if (n.dt !== o.dt) {
query += this.genQuery(
`\nALTER TABLE ?? ALTER COLUMN ?? TYPE ${n.dt};\n`,
[this.getTnPath(t), n.cn],
shouldSanitize
);
}
if (n.rqd !== o.rqd) {
query += this.genQuery( query += this.genQuery(
`\nALTER TABLE ?? ALTER COLUMN ?? ${n.dt}`, `\nALTER TABLE ?? ALTER COLUMN ?? ${n.dt}${scaleAndPrecision}`,
[this.getTnPath(t), n.cn], [this.getTnPath(t), n.cn],
shouldSanitize shouldSanitize
); );
if (
![
'int',
'bigint',
'bit',
'real',
'float',
'decimal',
'money',
'smallint',
'tinyint',
'geometry',
'datetime',
'text',
].includes(n.dt)
)
query += n.dtxp && n.dtxp != -1 ? `(${n.dtxp})` : '';
query += n.rqd ? ` NOT NULL;\n` : ` NULL;\n`; query += n.rqd ? ` NOT NULL;\n` : ` NULL;\n`;
} }
@ -2787,43 +2765,32 @@ function getDefaultValue(n) {
function getDefaultLengthIsDisabled(type) { function getDefaultLengthIsDisabled(type) {
switch (type) { switch (type) {
// case 'binary':
// case 'char':
// case 'sql_variant':
// case 'nvarchar':
// case 'nchar':
// case 'ntext':
// case 'varbinary':
// case 'sysname':
case 'bigint':
case 'bit':
case 'date':
case 'datetime':
case 'datetime2':
case 'datetimeoffset': case 'datetimeoffset':
case 'decimal':
case 'float':
case 'geography': case 'geography':
case 'geometry': case 'geometry':
case 'heirarchyid': case 'heirarchyid':
case 'image': case 'image':
case 'int':
case 'money': case 'money':
case 'numeric':
case 'real': case 'real':
case 'json': case 'json':
case 'smalldatetime': case 'smalldatetime':
case 'smallint':
case 'smallmoney': case 'smallmoney':
case 'text': case 'text':
case 'time': case 'time':
case 'timestamp': case 'timestamp':
case 'int':
case 'tinyint': case 'tinyint':
case 'bigint':
case 'bit':
case 'smallint':
case 'float':
case 'uniqueidentifier': case 'uniqueidentifier':
case 'xml': case 'xml':
return true; return true;
break; break;
default: default:
case 'decimal':
case 'numeric':
case 'varchar': case 'varchar':
return false; return false;
break; break;

Loading…
Cancel
Save