Skip to content

Commit

Permalink
fix: resolves issue with mssql column recreation (#9773)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
ertl and ertl committed Apr 5, 2023
1 parent cb154d4 commit 07221a3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/driver/sqlserver/SqlServerDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions test/github-issues/9399/entity/ExampleEntity.ts
Original file line number Diff line number Diff line change
@@ -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
}
34 changes: 34 additions & 0 deletions test/github-issues/9399/issue-9399.ts
Original file line number Diff line number Diff line change
@@ -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)
}),
))
})

0 comments on commit 07221a3

Please sign in to comment.