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
feat: add support to string array on dropColumns #7654
Conversation
changedTable.findColumnForeignKeys(column).forEach(fk => changedTable.removeForeignKey(fk)); | ||
columns.forEach((column: TableColumn|string) => { | ||
const columnInstance = column instanceof TableColumn ? column : table.findColumnByName(column); | ||
if (!columnInstance) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We must throw an error here instead of silently break the operation:
if (!columnInstance)
throw new Error(`Column "${column}" was not found in table "${table.name}"`);
table.findColumnForeignKeys(column).forEach(fk => table.removeForeignKey(fk)); | ||
columns.forEach((column: TableColumn|string) => { | ||
const columnInstance = column instanceof TableColumn ? column : table.findColumnByName(column); | ||
if (!columnInstance) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We must throw an error here instead of silently break the operation:
if (!columnInstance)
throw new Error(`Column "${column}" was not found in table "${table.name}"`);
@AlexMesser i've applied your suggestions and some tests are failing now... as soon as i fixes then I let you know, thanks! |
#4807 related |
table.removeColumn(columnInstance); | ||
table.findColumnUniques(columnInstance).forEach(unique => table.removeUniqueConstraint(unique)); | ||
table.findColumnIndices(columnInstance).forEach(index => table.removeIndex(index)); | ||
table.findColumnForeignKeys(columnInstance).forEach(fk => table.removeForeignKey(fk)); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this block after await this.recreateTable(changedTable, table);
since table
is replaced with changedTable
in recreateTable()
method. This is why your test is failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @AlexMesser, now all tests passed!
removed `skip`
|
||
await queryRunner.executeMemoryDownSql(); | ||
describe("when columns are strings", () => { | ||
it("should correctly drop column and revert drop", () => Promise.all(connections.map(async connection => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add test to affirm that trying to drop a non-existent column emits an error
thank you for contribution! |
Description of change
This PR intends to add support to an array of strings when droping a list of columns.
After this PR, this:
will turn into this:
Less verbosity and keep consistent with
dropColumn
that already accept a string.Fixes #4807
Fixes #7655
Pull-Request Checklist
master
branchnpm run lint
passes with this changenpm run test
passes with this changeFixes #0000