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

FK column from referencing table not present in "references" but present in "alter" #196

Open
tduval-unifylogic opened this issue Apr 14, 2023 · 6 comments

Comments

@tduval-unifylogic
Copy link

Describe the bug
when a foreign key is defined within CREATE TABLE tablename ():

CONSTRAINT fk_order FOREIGN KEY (order_identifier) REFERENCES orders(order_id),

The column order_identifier is not output in the results, so no way to know which column from the table is the referencing column. e.g., output:

"references": [
  {
    "table": "orders",
    "columns": [
      "order_id"
    ],
    "schema": null,
    "on_delete": null,
    "on_update": null,
    "deferrable_initially": null,
    "constraint_name": "fk_order"
  }
]

To Reproduce
Steps to reproduce the behavior (this example is using postgres as dialect):

  1. process file1.sql and view results and find alter in order_items table results. Column "name": "order_identifier" is present
sql = open('file1.sql', 'r').read()
results = parse_from_file(sql, group_by_type=True)
print(json.dumps(results, indent=2))
  1. process file2.sql and find constraints/references in order_items table results. Column "name": "order_identifier" is not present
sql = open('file2.sql', 'r').read()
results = parse_from_file(sql, group_by_type=True)
print(json.dumps(results, indent=2))

Expected behavior
to see similar results output from alter, where the name of referencing column is presented:

"alter": {
  "columns": [
    {
        "name": "order_identifier",
        "constraint_name": "fk_order",
        "references": {
          "table": "orders",
          "schema": null,
          "on_delete": null,
          "on_update": null,
          "deferrable_initially": null,
          "column": "product_id"
            }
    }, ...

Screenshots
n/a

Desktop (please complete the following information):

  • OS: macOS Monterey v12.6.1, Mac mini (M1, 2020)
  • Browser: n/a
  • Version:
    • python == 3.9.6
    • simple-ddl-parser == 0.30.0

Smartphone (please complete the following information):

  • Device: n/a
  • OS: n/a
  • Browser: n/a
  • Version: n/a

Additional context
Add any other context about the problem here.

@tduval-unifylogic tduval-unifylogic changed the title FK column from referencing table not present in _references_ but present in _alter_ FK column from referencing table not present in "references" but present in "alter" Apr 14, 2023
@tduval-unifylogic
Copy link
Author

@xnuinside , checking in... would really like to use your parser as it is amazing!
The referencing column metadata missing is a blocker for us though.
Any idea on when this could get resolved?

@xnuinside
Copy link
Owner

xnuinside commented Apr 24, 2023

@tduval-unifylogic hi! I will have time on this weekends, I hope, I will create new release with fix

@tduval-unifylogic
Copy link
Author

Thank you!
Access to parsed comments would also be a blessing! I know there's an issue captured on this already.
We're creating ontologies from schemas, so any semantic context we can get is a bonus.

@xnuinside
Copy link
Owner

sure, I will try to add it

@cfhowes
Copy link
Contributor

cfhowes commented Jan 5, 2024

I am having the same problem. Will try and post a PR in the next couple of days.

cfhowes added a commit to cfhowes/simple-ddl-parser that referenced this issue Jan 6, 2024
xnuinside added a commit that referenced this issue Jan 7, 2024
Issue #196: Add the 'name' to the 'reference' block for FOREIGN KEY constraints
@cfhowes
Copy link
Contributor

cfhowes commented Jan 8, 2024

I don't have the ability to update ticket status, but I believe that as of version 0.32.0 this should be solved.

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

No branches or pull requests

3 participants