-
-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(schema): fix renaming of multiple columns at the same time
Closes #1262
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import 'reflect-metadata'; | ||
import { Entity, MikroORM, PrimaryKey, Property } from '@mikro-orm/core'; | ||
import { remove } from 'fs-extra'; | ||
import { TEMP_DIR } from '../bootstrap'; | ||
|
||
@Entity({ tableName: 'user' }) | ||
class UserBefore { | ||
|
||
@PrimaryKey() | ||
id!: string; | ||
|
||
@Property() | ||
created: Date = new Date(); | ||
|
||
@Property() | ||
updated: Date = new Date(); | ||
|
||
@Property() | ||
deleted: Date = new Date(); | ||
|
||
} | ||
|
||
@Entity({ tableName: 'user' }) | ||
class UserAfter { | ||
|
||
@PrimaryKey() | ||
id!: string; | ||
|
||
@Property() | ||
createdAt: Date = new Date(); | ||
|
||
@Property() | ||
updatedAt: Date = new Date(); | ||
|
||
@Property() | ||
deletedAt: Date = new Date(); | ||
|
||
} | ||
|
||
describe('GH issue 1262', () => { | ||
|
||
async function createAndRunMigration(entities: any[]) { | ||
const db = await MikroORM.init({ | ||
type: 'sqlite', | ||
entities, | ||
dbName: TEMP_DIR + '/gh_1262.db', | ||
}); | ||
|
||
await db.getSchemaGenerator().updateSchema(); | ||
await db.close(); | ||
} | ||
|
||
test('renaming multiple columns at once', async () => { | ||
await remove(TEMP_DIR + '/gh_1262.db'); | ||
await createAndRunMigration([UserBefore]); | ||
|
||
// Simulates adding `profile` to the User entity | ||
await createAndRunMigration([UserAfter]); | ||
await remove(TEMP_DIR + '/gh_1262.db'); | ||
}); | ||
|
||
}); |