Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add primarykey and foreignkey properties to column objects for table-level constraints#2388

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge4 commits intodevelop
base:develop
Choose a base branch
Loading
fromcopilot/fix-foreign-key-detection

Conversation

Copy link
Contributor

CopilotAI commentedDec 17, 2025
edited
Loading

Plan to fix foreign key detection in table columns

  • Explore repository structure and understand the codebase
  • Identify the issue: table-level constraint definitions don't mark columns withprimarykey orforeignkey properties
  • Create test file to validate the fix
  • Modifysrc/60createtable.js to mark columns when PRIMARY KEY constraint is defined
  • Modifysrc/60createtable.js to mark columns when FOREIGN KEY constraint is defined
  • Run tests to ensure fix works correctly
  • Verify no regressions with existing tests (2097 passing)
  • Run code review (addressed feedback)
  • Run security scan (no issues found)
  • Rename test file to test1643.js per review feedback

Summary

Fixed the issue where foreign key and primary key constraints defined at the table level were not marking columns withprimarykey orforeignkey properties. Columns can now be introspected to determine if they are part of a primary key or have foreign key relationships.

Changes:

  • Primary key columns are now marked withprimarykey: true
  • Foreign key columns are now marked with aforeignkey object containingtableid,columnid, andconstraintid (when available)
  • Added comprehensive test coverage for all scenarios in test/test1643.js
Original prompt

This section details on the original issue you should resolve

<issue_title>Foreign key not detected in tables object</issue_title>
<issue_description>I'm having an issue with foreign key detection. I'm creating two tables, let's call them "Table1" and "Table2". Table1 has a primary key called "PK_Table1" on a column named "Column1". Table2 has a foreign key "FK_Table2_Column1" that references "Column1" in "Table1".

When I create the tables and inspect the resulting objects, "Table1" correctly shows "Column1" as having a primary key, but "Table2" does not show "Column1" as having a foreign key. Additionally, when I try to access the "foreignkey" property of "Column1" in "Table2", it doesn't exist.

I've checked the "checks" property of "Table2", and the foreign key constraint appears to be correctly detected and stored there (fk is equal to true and the name of the foreign key is printed, but not the columnid).

Could you please advise on how to properly detect and access foreign keys?

CREATETABLETable1 (    Column1NUMERIC(2,0)NOT NULL,    Column2VARCHAR(50)NOT NULL,    Column3 DATETIMENOT NULL,    Column4 DATETIMENOT NULL,    Column5VARCHAR(50)NOT NULL,    Column6 DATETIMENOT NULL,CONSTRAINT PK_Table1PRIMARY KEY (Column1),CONSTRAINT UC_Column1 UNIQUE (Column1),CONSTRAINT UC_Column3_Column4 UNIQUE (Column3, Column4));CREATETABLETable2 (    Column1NUMERIC(2,0)NOT NULL,    Column2NUMERIC(2,0)NOT NULL,    Column3VARCHAR(300)NOT NULL,    Column4VARCHAR(50)NOT NULL,    Column5 DATETIMENOT NULL,    Column6NUMERIC(4,0)NOT NULL,CONSTRAINT PK_Table2PRIMARY KEY (Column1, Column2),CONSTRAINT UC_PK_Table2 UNIQUE (Column1, Column2),CONSTRAINT FK_Table2_Column1FOREIGN KEY (Column1)REFERENCES Table1(Column1));

JSFiddle:https://jsfiddle.net/rcnv6gfs/</issue_description>

Comments on the Issue (you are@copilot in this section)

@mathiasrwLooks correct to me.@matndev Does this work?

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn moreCopilot coding agent tips in the docs.

Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
CopilotAI changed the title[WIP] Fix foreign key not detected in tables objectAdd primarykey and foreignkey properties to column objects for table-level constraintsDec 17, 2025
CopilotAI requested a review frommathiasrwDecember 17, 2025 13:05
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Copy link
Member

Choose a reason for hiding this comment

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

We cant just check the mark. We need to verify it behaves as expected. With throwing errors if we violate and allows if its correct.

Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@mathiasrwmathiasrwAwaiting requested review from mathiasrw

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Foreign key not detected in tables object

2 participants

@mathiasrw

[8]ページ先頭

©2009-2025 Movatter.jp