mirror of
https://github.com/n8n-io/n8n.git
synced 2026-05-12 16:10:30 +02:00
fix(core): Rename data table columns during source control pull (#27746)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4436e4b71c
commit
d9f8f04772
|
|
@ -2980,6 +2980,48 @@ describe('SourceControlImportService', () => {
|
|||
);
|
||||
});
|
||||
|
||||
it('should rename columns when name changes but ID stays the same', async () => {
|
||||
// Arrange
|
||||
const mockDataTable = {
|
||||
id: 'dt1',
|
||||
name: 'Test Table',
|
||||
ownedBy: {
|
||||
type: 'team',
|
||||
teamId: 'project1',
|
||||
teamName: 'Team Project 1',
|
||||
},
|
||||
columns: [{ id: 'col1', name: 'newColumnName', type: 'string', index: 0 }],
|
||||
createdAt: '2024-01-01T00:00:00.000Z',
|
||||
updatedAt: '2024-01-02T00:00:00.000Z',
|
||||
};
|
||||
|
||||
const existingTable = {
|
||||
id: 'dt1',
|
||||
name: 'Test Table',
|
||||
projectId: 'project1',
|
||||
columns: [{ id: 'col1', name: 'oldColumnName' }],
|
||||
};
|
||||
|
||||
fsReadFile.mockResolvedValue(JSON.stringify(mockDataTable) as any);
|
||||
dataTableRepository.findOne.mockResolvedValue(existingTable as any);
|
||||
dataTableColumnRepository.find.mockResolvedValue([
|
||||
{ id: 'col1', name: 'oldColumnName' },
|
||||
] as any);
|
||||
projectRepository.findOne.mockResolvedValue({ id: 'project1', type: 'team' } as any);
|
||||
|
||||
// Act
|
||||
await service.importDataTablesFromWorkFolder([mockCandidate], mockUser.id);
|
||||
|
||||
// Assert
|
||||
expect(dataTableDDLService.renameColumn).toHaveBeenCalledWith(
|
||||
'dt1',
|
||||
'oldColumnName',
|
||||
'newColumnName',
|
||||
'sqlite',
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
|
||||
it('should delete removed columns', async () => {
|
||||
// Arrange
|
||||
const mockDataTable = {
|
||||
|
|
|
|||
|
|
@ -1422,6 +1422,20 @@ export class SourceControlImportService {
|
|||
});
|
||||
columnEntities.push(columnEntity);
|
||||
|
||||
// Rename columns whose name changed (same ID, different name)
|
||||
if (!isNewTable && existingColumnIds.has(column.id)) {
|
||||
const oldName = existingColumnNameMap.get(column.id);
|
||||
if (oldName && oldName !== column.name) {
|
||||
await this.dataTableDDLService.renameColumn(
|
||||
dataTable.id,
|
||||
oldName,
|
||||
column.name,
|
||||
dbType,
|
||||
trx,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Add new columns to existing physical table
|
||||
if (!isNewTable && !existingColumnIds.has(column.id)) {
|
||||
await this.dataTableDDLService.addColumn(dataTable.id, columnEntity, dbType, trx);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user