typeorm
typeorm copied to clipboard
Allow index naming on JoinTable
Feature Description
Allowing to specify index names when creating a JoinTable.
The Problem
I'm personally looking to pick up an existing database with TypeORM and am trying to do so with minimal changes, unfortunately I can't count on index names being made with a single strategy for this. So a NamingStrategy might not be sufficient.
The Solution
Adding inputs for index names onto JoinTable, e.g.;
@JoinTable({
indices: {
ownerName: "index_user_id",
inverseName: "index_role_id",
},
})
Considered Alternatives
I considered fully adding indices here akin to JoinColumns being specified, however that complicates the work needed by a lot so for the meantime I opted for this. There may be other alternatives I haven't considered yet since I'm not too experienced with the code base at the moment.
Relevant Database Driver(s)
I don't think, no matter what changes get requested, this will need adjustments in database drivers.
DB Type | Relevant |
---|---|
aurora-data-api |
no |
aurora-data-api-pg |
no |
better-sqlite3 |
no |
cockroachdb |
no |
cordova |
no |
expo |
no |
mongodb |
no |
mysql |
no |
nativescript |
no |
oracle |
no |
postgres |
no |
react-native |
no |
sap |
no |
sqlite |
no |
sqlite-abstract |
no |
sqljs |
no |
sqlserver |
no |
Are you willing to resolve this issue by submitting a Pull Request?
- ✅ Yes, I have the time, and I know how to start.
- ✖️ Yes, I have the time, but I don't know how to start. I would need guidance.
- ✖️ No, I don’t have the time, but I can support (using donations) development.
- ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
I already have a commit ready for the changes as suggested in this issue, I'm opening the issue for a # to create the tests under and for early feedback on the idea. If need be and if so requested I should be able to make the alternative as mentioned as well (adding full index options), although would appreciate some pointers on execution of that.
Sounds great, maybe we can adding inputs for index names onto JoinTable, e.g.;
@JoinTable({
name: 'paymentTransactions',
joinColumn: {
name: 'paymentId',
foreignKeyConstraintName: 'payment',
referencedColumnName: 'id',
index: 'paymentIdx'
},
inverseJoinColumn: {
name: 'transactionId',
foreignKeyConstraintName: 'transaction',
referencedColumnName: 'id',
index: 'transactionIdx'
}
})
Hi, is a PR planned? What are the nexts steps on this subject? I wanted to migrate from V2.30 to V3.11, and given the change of strategy, we should pass / wait by this feature, to have zero downtime on our saas.
I really like the idea of @trylovetom :)
@JoinColumn
needs this as well