From d029c893264cae0f309a0396878625740599fd4b Mon Sep 17 00:00:00 2001 From: mertmit Date: Fri, 9 Dec 2022 03:50:56 +0300 Subject: [PATCH] feat: dtxp handling for snowflake client Signed-off-by: mertmit --- .../nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts | 35 ++++++------------- .../lib/snowflake/SnowflakeClient.ts | 5 ++- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts b/packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts index d43931de14..0a58f2fdd2 100644 --- a/packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts +++ b/packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts @@ -164,6 +164,11 @@ export class SnowflakeUi { static getDefaultLengthForDatatype(type): any { switch (type) { + case 'VARCHAR': + case 'CHAR': + case 'CHARACTER': + case 'STRING': + return 255; case 'NUMBER': case 'DECIMAL': case 'NUMERIC': @@ -179,31 +184,16 @@ export class SnowflakeUi { case 'DOUBLE': case 'DOUBLE PRECISION': case 'REAL': - case 'VARCHAR': - case 'CHAR': - case 'CHARACTER': - case 'STRING': - case 'TEXT': - case 'BINARY': - case 'VARBINARY': - case 'BOOLEAN': - case 'DATE': - case 'DATETIME': - case 'TIME': - case 'TIMESTAMP': - case 'TIMESTAMP_LTZ': - case 'TIMESTAMP_NTZ': - case 'TIMESTAMP_TZ': - case 'VARIANT': - case 'OBJECT': - case 'ARRAY': - case 'GEOGRAPHY': - return ''; + return 38; } } static getDefaultLengthIsDisabled(type): any { switch (type) { + case 'VARCHAR': + case 'CHAR': + case 'CHARACTER': + case 'STRING': case 'NUMBER': case 'DECIMAL': case 'NUMERIC': @@ -219,10 +209,7 @@ export class SnowflakeUi { case 'DOUBLE': case 'DOUBLE PRECISION': case 'REAL': - case 'VARCHAR': - case 'CHAR': - case 'CHARACTER': - case 'STRING': + return false; case 'TEXT': case 'BINARY': case 'VARBINARY': diff --git a/packages/nocodb/src/lib/db/sql-client/lib/snowflake/SnowflakeClient.ts b/packages/nocodb/src/lib/db/sql-client/lib/snowflake/SnowflakeClient.ts index ad8c19f7e6..8eae107d58 100644 --- a/packages/nocodb/src/lib/db/sql-client/lib/snowflake/SnowflakeClient.ts +++ b/packages/nocodb/src/lib/db/sql-client/lib/snowflake/SnowflakeClient.ts @@ -2433,11 +2433,13 @@ class SnowflakeClient extends KnexClient { query += this.genQuery(` ?? NUMBER(38,0) NOT NULL autoincrement UNIQUE`, [n.cn], shouldSanitize); } else { query += this.genQuery(` ?? ${n.dt}`, [n.cn], shouldSanitize); + query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : ''; query += n.rqd ? ' NOT NULL' : ' NULL'; query += defaultValue ? ` DEFAULT ${defaultValue}` : ''; } } else if (change === 1) { query += this.genQuery(` ADD ?? ${n.dt}`, [n.cn], shouldSanitize); + query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp})` : ''; query += n.rqd ? ' NOT NULL' : ' NULL'; query += defaultValue ? ` DEFAULT ${defaultValue}` : ''; query = this.genQuery(`ALTER TABLE ?? ${query};`, [this.getTnPath(t)], shouldSanitize); @@ -2452,10 +2454,11 @@ class SnowflakeClient extends KnexClient { if (n.dt !== o.dt) { query += this.genQuery( - `\nALTER TABLE ?? ALTER COLUMN ?? SET DATA TYPE ${n.dt};\n`, + `\nALTER TABLE ?? ALTER COLUMN ?? SET DATA TYPE ${n.dt}`, [this.getTnPath(t), n.cn], shouldSanitize ); + query += n.dtxp && n.dt !== 'text' ? `(${n.dtxp});\n` : ';\n'; } if (n.rqd !== o.rqd) {