Skip to content

Comments

openreader: allow to disable fk contraint#431

Merged
belopash merged 3 commits intomasterfrom
disable-fk-constraint
Feb 10, 2026
Merged

openreader: allow to disable fk contraint#431
belopash merged 3 commits intomasterfrom
disable-fk-constraint

Conversation

@belopash
Copy link
Contributor

@belopash belopash commented Feb 9, 2026

No description provided.

directive @fulltext(query: String!) on FIELD_DEFINITION
directive @cardinality(value: Int!) on OBJECT | FIELD_DEFINITION
directive @byteWeight(value: Float!) on FIELD_DEFINITION
directive @disableForeignKeyConstraint on FIELD_DEFINITION
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mo4islona not sure about directive name

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm good with this name

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support in openreader/typeorm code generation to disable DB-level foreign key constraints for entity relationships, and updates the ERC20 transfers example to use nullable FK relations without enforced constraints.

Changes:

  • Introduces @disableForeignKeyConstraint directive in openreader schema parsing and plumbs it through the model (FkPropType.disableConstraint).
  • Updates TypeORM model codegen to emit createForeignKeyConstraints: false for FK relations when requested.
  • Extends OpenCRUD schema/query planning to expose <fkField>Id scalar fields and allow selecting/filtering by them; updates the erc20-transfers example schema/models/migrations accordingly.

Reviewed changes

Copilot reviewed 11 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
typeorm/typeorm-codegen/src/codegen.ts Emits createForeignKeyConstraints: false for FK relations when disableConstraint is set.
graphql/openreader/src/model.ts Adds disableConstraint?: boolean to FkPropType.
graphql/openreader/src/model.schema.ts Adds @disableForeignKeyConstraint directive and maps it into FK property metadata.
graphql/openreader/src/util/util.ts Adds helpers to derive/recognize <fkField>Id virtual fields.
graphql/openreader/src/sql/cursor.ts Allows resolving virtual <fkField>Id fields as scalar columns.
graphql/openreader/src/dialect/opencrud/schema.ts Exposes <fkField>Id output fields and adds where-filter support for them.
graphql/openreader/src/dialect/opencrud/tree.ts Allows requesting <fkField>Id even though it isn’t a modeled property.
test/erc20-transfers/schema.graphql Adds Account entity and marks Transfer.from/to with @disableForeignKeyConstraint.
test/erc20-transfers/src/model/generated/account.model.ts Adds generated Account entity model.
test/erc20-transfers/src/model/generated/transfer.model.ts Changes from/to from scalar strings to FK relations with constraints disabled.
test/erc20-transfers/src/model/generated/index.ts Exports the newly generated Account model.
test/erc20-transfers/src/processor.ts Writes from/to as Account references (id-only objects) instead of strings.
test/erc20-transfers/db/migrations/1770630835290-Data.js New migration reflecting the new schema (account table + transfer FK id columns + indexes).
test/erc20-transfers/db/migrations/1682961487386-Data.js Removes the old migration that stored from/to as text columns.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@belopash belopash merged commit dc71ff1 into master Feb 10, 2026
1 check passed
@belopash belopash deleted the disable-fk-constraint branch February 10, 2026 21:51
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

Successfully merging this pull request may close these issues.

2 participants