-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: redundant Unique constraint on primary join column in Postgres (#…
…9677) * test: one migration for PrimaryColumn and JoinColumn in pg * fix: stop postgres from creating unique on PrimaryColumn with JoinColumn
- Loading branch information
1 parent
1a9b9fb
commit b8704f8
Showing
4 changed files
with
63 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Entity, OneToOne, PrimaryGeneratedColumn } from "../../../../src" | ||
import { UserProfile } from "./UserProfile" | ||
|
||
@Entity() | ||
export class User { | ||
@PrimaryGeneratedColumn() | ||
public id: number | ||
|
||
@OneToOne(() => UserProfile, (userProfile) => userProfile.user) | ||
public profile: UserProfile | ||
} |
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,12 @@ | ||
import { Entity, JoinColumn, OneToOne, PrimaryColumn } from "../../../../src" | ||
import { User } from "./User" | ||
|
||
@Entity() | ||
export class UserProfile { | ||
@PrimaryColumn() | ||
public userId: number | ||
|
||
@OneToOne(() => User, (user) => user.profile) | ||
@JoinColumn() | ||
public user: User | ||
} |
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,36 @@ | ||
import { DataSource } from "../../../src" | ||
import { | ||
createTestingConnections, | ||
closeTestingConnections, | ||
} from "../../utils/test-utils" | ||
import { UserProfile } from "./entity/UserProfile" | ||
import { User } from "./entity/User" | ||
import { expect } from "chai" | ||
|
||
describe("github issues > #8485 second migration is generated for a combination of PrimaryColumn and JoinColumn with Postgres", () => { | ||
let dataSources: DataSource[] | ||
before( | ||
async () => | ||
(dataSources = await createTestingConnections({ | ||
entities: [User, UserProfile], | ||
enabledDrivers: ["postgres"], | ||
dropSchema: true, | ||
schemaCreate: false, | ||
})), | ||
) | ||
after(() => closeTestingConnections(dataSources)) | ||
|
||
it("should not create second migration", () => | ||
Promise.all( | ||
dataSources.map(async (dataSource) => { | ||
await dataSource.driver.createSchemaBuilder().build() | ||
|
||
const sqlInMemory = await dataSource.driver | ||
.createSchemaBuilder() | ||
.log() | ||
|
||
expect(sqlInMemory.upQueries).to.be.empty | ||
expect(sqlInMemory.downQueries).to.be.empty | ||
}), | ||
)) | ||
}) |