Skip to content

Commit

Permalink
discard serial values in csv
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaysasidrn committed Apr 30, 2024
1 parent a6e5dd2 commit b22cc1f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server/src/services/tooljet_db_bulk_upload.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export class TooljetDbBulkUploadService {
.filter((colDetails) => colDetails.keytype === 'PRIMARY KEY')
.map((colDetails) => colDetails.column_name);

const serialTypeColumns = internalTableColumnSchema
.filter((colDetails) => colDetails.data_type === 'integer' && /^nextval\(/.test(colDetails.column_default))
.map((colDetails) => colDetails.column_name);

const allValueSets = [];
let allPlaceholders = [];
let parameterIndex = 1;
Expand All @@ -125,11 +129,9 @@ export class TooljetDbBulkUploadService {
const currentPlaceholders = [];

for (const col of Object.keys(row)) {
if (row[col] === null && primaryKeyColumns.includes(col)) {
// Use DEFAULT when the value is null and it's a primary key column
if (serialTypeColumns.includes(col) || (row[col] === null && primaryKeyColumns.includes(col))) {
valueSet.push('DEFAULT');
} else {
// Otherwise, use the placeholder and collect the value
valueSet.push(`$${parameterIndex++}`);
currentPlaceholders.push(row[col]);
}
Expand Down

0 comments on commit b22cc1f

Please sign in to comment.