Skip to content

Commit

Permalink
revert: "feat: use char(36) for uuid representation in mysql (#7853)" (
Browse files Browse the repository at this point in the history
…#8343)

This reverts commit 063aafa.
  • Loading branch information
pleerock committed Nov 9, 2021
1 parent ae858ad commit 1588c58
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
11 changes: 7 additions & 4 deletions src/driver/mysql/MysqlDriver.ts
Expand Up @@ -610,7 +610,7 @@ export class MysqlDriver implements Driver {
return "tinyint";

} else if (column.type === "uuid") {
return "char";
return "varchar";

} else if (column.type === "json" && this.options.type === "mariadb") {
/*
Expand Down Expand Up @@ -703,10 +703,13 @@ export class MysqlDriver implements Driver {
if (column.length)
return column.length.toString();

switch (column.type) {
case "uuid":
return "36";
/**
* fix https://github.com/typeorm/typeorm/issues/1139
*/
if (column.generationStrategy === "uuid")
return "36";

switch (column.type) {
case String:
case "varchar":
case "nvarchar":
Expand Down
16 changes: 3 additions & 13 deletions test/functional/uuid/mysql/uuid-mysql.ts
Expand Up @@ -30,7 +30,7 @@ describe("uuid-mysql", () => {
await postRepository.save(post);
const loadedPost = await postRepository.findOne(1);
expect(loadedPost!.uuid).to.be.exist;
postTable!.findColumnByName("uuid")!.type.should.be.equal("char");
postTable!.findColumnByName("uuid")!.type.should.be.equal("varchar");

const post2 = new Post();
post2.uuid = "fd357b8f-8838-42f6-b7a2-ae027444e895";
Expand All @@ -47,11 +47,10 @@ describe("uuid-mysql", () => {
expect(loadedQuestion!.uuid2).to.equal("fd357b8f-8838-42f6-b7a2-ae027444e895");
expect(loadedQuestion!.uuid3).to.be.null;
expect(loadedQuestion!.uuid4).to.be.exist;
questionTable!.findColumnByName("id")!.type.should.be.equal("char");
questionTable!.findColumnByName("uuid")!.type.should.be.equal("char");
questionTable!.findColumnByName("id")!.type.should.be.equal("varchar");
questionTable!.findColumnByName("uuid")!.type.should.be.equal("varchar");
questionTable!.findColumnByName("uuid2")!.type.should.be.equal("varchar");
questionTable!.findColumnByName("uuid3")!.type.should.be.equal("varchar");
questionTable!.findColumnByName("uuid4")!.type.should.be.equal("char");

const question2 = new Question();
question2.id = "1ecad7f6-23ee-453e-bb44-16eca26d5189";
Expand All @@ -77,13 +76,4 @@ describe("uuid-mysql", () => {
expect(question!.uuid2).to.exist;
})));

it("should create a table column that's char(36)", () => Promise.all(connections.map(async connection => {
const table = await connection.createQueryRunner().getTable('question')

const column = table?.findColumnByName("uuid")

expect(column?.type).to.equal("char")
expect(column?.length).to.equal("36")
})));

});

0 comments on commit 1588c58

Please sign in to comment.