Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(schema): do not inherit schema for FKs if not a wildcard entity
Closes #4918
- Loading branch information
Showing
5 changed files
with
80 additions
and
5 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
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,43 @@ | ||
import { MikroORM } from '@mikro-orm/postgresql'; | ||
import { Entity, ManyToOne, PrimaryKey, Rel } from '@mikro-orm/core'; | ||
|
||
@Entity() | ||
class Two { | ||
|
||
@PrimaryKey() | ||
id!: string; | ||
|
||
@ManyToOne(() => One, { deleteRule: 'cascade' }) | ||
one!: Rel<One>; | ||
|
||
} | ||
|
||
@Entity({ schema: 'test' }) | ||
class One { | ||
|
||
@PrimaryKey() | ||
id!: string; | ||
|
||
@ManyToOne(() => Two, { deleteRule: 'cascade' }) | ||
two!: Two; | ||
|
||
} | ||
|
||
let orm: MikroORM; | ||
|
||
beforeAll(async () => { | ||
orm = await MikroORM.init({ | ||
entities: [One], | ||
dbName: '4918', | ||
}); | ||
await orm.schema.ensureDatabase(); | ||
await orm.schema.dropSchema(); | ||
}); | ||
|
||
afterAll(() => orm.close(true)); | ||
|
||
test('GH #4918', async () => { | ||
const sql = await orm.schema.getCreateSchemaSQL(); | ||
expect(sql).toMatchSnapshot(); | ||
await orm.schema.execute(sql); | ||
}); |
19 changes: 19 additions & 0 deletions
19
tests/features/schema-generator/__snapshots__/GH4918.test.ts.snap
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,19 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`GH #4918 1`] = ` | ||
"set names 'utf8'; | ||
set session_replication_role = 'replica'; | ||
create schema if not exists "test"; | ||
create table "two" ("id" varchar(255) not null, "one_id" varchar(255) not null, constraint "two_pkey" primary key ("id")); | ||
create table "test"."one" ("id" varchar(255) not null, "two_id" varchar(255) not null, constraint "one_pkey" primary key ("id")); | ||
alter table "two" add constraint "two_one_id_foreign" foreign key ("one_id") references "test"."one" ("id") on update cascade on delete cascade; | ||
alter table "test"."one" add constraint "one_two_id_foreign" foreign key ("two_id") references "two" ("id") on update cascade on delete cascade; | ||
set session_replication_role = 'origin'; | ||
" | ||
`; |