mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
fix(core): Remove explicit column ordering in Data Table inserts (no-changelog) (#19031)
This commit is contained in:
@@ -1003,6 +1003,62 @@ describe('dataStore', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('inserts in correct order even with different column order', async () => {
|
||||||
|
// ARRANGE
|
||||||
|
const { id: dataStoreId } = await dataStoreService.createDataStore(project1.id, {
|
||||||
|
name: 'myDataStore',
|
||||||
|
columns: [
|
||||||
|
{ name: 'c4', type: 'date' },
|
||||||
|
{ name: 'c3', type: 'boolean' },
|
||||||
|
{ name: 'c2', type: 'string' },
|
||||||
|
{ name: 'c1', type: 'number' },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
// Insert initial row
|
||||||
|
const ids = await dataStoreService.insertRows(
|
||||||
|
dataStoreId,
|
||||||
|
project1.id,
|
||||||
|
[
|
||||||
|
{ c1: 1, c2: 'foo', c3: true, c4: now },
|
||||||
|
{ c2: 'bar', c1: 2, c3: false, c4: now },
|
||||||
|
{ c1: null, c2: null, c3: null, c4: null },
|
||||||
|
],
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
expect(ids).toEqual([
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
c1: 1,
|
||||||
|
c2: 'foo',
|
||||||
|
c3: true,
|
||||||
|
c4: now,
|
||||||
|
createdAt: expect.any(Date),
|
||||||
|
updatedAt: expect.any(Date),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
c1: 2,
|
||||||
|
c2: 'bar',
|
||||||
|
c3: false,
|
||||||
|
c4: now,
|
||||||
|
createdAt: expect.any(Date),
|
||||||
|
updatedAt: expect.any(Date),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
c1: null,
|
||||||
|
c2: null,
|
||||||
|
c3: null,
|
||||||
|
c4: null,
|
||||||
|
createdAt: expect.any(Date),
|
||||||
|
updatedAt: expect.any(Date),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it('rejects a mismatched row with unknown column', async () => {
|
it('rejects a mismatched row with unknown column', async () => {
|
||||||
// ARRANGE
|
// ARRANGE
|
||||||
const { id: dataStoreId } = await dataStoreService.createDataStore(project1.id, {
|
const { id: dataStoreId } = await dataStoreService.createDataStore(project1.id, {
|
||||||
|
|||||||
@@ -160,7 +160,6 @@ export class DataStoreRowsRepository {
|
|||||||
const useReturning = dbType === 'postgres' || dbType === 'mariadb';
|
const useReturning = dbType === 'postgres' || dbType === 'mariadb';
|
||||||
|
|
||||||
const table = this.toTableName(dataStoreId);
|
const table = this.toTableName(dataStoreId);
|
||||||
const columnNames = columns.map((c) => c.name);
|
|
||||||
const escapedColumns = columns.map((c) => this.dataSource.driver.escape(c.name));
|
const escapedColumns = columns.map((c) => this.dataSource.driver.escape(c.name));
|
||||||
const escapedSystemColumns = DATA_TABLE_SYSTEM_COLUMNS.map((x) =>
|
const escapedSystemColumns = DATA_TABLE_SYSTEM_COLUMNS.map((x) =>
|
||||||
this.dataSource.driver.escape(x),
|
this.dataSource.driver.escape(x),
|
||||||
@@ -181,11 +180,7 @@ export class DataStoreRowsRepository {
|
|||||||
completeRow[column.name] = normalizeValue(completeRow[column.name], column.type, dbType);
|
completeRow[column.name] = normalizeValue(completeRow[column.name], column.type, dbType);
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = this.dataSource
|
const query = this.dataSource.createQueryBuilder().insert().into(table).values(completeRow);
|
||||||
.createQueryBuilder()
|
|
||||||
.insert()
|
|
||||||
.into(table, columnNames)
|
|
||||||
.values(completeRow);
|
|
||||||
|
|
||||||
if (useReturning) {
|
if (useReturning) {
|
||||||
query.returning(returnData ? selectColumns.join(',') : 'id');
|
query.returning(returnData ? selectColumns.join(',') : 'id');
|
||||||
|
|||||||
Reference in New Issue
Block a user