Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws-redshift): Columns are not dropped on removal from array #23011

Merged
merged 26 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
26ac072
Initial build, fullfilling prebuild requirements
Rizxcviii Nov 18, 2022
85bb3df
addition, deletion
Rizxcviii Nov 18, 2022
58b24a2
addition, deletion
Rizxcviii Nov 18, 2022
11b9b63
Merge pull request #1 from Rizxcviii/feature/delete-columns
Rizxcviii Nov 18, 2022
773b403
Merge branch 'main' into main
Rizxcviii Nov 18, 2022
37a4c65
yarn build successful
Rizxcviii Nov 18, 2022
e7b4899
Merge pull request #2 from Rizxcviii/bugfix/post-pr-changes
Rizxcviii Nov 18, 2022
a2d67ce
Generating integration test
Rizxcviii Nov 18, 2022
f643ae6
Merge branch 'main' into main
Rizxcviii Nov 18, 2022
ec1ab9c
Merge branch 'aws:main' into main
Rizxcviii Nov 21, 2022
f8f893f
Merge branch 'main' into main
Rizxcviii Nov 21, 2022
8b85042
integ test
Rizxcviii Nov 21, 2022
40e88cc
removing diffAssets for build
Rizxcviii Nov 21, 2022
8bf1b7a
Merge branch 'main' into main
Rizxcviii Nov 21, 2022
527c2e3
Adding comment for better awareness of current risk
Rizxcviii Nov 21, 2022
e3e11fa
Merge branch 'main' into main
Rizxcviii Nov 21, 2022
3647bfa
Merge branch 'main' into main
Rizxcviii Nov 27, 2022
933741c
Merge branch 'main' into main
Rizxcviii Nov 28, 2022
c457d53
buildup and yarn install
Rizxcviii Nov 28, 2022
3a13216
updating third party liscences
Rizxcviii Nov 28, 2022
42ec51b
Merge branch 'main' into main
Rizxcviii Dec 12, 2022
0c43cc0
reverting prettier
Rizxcviii Dec 12, 2022
af962b9
reverting prettier
Rizxcviii Dec 12, 2022
958c9f0
modification: rearranging tests, changing commented text
Rizxcviii Dec 16, 2022
4430234
addition: previous table column added back in
Rizxcviii Dec 21, 2022
6c50104
Merge branch 'main' into main
mergify[bot] Dec 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ async function updateTable(
}

const oldTableColumns = oldResourceProperties.tableColumns;
if (!oldTableColumns.every(oldColumn => tableColumns.some(column => column.name === oldColumn.name && column.dataType === oldColumn.dataType))) {
return createTable(tableNamePrefix, tableNameSuffix, tableColumns, tableAndClusterProps);
const columnDeletions = oldTableColumns.filter(oldColumn => (
tableColumns.every(column => oldColumn.name !== column.name)
comcalvi marked this conversation as resolved.
Show resolved Hide resolved
));
if (columnDeletions.length > 0) {
alterationStatements.push(...columnDeletions.map(column => `ALTER TABLE ${tableName} DROP COLUMN ${column.name}`));
}

const columnAdditions = tableColumns.filter(column => {
Expand Down
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-redshift/lib/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export enum TableAction {
*/
export interface Column {
/**
* The name of the column.
* The unique name/identifier of the column.
*
* **NOTE**. After deploying this column, you cannot change its name. Doing so will cause the column to be dropped and recreated.
*/
readonly name: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,17 @@ describe('update', () => {
}));
});

test('replaces if table columns change', async () => {
Rizxcviii marked this conversation as resolved.
Show resolved Hide resolved
const newTableColumnName = 'col2';
const newTableColumnDataType = 'varchar(1)';
const newTableColumns = [{ name: newTableColumnName, dataType: newTableColumnDataType }];
test('does not replace if table columns removed', async () => {
const newResourceProperties = {
...resourceProperties,
tableColumns: newTableColumns,
tableColumns: [],
};

await expect(manageTable(newResourceProperties, event)).resolves.not.toMatchObject({
await expect(manageTable(newResourceProperties, event)).resolves.toMatchObject({
PhysicalResourceId: physicalResourceId,
});
expect(mockExecuteStatement).toHaveBeenCalledWith(expect.objectContaining({
Sql: `CREATE TABLE ${tableNamePrefix}${requestIdTruncated} (${newTableColumnName} ${newTableColumnDataType})`,
Sql: `ALTER TABLE ${physicalResourceId} DROP COLUMN col1`,
}));
});

Expand Down

This file was deleted.

This file was deleted.

Loading