Incorrect EntityId column types and missing foreign keys #2318
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
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 beconst 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:
The text was updated successfully, but these errors were encountered: