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(redshift): tableNameSuffix evaluation #17213

Merged
merged 17 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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 @@ -6,7 +6,7 @@ import { ClusterProps, executeStatement } from './util';

export async function handler(props: TableHandlerProps & ClusterProps, event: AWSLambda.CloudFormationCustomResourceEvent) {
const tableNamePrefix = props.tableName.prefix;
const tableNameSuffix = props.tableName.generateSuffix ? `${event.RequestId.substring(0, 8)}` : '';
const tableNameSuffix = props.tableName.generateSuffix === 'true' ? `${event.RequestId.substring(0, 8)}` : '';
const tableColumns = props.tableColumns;
const clusterProps = props;

Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-redshift/lib/private/handler-props.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column } from '../table';
import { Column } from "../table";

export interface DatabaseQueryHandlerProps {
readonly handler: string;
Expand All @@ -15,7 +15,7 @@ export interface UserHandlerProps {
export interface TableHandlerProps {
readonly tableName: {
readonly prefix: string;
readonly generateSuffix: boolean;
readonly generateSuffix: string;
};
readonly tableColumns: Column[];
}
Expand Down
34 changes: 19 additions & 15 deletions packages/@aws-cdk/aws-redshift/lib/table.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as cdk from '@aws-cdk/core';
import { Construct } from 'constructs';
import { ICluster } from './cluster';
import { DatabaseOptions } from './database-options';
import { DatabaseQuery } from './private/database-query';
import { HandlerName } from './private/database-query-provider/handler-name';
import { TableHandlerProps } from './private/handler-props';
import { IUser } from './user';
import * as cdk from "@aws-cdk/core";
import { Construct } from "constructs";
import { ICluster } from "./cluster";
import { DatabaseOptions } from "./database-options";
import { DatabaseQuery } from "./private/database-query";
import { HandlerName } from "./private/database-query-provider/handler-name";
import { TableHandlerProps } from "./private/handler-props";
import { IUser } from "./user";

// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
// eslint-disable-next-line no-duplicate-imports, import/order
import { Construct as CoreConstruct } from '@aws-cdk/core';
import { Construct as CoreConstruct } from "@aws-cdk/core";

/**
* An action that a Redshift user can be granted privilege to perform on a table.
Expand Down Expand Up @@ -50,7 +50,7 @@ export enum TableAction {
/**
* Grants all available privileges at once to the specified user or user group.
*/
ALL
ALL,
}

/**
Expand Down Expand Up @@ -164,13 +164,17 @@ export class Table extends TableBase {
/**
* Specify a Redshift table using a table name and schema that already exists.
*/
static fromTableAttributes(scope: Construct, id: string, attrs: TableAttributes): ITable {
return new class extends TableBase {
static fromTableAttributes(
scope: Construct,
id: string,
attrs: TableAttributes
): ITable {
return new (class extends TableBase {
readonly tableName = attrs.tableName;
readonly tableColumns = attrs.tableColumns;
readonly cluster = attrs.cluster;
readonly databaseName = attrs.databaseName;
}(scope, id);
})(scope, id);
}

readonly tableName: string;
Expand All @@ -187,14 +191,14 @@ export class Table extends TableBase {
this.cluster = props.cluster;
this.databaseName = props.databaseName;

this.resource = new DatabaseQuery<TableHandlerProps>(this, 'Resource', {
this.resource = new DatabaseQuery<TableHandlerProps>(this, "Resource", {
removalPolicy: cdk.RemovalPolicy.RETAIN,
...props,
handler: HandlerName.Table,
properties: {
tableName: {
prefix: props.tableName ?? cdk.Names.uniqueId(this),
generateSuffix: !props.tableName,
generateSuffix: !props.tableName ? "true" : "false",
},
tableColumns: this.tableColumns,
},
Expand Down
Loading