fix: resolves issue with mssql column recreation (#9773)

* fix: resolves issue with mssql column recreation when length max is in lower case

Closes: #9399

* removed redundant question mark

---------

Co-authored-by: ke <ke@sbs.co.at>
This commit is contained in:
ertl 2023-04-05 18:13:57 +02:00 committed by GitHub
parent cb154d4ca3
commit 07221a3646
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 1 deletions

View File

@ -1042,7 +1042,10 @@ export class SqlServerDriver implements Driver {
// of data type precedence to the expressions specified in the formula.
if (columnMetadata.asExpression) return false
return tableColumn.length !== this.getColumnLength(columnMetadata)
return (
tableColumn.length.toUpperCase() !==
this.getColumnLength(columnMetadata).toUpperCase()
)
}
protected lowerDefaultValueIfNecessary(value: string | undefined) {

View File

@ -0,0 +1,13 @@
import { Entity, Generated } from "../../../../src"
import { PrimaryGeneratedColumn } from "../../../../src"
import { Column } from "../../../../src"
@Entity()
export class ExampleEntity {
@Generated("increment")
@PrimaryGeneratedColumn()
id: number
@Column({ type: "nvarchar", length: "max" })
value: string
}

View File

@ -0,0 +1,34 @@
import "reflect-metadata"
import {
createTestingConnections,
closeTestingConnections,
} from "../../utils/test-utils"
import { DataSource } from "../../../src"
import { expect } from "chai"
describe("github issues > #9399 mssql: Column is dropped and recreated in every migration", () => {
let dataSources: DataSource[]
before(
async () =>
(dataSources = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
schemaCreate: true,
dropSchema: true,
enabledDrivers: ["mssql"],
})),
)
after(() => closeTestingConnections(dataSources))
it("No migration should be created", () =>
Promise.all(
dataSources.map(async (dataSource) => {
await dataSource.runMigrations()
const sqlInMemory = await dataSource.driver
.createSchemaBuilder()
.log()
expect(sqlInMemory.upQueries.length).to.eql(0)
expect(sqlInMemory.downQueries.length).to.eql(0)
}),
))
})