Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@thisiscab
Copy link
Contributor

Description

Add the ability to add table constraint to Redshift tables.

Motivation and Context

While the table keys constraints (UNIQUE, PRIMARY, FOREIGN) aren't
enforced by Redshift, it's still useful to be able to set that data.
Given the situation that there is a monitoring task that manually checks
if the table constraints are respected, it's useful to be able to set
multiple primary keys on a given table.

Based on the syntax of the CREATE commands of Redshift (see link down
below) we think it's useful to add support to it.

https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html

Have you tested this? If so, how?

We've been using this feature for a few months now without problems.

Copy link
Collaborator

@dlstadther dlstadther left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this can be tested, but mind checking?

Thanks!

type=self.table_type,
table=self.table,
coldefs=coldefs,
table_constraints=table_constraints,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of the scope of this PR, but if you'd like it would be awesome to reduce the duplicated code here for where len == 2 and len == 3 for the creation of query. The only difference is the definition of coldefs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would agree with you that the whole Redshift contrib should be refactored. There would a lot of value to make it a little bit more DRY.

If I have more time in the upcoming weeks I'll take a jab at refactoring it so that it's a little bit saner! :)

@thisiscab thisiscab force-pushed the feature/add-table-constraints-to-redshift branch 2 times, most recently from c8161d6 to 831b8e0 Compare June 6, 2018 20:36
While the table keys constraints (UNIQUE, PRIMARY, FOREIGN) aren't
enforced by Redshift, it's still useful to be able to set that data.
Given the situation that there is a monitoring task that manually checks
if the table constraints are respected, it's useful to be able to set
multiple primary keys on a given table.

Based on the syntax of the CREATE commands of Redshift (see link down
below) we think it's useful to add support to it.

https://docs.aws.amazon.com/redshift/latest/dg/r_CREATE_TABLE_NEW.html
@thisiscab thisiscab force-pushed the feature/add-table-constraints-to-redshift branch from 831b8e0 to aaf3282 Compare June 6, 2018 20:37
@thisiscab
Copy link
Contributor Author

@dlstadther I've added specs like you've suggested. It seems though that there is a spec that randomly fails that is not related to my edit. What would you suggest the next step be?

@thisiscab
Copy link
Contributor Author

Now that I think more about this, maybe the constraint should be a tuple instead of a string. I'll think about it overnight and see where I stand on this!

@dlstadther
Copy link
Collaborator

I reran the build and got a green build... weird

@thisiscab
Copy link
Contributor Author

I've decided to keep going on with the string instead of the tuple to follow the same behavior as table_attributes. So you've got my green light on this! :)

@dlstadther dlstadther merged commit fdf8b59 into spotify:master Jul 9, 2018
@dlstadther
Copy link
Collaborator

Sorry for the delay here @cabouffard . Thanks for contributing!

@thisiscab thisiscab deleted the feature/add-table-constraints-to-redshift branch July 9, 2018 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants