undeexcepturi
Version:
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.
60 lines (42 loc) • 1.18 kB
text/typescript
import 'reflect-metadata';
import { Entity, MikroORM, OneToOne, PrimaryKey } from '@mikro-orm/core';
import { SqliteDriver } from '@mikro-orm/sqlite';
()
class Profile {
()
id!: string;
}
()
class User {
()
id!: string;
}
({ tableName: 'user' })
class User2 {
()
id!: string;
(() => Profile, undefined, { nullable: true })
profile!: Profile;
}
describe('adding FK column (GH 942)', () => {
let orm: MikroORM<SqliteDriver>;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [User, Profile],
driver: SqliteDriver,
dbName: ':memory:',
});
await orm.schema.createSchema();
});
afterAll(() => orm.close(true));
test('schema: adding 1:1 relation', async () => {
orm.getMetadata().reset('User');
await orm.discoverEntity(User2);
const diff1 = await orm.schema.getUpdateSchemaSQL();
expect(diff1).toMatchSnapshot();
await orm.schema.execute(diff1);
// sqlite does not support automatic down migrations
const diff2 = await orm.schema.getUpdateSchemaMigrationSQL();
expect(diff2.down).toBe('');
});
});