fix: #10040 TypeORM synchronize database even if it is up to date (#10041)

* test: #10040 TypeORM synchronize database even if it is up to date

* formating

* fix: TypeORM synchronize database even if it is up to date #10040
This commit is contained in:
juliengbt 2023-06-20 21:38:55 +02:00 committed by GitHub
parent 7108cc6f71
commit b1a3a39504
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 1 deletions

View File

@ -842,7 +842,10 @@ export class MysqlDriver implements Driver {
* fix https://github.com/typeorm/typeorm/issues/1139
* note that if the db did support uuid column type it wouldn't have been defaulted to varchar
*/
if (column.generationStrategy === "uuid" && column.type === "varchar")
if (
column.generationStrategy === "uuid" &&
!this.uuidColumnTypeSuported
)
return "36"
switch (column.type) {

View File

@ -0,0 +1,19 @@
import {
Column,
Entity,
OneToMany,
PrimaryGeneratedColumn,
} from "../../../../src"
import { Todo } from "./todo"
@Entity({ name: "person" })
export class Person {
@PrimaryGeneratedColumn("uuid")
id: string
@Column("varchar")
name: string
@OneToMany(() => Todo, (o) => o.owner)
todos: Todo[]
}

View File

@ -0,0 +1,19 @@
import {
Column,
Entity,
ManyToOne,
PrimaryGeneratedColumn,
} from "../../../../src"
import { Person } from "./person"
@Entity({ name: "todo" })
export class Todo {
@PrimaryGeneratedColumn("uuid")
id: string
@Column("varchar")
description: string
@ManyToOne(() => Person, (o) => o.todos)
owner: Person
}

View File

@ -0,0 +1,33 @@
import { expect } from "chai"
import { DataSource } from "../../../src"
import {
closeTestingConnections,
createTestingConnections,
reloadTestingDatabases,
} from "../../utils/test-utils"
import { Person } from "./entity/person"
import { Todo } from "./entity/todo"
describe("github issues > #10040 TypeORM synchronize database even if it is up to date", () => {
let dataSources: DataSource[]
before(async () => {
dataSources = await createTestingConnections({
entities: [Person, Todo],
enabledDrivers: ["mysql"],
})
})
beforeEach(() => reloadTestingDatabases(dataSources))
after(() => closeTestingConnections(dataSources))
it("should return an empty array for the upQueries after sync", async () => {
await Promise.all(
dataSources.map(async (dataSource) => {
await dataSource.synchronize()
const logs = await dataSource.driver.createSchemaBuilder().log()
expect(logs.upQueries.length).to.be.eql(0)
}),
)
})
})