fix(core): Remove explicit column ordering in Data Table inserts (no-changelog) (#19031)

This commit is contained in:
Charlie Kolb
2025-09-01 12:03:17 +02:00
committed by GitHub
parent 056418307a
commit 56ead93265
2 changed files with 57 additions and 6 deletions

View File

@@ -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 () => {
// ARRANGE
const { id: dataStoreId } = await dataStoreService.createDataStore(project1.id, {

View File

@@ -160,7 +160,6 @@ export class DataStoreRowsRepository {
const useReturning = dbType === 'postgres' || dbType === 'mariadb';
const table = this.toTableName(dataStoreId);
const columnNames = columns.map((c) => c.name);
const escapedColumns = columns.map((c) => this.dataSource.driver.escape(c.name));
const escapedSystemColumns = DATA_TABLE_SYSTEM_COLUMNS.map((x) =>
this.dataSource.driver.escape(x),
@@ -181,11 +180,7 @@ export class DataStoreRowsRepository {
completeRow[column.name] = normalizeValue(completeRow[column.name], column.type, dbType);
}
const query = this.dataSource
.createQueryBuilder()
.insert()
.into(table, columnNames)
.values(completeRow);
const query = this.dataSource.createQueryBuilder().insert().into(table).values(completeRow);
if (useReturning) {
query.returning(returnData ? selectColumns.join(',') : 'id');