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 }}"
# Build executables and publish to GitHub
# release-executables:
# needs: [set-tag, release-npm]
# uses: ./.github/workflows/release-timely-executables.yml
# with:
# tag: ${{ needs.set-tag.outputs.current_version }}-${{ needs.set-tag.outputs.nightly_build_tag }}
# secrets:
# NC_GITHUB_TOKEN: "${{ secrets.NC_GITHUB_TOKEN }}"
release-executables:
needs: [set-tag, release-npm]
uses: ./.github/workflows/release-timely-executables.yml
with:
tag: ${{ needs.set-tag.outputs.current_version }}-${{ needs.set-tag.outputs.nightly_build_tag }}
secrets:
NC_GITHUB_TOKEN: "${{ secrets.NC_GITHUB_TOKEN }}"
# Build docker image and push to docker hub
release-docker:

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

@ -257,6 +257,8 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
})
const cellObj = ws[cellId]
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 {
// TODO: do parsing if necessary based on type
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) => {
return isURL(str)
return isURL(`${str}`)
}
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) {
switch (type) {
case 'bigint':
@ -306,7 +190,7 @@ export class MssqlUi {
return '';
case 'decimal':
return '';
return 10;
case 'float':
return '';
@ -394,8 +278,12 @@ export class MssqlUi {
static getDefaultLengthIsDisabled(type) {
switch (type) {
case 'nvarchar':
case 'numeric':
case 'decimal':
return false;
case 'tinyint':
case 'float':
case 'int':
case 'bigint':
case 'binary':
case 'bit':
@ -404,17 +292,13 @@ export class MssqlUi {
case 'datetime':
case 'datetime2':
case 'datetimeoffset':
case 'decimal':
case 'float':
case 'geography':
case 'geometry':
case 'heirarchyid':
case 'image':
case 'int':
case 'money':
case 'nchar':
case 'ntext':
case 'numeric':
case 'real':
case 'json':
case 'smalldatetime':
@ -425,7 +309,6 @@ export class MssqlUi {
case 'text':
case 'time':
case 'timestamp':
case 'tinyint':
case 'uniqueidentifier':
case 'varbinary':
case 'xml':
@ -578,7 +461,7 @@ export class MssqlUi {
return '';
case 'decimal':
return '';
return '2';
case 'float':
return '';
@ -608,7 +491,7 @@ export class MssqlUi {
return '';
case 'numeric':
return '';
return '2';
case 'nvarchar':
return '';
@ -714,8 +597,8 @@ export class MssqlUi {
// }
}
static showScale(_columnObj) {
return false;
static showScale(columnObj) {
return columnObj.dt === 'decimal' || columnObj.dt === 'numeric';
}
static removeUnsigned(columns) {
@ -1261,6 +1144,7 @@ export class MssqlUi {
'real',
'smallint',
'tinyint',
'money',
];
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 shouldSanitize = true;
const scaleAndPrecision =
!getDefaultLengthIsDisabled(n.dt) && n.dtxp
? `(${n.dtxp}${n.dtxs ? `,${n.dtxs}` : ''})`
: '';
if (change === 0) {
query = existingQuery ? ',' : '';
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.ai ? ' IDENTITY(1,1)' : ' ';
query += defaultValue
@ -2599,7 +2603,7 @@ class MssqlClient extends KnexClient {
}
} else if (change === 1) {
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.ai ? ' IDENTITY(1,1)' : ' ';
query += defaultValue
@ -2629,43 +2633,17 @@ class MssqlClient extends KnexClient {
);
}
if (n.dtxp !== o.dtxp && !['text'].includes(n.dt)) {
query += this.genQuery(
`\nALTER TABLE ?? ALTER COLUMN ?? ${n.dt}(${n.dtxp});\n`,
[this.getTnPath(t), n.cn],
shouldSanitize
);
} 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) {
if (
n.dtxp !== o.dtxp ||
n.dtxs !== o.dtxs ||
n.dt !== o.dt ||
n.rqd !== o.rqd
) {
query += this.genQuery(
`\nALTER TABLE ?? ALTER COLUMN ?? ${n.dt}`,
`\nALTER TABLE ?? ALTER COLUMN ?? ${n.dt}${scaleAndPrecision}`,
[this.getTnPath(t), n.cn],
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`;
}
@ -2787,43 +2765,32 @@ function getDefaultValue(n) {
function getDefaultLengthIsDisabled(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 'decimal':
case 'float':
case 'geography':
case 'geometry':
case 'heirarchyid':
case 'image':
case 'int':
case 'money':
case 'numeric':
case 'real':
case 'json':
case 'smalldatetime':
case 'smallint':
case 'smallmoney':
case 'text':
case 'time':
case 'timestamp':
case 'int':
case 'tinyint':
case 'bigint':
case 'bit':
case 'smallint':
case 'float':
case 'uniqueidentifier':
case 'xml':
return true;
break;
default:
case 'decimal':
case 'numeric':
case 'varchar':
return false;
break;

Loading…
Cancel
Save