changes to allow for compound foreign keys#203
Conversation
|
Sorry for not reviewing this yet! I'll try to carve out time to look at it in the next few days. |
| Trigger = namedtuple("Trigger", ("name", "table", "sql")) | ||
|
|
||
|
|
||
| class ForeignKey(ForeignKeyBase): |
There was a problem hiding this comment.
It looks like ForeignKeyBase is missing - I added this and the tests started passing again:
ForeignKeyBase = namedtuple(
"ForeignKey", ("table", "column", "other_table", "other_column")
)|
Sorry for taking so long to review this! This approach looks great to me - being able to optionally pass a tuple anywhere the API currently expects a column is smart, and it's consistent with how the There's just one problem I can see with this: the way it changes the This represents a breaking change to the existing API - any code that expects As such, I'd have to bump the major version of Ideally I'd like to make this change in a way that doesn't represent an API compatibility break. I need to think a bit harder about how that might be achieved. |
|
One way that this could avoid a breaking change would be to have This is a bit of an ugly API design, and it could still break existing code that encounters a compound foreign key for the first time - but it would leave code working for the more common case of a non-compound-foreign-key. |
|
Another option: expand the The question then is what should I'd be inclined to say they should return We can label Since this would still be a breaking change in some minor edge-cases I'm thinking maybe 4.0 needs to happen in order to land this feature. I'm not opposed to doing that, I was just hoping it might be avoidable. |
|
Thanks for looking at this - home schooling kids has prevented me from replying. I'd struggled with how to adapt the API for the foreign keys too - I definitely tried the String/Tuple approach. I hadn't considered the breaking changes that would introduce though. I can take a look at this and try and make the change - see which of your options works best. I've got a workaround for the use-case I was looking at this for, so it wouldn't be a problem for me if it was put on the back burner until a hypothetical v4.0 anyway. |
|
Is there any progress elsewhere on the handling of compound / composite foreign keys, or is this PR still effectively open? |
|
i'll adopt this PR to make the changes @simonw suggested #203 (comment) |
Add support for compound foreign keys, as per issue #117
Not sure if this is the right approach. In particular I'm unsure about:
ForeignKeyclass, which replaces the namedtuple in order to ensure thatcolumnandother_columnare forced into tuples. The class does the job, but doesn't feel very elegant.guess_foreign_tableto take account of multiple columns, so it just checks for the first column in the foreign key definition. This isn't ideal.The PR also contains a minor related change that columns and tables are always quoted in foreign key definitions.