Browse Source

fix: pk handling for snowflake client

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/4645/head
mertmit 2 years ago
parent
commit
459377c5e1
  1. 2
      packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts
  2. 13
      packages/nocodb/src/lib/db/sql-client/lib/snowflake/SnowflakeClient.ts

2
packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts

@ -812,7 +812,7 @@ export class SnowflakeUi {
switch (col.uidt) { switch (col.uidt) {
case 'ID': case 'ID':
if (idType === 'AG') { if (idType === 'AG') {
return ['char', 'character', 'VARCHAR']; return ['VARCHAR'];
} else if (idType === 'AI') { } else if (idType === 'AI') {
return [ return [
'NUMBER' 'NUMBER'

13
packages/nocodb/src/lib/db/sql-client/lib/snowflake/SnowflakeClient.ts

@ -2364,13 +2364,18 @@ class SnowflakeClient extends KnexClient {
// do nothing // do nothing
} else if (pksChanged) { } else if (pksChanged) {
query += numOfPksInOriginal.length query += numOfPksInOriginal.length
? this.genQuery(`alter TABLE ?? drop constraint IF EXISTS ??;`, [this.getTnPath(t), `${t}_pkey`]) ? this.genQuery(`alter TABLE ?? drop constraint IF EXISTS ??;`, [
t,
`${t}_pkey`,
])
: ''; : '';
if (numOfPksInNew.length) { if (numOfPksInNew.length) {
if (!createTable) { if (createTable) {
query += this.genQuery(`, constraint ?? PRIMARY KEY (??)`, [`${t}_pkey`, numOfPksInNew]);
} else {
query += this.genQuery( query += this.genQuery(
`alter TABLE ?? add constraint ?? PRIMARY KEY(??);`, `alter TABLE ?? add constraint ?? PRIMARY KEY(??);`,
[this.getTnPath(t), `${t}_pkey`, numOfPksInNew] [t, `${t}_pkey`, numOfPksInNew]
); );
} }
} }
@ -2425,7 +2430,7 @@ class SnowflakeClient extends KnexClient {
if (change === 0) { if (change === 0) {
query = existingQuery ? ',' : ''; query = existingQuery ? ',' : '';
if (n.ai) { if (n.ai) {
query += this.genQuery(` ?? NUMBER(38,0) NOT NULL autoincrement PRIMARY KEY UNIQUE`, [n.cn], shouldSanitize); query += this.genQuery(` ?? NUMBER(38,0) NOT NULL autoincrement UNIQUE`, [n.cn], shouldSanitize);
} else { } else {
query += this.genQuery(` ?? ${n.dt}`, [n.cn], shouldSanitize); query += this.genQuery(` ?? ${n.dt}`, [n.cn], shouldSanitize);
query += n.rqd ? ' NOT NULL' : ' NULL'; query += n.rqd ? ' NOT NULL' : ' NULL';

Loading…
Cancel
Save