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

Create explicit foreignKey element #87

Closed
austinhyde opened this issue Jul 1, 2015 · 1 comment
Closed

Create explicit foreignKey element #87

austinhyde opened this issue Jul 1, 2015 · 1 comment

Comments

@austinhyde
Copy link
Member

MySQL does this thing where it generates indexes for foreign keys, unless you already have one defined. The issue is that the mysql5 driver can only accurately detect this for the single-column case, since composite foreign keys are defined as explicit SQL in a <constraint> tag.

The solution for this is to create a new <foreignKey> element which acts as an alternative to a <constraint>, and explicitly defines source and target columns for the foreign key. This will allow both mysql5 and pgsql8 drivers to better handle validation and bizarre behavior.

This functionality needs added to both mysql5 and pgsql8 drivers, for:

  • Extraction: Extract composite foreign keys as foreignKey elements, rather than constraint elements
  • XML Parsing: Need to ensure overlays work correctly, and that referenced source columns exist in the current table, and that referenced target columns exist in the target table.
  • SQL Output: Need to generate correct DDL for creating/updating/dropping a foreignKey element. It will probably be easiest to just have the existing constraint system recognize foreignKey as a type of constraint, similar to column unique, column foreign keys, or actual <constraint>s.

An example foreignKey definition would be:

<table ...>
  <foreignKey
      columns="column_one, column_two"
      foreignSchema="other_schema"
      foreignTable="other_table"
      foreignColumns="column_one, column_two"
      constraintName="table_one_col_one_two_fkey"
      indexName="table_one_col_one_two_fkey_idx">
</table>
  • foreignSchema may be omitted if the foreignTable is in the current schema.
  • foreignColumns may be omitted if the columns are named the same as those listed in columns.
  • constraintName defines what the name of the constraint should be.
  • indexName is optional, and serves as a hint for mysql to name the corresponding "magic index"
@nkiraly
Copy link
Member

nkiraly commented Aug 17, 2015

This is available as of v1.4.0-alpha2

@nkiraly nkiraly assigned nkiraly and unassigned nkiraly Aug 17, 2015
nkiraly added a commit that referenced this issue Aug 17, 2015
…d processing

XML foreignKey element support and constraint definition refactoring github/nkiraly/DBSteward PR #93 issue #87
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants