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

Incorrect EntityId column types and missing foreign keys #2318

Open
jacobfrantz1 opened this issue Jul 26, 2023 · 2 comments
Open

Incorrect EntityId column types and missing foreign keys #2318

jacobfrantz1 opened this issue Jul 26, 2023 · 2 comments
Assignees
Labels
P4: low Non-critical, workarounds exist status: research needed 🔍 More in-depth research need to make a decision+ type: bug 🐛 Something isn't working @vendure/core
Milestone

Comments

@jacobfrantz1
Copy link
Contributor

Describe the bug
There's weirdness related to EntityId() Columns that don't have a foreign key. They don't use the entityIdStrategy's primaryKeyType and use varchar instead. This led to problems when I was migrating to v2, which I documented in vendure-ecommerce/v2-migration-tool#9. I only found 2 EntityId Columns without a foreign key in the project. They are product_variant_price.channelId and order.taxZoneId.

Expected behavior
The two columns that use the EntityId decorator and don't have a foreign key should have a foreign key, and the code that incorrectly assumes the type as varchar should be corrected. We shouldn't rely on typeorm fixing foreign key types, which is what I think is occurring.

The code const columnDataType = entityIdStrategy.primaryKeyType === 'increment' ? 'int' : 'varchar'; in set-entity-id-strategy.ts should probably be const columnDataType = entityIdStrategy.primaryKeyType === 'increment' ? 'int' : entityIdStrategy.primaryKeyType;

This would be a breaking change for anybody using a primaryKeyType other than increment, and a migration would be required for it.

Environment:

  • @vendure/core version: 2.0.4
  • Nodejs version: 16.20.1
  • Database (mysql/postgres etc): postgresql 14
@michaelbromley
Copy link
Member

Hi,
thanks for the report. This would indeed be a breaking change but you are totally correct, we should use 'uuid' rather than 'varchar'.

I've added this to "planned" but I'm not sure yet when I want to make the change. Apart from the migration issue, did you run into any other problems due to the varchar data type?

@jacobfrantz1
Copy link
Contributor Author

I didn't have any other problems due to the varchar data type that I know of.

@dlhck dlhck added P4: low Non-critical, workarounds exist and removed next major labels Sep 24, 2024
@dlhck dlhck moved this from 📅 Planned to 📦 Backlog in Vendure OS Roadmap Sep 24, 2024
@dlhck dlhck added the status: research needed 🔍 More in-depth research need to make a decision+ label Sep 27, 2024
@dlhck dlhck added this to the v3.4.0 milestone Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4: low Non-critical, workarounds exist status: research needed 🔍 More in-depth research need to make a decision+ type: bug 🐛 Something isn't working @vendure/core
Projects
Status: 📅 Planned
Development

No branches or pull requests

3 participants