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 would not be deleted upon removal from the array #22974

Closed
wants to merge 11 commits into from
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)
));
if (columnDeletions.length > 0) {
alterationStatements.push(...columnDeletions.map(column => `ALTER TABLE ${tableName} DROP COLUMN ${column.name}`));
}

const columnAdditions = tableColumns.filter(column => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,37 +225,34 @@ describe('update', () => {
}));
});

test('replaces if table columns change', async () => {
test('does not replace if table columns added', async () => {
const newTableColumnName = 'col2';
const newTableColumnDataType = 'varchar(1)';
const newTableColumns = [{ name: newTableColumnName, dataType: newTableColumnDataType }];
const newTableColumns = [{ name: 'col1', dataType: 'varchar(1)' }, { name: newTableColumnName, dataType: newTableColumnDataType }];
const newResourceProperties = {
...resourceProperties,
tableColumns: newTableColumns,
};

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} ADD ${newTableColumnName} ${newTableColumnDataType}`,
}));
});

test('does not replace if table columns added', async () => {
const newTableColumnName = 'col2';
const newTableColumnDataType = 'varchar(1)';
const newTableColumns = [{ name: 'col1', dataType: 'varchar(1)' }, { 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.toMatchObject({
PhysicalResourceId: physicalResourceId,
});
expect(mockExecuteStatement).toHaveBeenCalledWith(expect.objectContaining({
Sql: `ALTER TABLE ${physicalResourceId} ADD ${newTableColumnName} ${newTableColumnDataType}`,
Sql: `ALTER TABLE ${physicalResourceId} DROP COLUMN col1`,
}));
});

Expand Down
44 changes: 22 additions & 22 deletions packages/@aws-cdk/cfnspec/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"compilerOptions": {
"target":"ES2020",
"module": "commonjs",
"lib": ["es2016", "es2017.object", "es2017.string"],
"declaration": true,
"composite": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": false,
"inlineSourceMap": true,
"inlineSources": true,
"experimentalDecorators": true,
"strictPropertyInitialization":false
},
"include": ["**/*.ts" ],
"exclude": ["node_modules"]
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"lib": ["es2016", "es2017.object", "es2017.string", "ES2019.Object"],
"declaration": true,
"composite": true,
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": false,
"inlineSourceMap": true,
"inlineSources": true,
"experimentalDecorators": true,
"strictPropertyInitialization": false
},
"include": ["**/*.ts"],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/integ-runner/THIRD_PARTY_LICENSES
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH RE

----------------

** aws-sdk@2.1255.0 - https://www.npmjs.com/package/aws-sdk/v/2.1255.0 | Apache-2.0
** aws-sdk@2.1256.0 - https://www.npmjs.com/package/aws-sdk/v/2.1256.0 | Apache-2.0
AWS SDK for JavaScript
Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Expand Down
28 changes: 20 additions & 8 deletions packages/aws-cdk/THIRD_PARTY_LICENSES
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH RE

----------------

** aws-sdk@2.1255.0 - https://www.npmjs.com/package/aws-sdk/v/2.1255.0 | Apache-2.0
** aws-sdk@2.1256.0 - https://www.npmjs.com/package/aws-sdk/v/2.1256.0 | Apache-2.0
AWS SDK for JavaScript
Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Expand Down Expand Up @@ -901,16 +901,28 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

----------------

** decamelize@5.0.1 - https://www.npmjs.com/package/decamelize/v/5.0.1 | MIT
MIT License
** decamelize@1.2.0 - https://www.npmjs.com/package/decamelize/v/1.2.0 | MIT
The MIT License (MIT)

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


----------------
Expand Down Expand Up @@ -3604,11 +3616,11 @@ OTHER DEALINGS IN THE SOFTWARE.

----------------

** uuid@8.0.0 - https://www.npmjs.com/package/uuid/v/8.0.0 | MIT
** uuid@3.4.0 - https://www.npmjs.com/package/uuid/v/3.4.0 | MIT

----------------

** uuid@8.3.2 - https://www.npmjs.com/package/uuid/v/8.3.2 | MIT
** uuid@8.0.0 - https://www.npmjs.com/package/uuid/v/8.0.0 | MIT

----------------

Expand Down
Loading