Add Support for Foreign Key Constraints #352
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes: #174
This fixes the following methods:
The basic idea is that when we want to create a foreign key between a
from_tableandto_tablewe ask:to_tablealready schema qualified? If so, leave it as it.to_tableandfrom_tableboth belong to the same schema? If so, leave them as is.to_tablewith the schema that it should belong to.The methods
#add_foreign_keyand#remove_foreign_keyare used under the hood by#add_reference,#remove_reference, and#change_tableso the fix works for all of them.A similar fix is added for
TableDefinition#foreign_keythat is used in#create_tableKnowing what schema a foreign key constraint should be on requires knowing what the database's "default" schema was (i.e., the current schema before we manipulated it by calling
#on_temporal_schemaor#on_history_schema). So this modifies#on_schemato keep track of that.@tagliala Let me know what you think of this approach and if it looks good I can address some of the outstanding issues and clean up the code a bit.
Todo:
#remove_foreign_keyis givennilfor theto_tablekeyword argument