-
-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sqlite): respect
autoincrement: false
in schema diffing
Closes #2800
- Loading branch information
Showing
4 changed files
with
118 additions
and
2 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
7 changes: 7 additions & 0 deletions
7
tests/features/schema-generator/__snapshots__/fk-diffing.sqlite.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,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`dropping tables with FKs in postgres schema generator removes stale FKs on target table dropping 1 1`] = ` | ||
"alter table \`sequence\` add column \`another_property\` text null; | ||
" | ||
`; |
101 changes: 101 additions & 0 deletions
101
tests/features/schema-generator/fk-diffing.sqlite.test.ts
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,101 @@ | ||
import { Entity, ManyToOne, MikroORM, PrimaryKey, Property } from '@mikro-orm/core'; | ||
|
||
@Entity() | ||
export class Door { | ||
|
||
@PrimaryKey({ autoincrement: false }) | ||
id!: number; | ||
|
||
@Property() | ||
label!: string; | ||
|
||
@Property({ default: true }) | ||
isEnabled!: boolean; | ||
|
||
@Property() | ||
state!: 'open' | 'closed'; | ||
|
||
} | ||
|
||
@Entity({ tableName: 'sequence' }) | ||
export class Sequence0 { | ||
|
||
@PrimaryKey() | ||
id!: number; | ||
|
||
@Property() | ||
index!: number; | ||
|
||
@Property() | ||
action!: 'on' | 'off' | 'low' | 'high'; | ||
|
||
@Property() | ||
target!: | ||
| 'relay1' | ||
| 'relay2' | ||
| 'relay3' | ||
| 'digitalOutput1' | ||
| 'digitalOutput2' | ||
| 'digitalOutput3'; | ||
|
||
@Property() | ||
duration!: number; | ||
|
||
@ManyToOne(() => Door) | ||
door!: Door; | ||
|
||
} | ||
|
||
@Entity({ tableName: 'sequence' }) | ||
export class Sequence1 { | ||
|
||
@PrimaryKey() | ||
id!: number; | ||
|
||
@Property() | ||
index!: number; | ||
|
||
@Property() | ||
action!: 'on' | 'off' | 'low' | 'high'; | ||
|
||
@Property({ nullable: true }) | ||
anotherProperty?: string; | ||
|
||
@Property() | ||
target!: | ||
| 'relay1' | ||
| 'relay2' | ||
| 'relay3' | ||
| 'digitalOutput1' | ||
| 'digitalOutput2' | ||
| 'digitalOutput3'; | ||
|
||
@Property() | ||
duration!: number; | ||
|
||
@ManyToOne(() => Door) | ||
door!: Door; | ||
|
||
} | ||
|
||
describe('dropping tables with FKs in postgres', () => { | ||
|
||
test('schema generator removes stale FKs on target table dropping 1', async () => { | ||
const orm = await MikroORM.init({ | ||
entities: [Sequence0, Door], | ||
dbName: `:memory:`, | ||
type: 'better-sqlite', | ||
cache: { enabled: false }, | ||
}); | ||
await orm.getSchemaGenerator().refreshDatabase(); | ||
|
||
orm.getMetadata().reset('Sequence0'); | ||
await orm.discoverEntity([Sequence1]); | ||
const diff1 = await orm.getSchemaGenerator().getUpdateSchemaSQL({ wrap: false }); | ||
expect(diff1).toMatchSnapshot(); | ||
await orm.getSchemaGenerator().execute(diff1); | ||
|
||
await orm.close(true); | ||
}); | ||
|
||
}); |