-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new migration strategy for updating DB. Add 'test' migration on n…
…ew join table for custom shows (#3)
- Loading branch information
1 parent
6d2bbf1
commit 70527b4
Showing
6 changed files
with
97 additions
and
35 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,35 @@ | ||
import { | ||
Entity, | ||
ManyToOne, | ||
PrimaryKeyProp, | ||
Property, | ||
Rel, | ||
Unique, | ||
} from '@mikro-orm/core'; | ||
import { CustomShow } from './CustomShow.js'; | ||
import { Program } from './Program.js'; | ||
|
||
@Entity() | ||
@Unique({ properties: ['customShow', 'content', 'index'] }) | ||
export class CustomShowContent { | ||
@ManyToOne({ primary: true, entity: () => CustomShow }) | ||
customShow!: Rel<CustomShow>; | ||
|
||
@ManyToOne({ primary: true, entity: () => Program }) | ||
content!: Rel<Program>; | ||
|
||
@Property() | ||
index!: number; | ||
|
||
[PrimaryKeyProp]?: ['customShow', 'content']; | ||
|
||
constructor( | ||
customShow: Rel<CustomShow>, | ||
content: Rel<Program>, | ||
index: number, | ||
) { | ||
this.customShow = customShow; | ||
this.content = content; | ||
this.index = index; | ||
} | ||
} |
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,14 @@ | ||
import { Migration } from '@mikro-orm/migrations'; | ||
|
||
export class Migration20240119164121 extends Migration { | ||
|
||
async up(): Promise<void> { | ||
this.addSql('drop index `custom_show_content_program_uuid_index`;'); | ||
|
||
this.addSql('alter table `custom_show_content` add column `index` integer not null constraint `custom_show_content_content_uuid_foreign` references `program` (`uuid`) on update cascade constraint `custom_show_content_custom_show_uuid_foreign` references `custom_show` (`uuid`) on update cascade;'); | ||
this.addSql('alter table `custom_show_content` rename column `program_uuid` to `content_uuid`;'); | ||
this.addSql('create index `custom_show_content_content_uuid_index` on `custom_show_content` (`content_uuid`);'); | ||
this.addSql('create unique index `custom_show_content_custom_show_uuid_content_uuid_index_unique` on `custom_show_content` (`custom_show_uuid`, `content_uuid`, `index`);'); | ||
} | ||
|
||
} |