Browse Source

Merge pull request #6873 from nocodb/nc-fix/pg-ai

fix: this record exist issue for pg duplicate
pull/6877/head
Raju Udava 1 year ago committed by GitHub
parent
commit
3c46249a1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      packages/nocodb/src/modules/jobs/jobs/export-import/export.service.ts
  2. 13
      packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts

11
packages/nocodb/src/modules/jobs/jobs/export-import/export.service.ts

@ -78,15 +78,20 @@ export class ExportService {
if (source.type === 'pg') { if (source.type === 'pg') {
if (column.ai) { if (column.ai) {
try { try {
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: null,
dbDriver: await NcConnectionMgrv2.get(source),
});
const sqlClient = await NcConnectionMgrv2.getSqlClient(source); const sqlClient = await NcConnectionMgrv2.getSqlClient(source);
const seq = await sqlClient.knex.raw( const seq = await sqlClient.raw(
`SELECT pg_get_serial_sequence('??', ?) as seq;`, `SELECT pg_get_serial_sequence('??', ?) as seq;`,
[model.table_name, column.column_name], [baseModel.getTnPath(model.table_name), column.column_name],
); );
if (seq.rows.length > 0) { if (seq.rows.length > 0) {
const seqName = seq.rows[0].seq; const seqName = seq.rows[0].seq;
const res = await sqlClient.knex.raw( const res = await sqlClient.raw(
`SELECT last_value as last FROM ${seqName};`, `SELECT last_value as last FROM ${seqName};`,
); );

13
packages/nocodb/src/modules/jobs/jobs/export-import/import.service.ts

@ -158,10 +158,19 @@ export class ImportService {
if (source.type === 'pg') { if (source.type === 'pg') {
if (modelData.pgSerialLastVal) { if (modelData.pgSerialLastVal) {
if (col.ai) { if (col.ai) {
const baseModel = await Model.getBaseModelSQL({
id: table.id,
viewId: null,
dbDriver: await NcConnectionMgrv2.get(source),
});
const sqlClient = await NcConnectionMgrv2.getSqlClient(source); const sqlClient = await NcConnectionMgrv2.getSqlClient(source);
await sqlClient.knex.raw( await sqlClient.raw(
`SELECT setval(pg_get_serial_sequence('??', ?), ?);`, `SELECT setval(pg_get_serial_sequence('??', ?), ?);`,
[table.table_name, col.column_name, modelData.pgSerialLastVal], [
baseModel.getTnPath(table.table_name),
col.column_name,
modelData.pgSerialLastVal,
],
); );
} }
} }

Loading…
Cancel
Save