-
-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(schema): respect schema when renaming columns in postgres (#3344)
- Loading branch information
1 parent
e611fa0
commit f905336
Showing
3 changed files
with
83 additions
and
3 deletions.
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
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,77 @@ | ||
import { Entity, MikroORM, PrimaryKey, Property } from '@mikro-orm/core'; | ||
import type { SqliteDriver } from '@mikro-orm/sqlite'; | ||
|
||
|
||
@Entity({ | ||
tableName: 'gh3339.Customer', | ||
}) | ||
export class Customer1 { | ||
|
||
@PrimaryKey({ fieldName: 'ID', type: 'number' }) | ||
id!: number; | ||
|
||
@Property() | ||
customerName?: string; | ||
|
||
} | ||
|
||
@Entity({ | ||
tableName: 'gh3339.Customer', | ||
}) | ||
export class Customer2 { | ||
|
||
@PrimaryKey({ fieldName: 'ID', type: 'number' }) | ||
id!: number; | ||
|
||
@Property() | ||
name?: string; | ||
|
||
} | ||
|
||
@Entity({ | ||
tableName: 'gh3339.Customer', | ||
}) | ||
export class Customer3 { | ||
|
||
@PrimaryKey({ fieldName: 'ID', type: 'number' }) | ||
id!: number; | ||
|
||
@Property() | ||
c_name?: string; | ||
|
||
} | ||
|
||
describe('GH issue 3339', () => { | ||
|
||
let orm: MikroORM; | ||
|
||
beforeAll(async () => { | ||
orm = await MikroORM.init({ | ||
dbName: `mikro_orm_test_gh_3339`, | ||
type: 'postgresql', | ||
schema: 'gh3339', | ||
entities: [ Customer1 ], | ||
}); | ||
const generator = orm.getSchemaGenerator(); | ||
await generator.ensureDatabase(); | ||
await generator.dropSchema(); | ||
await generator.createSchema(); | ||
await generator.refreshDatabase(); | ||
}); | ||
|
||
afterAll(() => orm.close(true)); | ||
|
||
test('reference schema name when updating column names inside sql', async () => { | ||
await orm.discoverEntity(Customer2); | ||
orm.getMetadata().reset('Customer1'); | ||
const diff1 = await orm.getSchemaGenerator().getUpdateSchemaSQL({ wrap: false }); | ||
expect(diff1).toContain('"gh3339"."Customer"'); | ||
await orm.getSchemaGenerator().execute(diff1); | ||
|
||
await orm.discoverEntity(Customer3); | ||
orm.getMetadata().reset('Customer2'); | ||
const diff2 = await orm.getSchemaGenerator().getUpdateSchemaSQL({ wrap: false }); | ||
expect(diff2).toContain('"gh3339"."Customer"'); | ||
await orm.getSchemaGenerator().execute(diff2); | ||
}); | ||
}); |