forked from typeorm/typeorm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support changing comments in MySQL columns (typeorm#6903)
in the mysql driver, column comments were only half supported - adding them to new columns & new tables was possible, but updating existing columns to include comments was not possible there also was no escaping done on the column comments - so depending on the contents of your comment, an invalid query could be generated adds support to add comments to existing columns, adds simple comment escaping code, & creates tests to verify the behavior
- Loading branch information
1 parent
0956ffc
commit c5143aa
Showing
6 changed files
with
133 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {expect} from "chai"; | ||
import "reflect-metadata"; | ||
import {Connection} from "../../../../src"; | ||
import {closeTestingConnections, createTestingConnections, reloadTestingDatabases} from "../../../utils/test-utils"; | ||
import {Test} from "./entity/Test"; | ||
|
||
describe("columns > comments", () => { | ||
|
||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
entities: [Test], | ||
// Only supported on mysql | ||
enabledDrivers: ["mysql"] | ||
})); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should persist comments of different types to the database", () => Promise.all(connections.map(async connection => { | ||
const table = (await connection.createQueryRunner().getTable("test"))!; | ||
|
||
expect(table.findColumnByName("a")!.comment).to.be.equal("Hello World") | ||
expect(table.findColumnByName("b")!.comment).to.be.equal("Hello\nWorld") | ||
expect(table.findColumnByName("c")!.comment).to.be.equal("Hello World! It's going to be a beautiful day.") | ||
expect(table.findColumnByName("d")!.comment).to.be.equal("Hello World! #@!$`") | ||
expect(table.findColumnByName("e")!.comment).to.be.equal("Hello World. \r\n\t\b\f\v") | ||
expect(table.findColumnByName("f")!.comment).to.be.equal("Hello World.\\") | ||
expect(table.findColumnByName("g")!.comment).to.be.equal(" ") | ||
expect(table.findColumnByName("h")!.comment).to.be.equal(undefined); | ||
expect(table.findColumnByName("i")!.comment).to.be.equal(undefined); | ||
|
||
}))); | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {Entity} from "../../../../../src/decorator/entity/Entity"; | ||
import {Column} from "../../../../../src/decorator/columns/Column"; | ||
import {PrimaryGeneratedColumn} from "../../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
|
||
@Entity() | ||
export class Test { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
// Standard Comment | ||
@Column({ comment: "Hello World"}) | ||
a: string; | ||
|
||
// Comment with a newline | ||
@Column({ comment: "Hello\nWorld"}) | ||
b: string; | ||
|
||
// Comment with a single quote | ||
@Column({ comment: "Hello World! It's going to be a beautiful day."}) | ||
c: string; | ||
|
||
// Comment with special characters | ||
@Column({ comment: "Hello World! #@!$`"}) | ||
d: string; | ||
|
||
// Comment with control characters | ||
@Column({ comment: "Hello World. \r\n\t\b\f\v\0"}) | ||
e: string; | ||
|
||
// Comment that ends with a backslash | ||
@Column({ comment: "Hello World.\\"}) | ||
f: string; | ||
|
||
// Comment that is only whitespace | ||
@Column({ comment: " "}) | ||
g: string; | ||
|
||
// Comment that is empty | ||
@Column({ comment: ""}) | ||
h: string; | ||
|
||
// No comment. | ||
@Column() | ||
i: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters