- Simplified the genre seeding process by replacing bulk save with individual insert queries, enhancing performance and error handling. - Removed unnecessary comments and streamlined the deletion process for genres, ensuring clarity in migration scripts. - Updated the `down` method to accurately restore deleted genres, maintaining data integrity during rollbacks.
42 lines
2.1 KiB
TypeScript
42 lines
2.1 KiB
TypeScript
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
|
|
export class SeedGenres1707420468655 implements MigrationInterface {
|
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
const genres = [
|
|
{ id: '3676ab4e-1b4f-4568-836a-43f84b1a6228', name: 'Action' },
|
|
{ id: '9d8be5ab-b956-4571-9b4e-1e25fb8b6e44', name: 'Adventure' },
|
|
{ id: 'b7bac6dd-2a86-4191-ac1e-c92be7b8b841', name: 'Comedy' },
|
|
{ id: 'e9e4285c-b6f3-46ef-a991-bd9f1537eae1', name: 'Crime' },
|
|
{ id: 'cc22046e-0b43-426c-9e70-b91ac6a601ba', name: 'Experimental' },
|
|
{ id: 'ed2515e3-da9a-4291-82bf-4ebe06831407', name: 'Western' },
|
|
{ id: '37306a11-e894-4e90-a200-87aabf67f70a', name: 'Historical' },
|
|
{ id: 'b20d0c86-b2d4-4fb0-8b39-dc855591fa24', name: 'Fiction' },
|
|
{ id: '8d7262a8-a94b-4f85-886a-a5ecff8844b3', name: 'Mystery' },
|
|
{ id: '51e56f26-bbb4-44e8-ac01-d7aa8ef81f3b', name: 'Documentary' },
|
|
{ id: '01854d65-636e-476b-9bbd-881c1834cdb0', name: 'Drama' },
|
|
{ id: '0bc7d835-ed31-4a6f-a76f-cfe26595eb11', name: 'Horror' },
|
|
{ id: '79a15574-5e83-4daf-8fdb-dd2261e12b60', name: 'Romance' },
|
|
{ id: '0029a12a-e9b9-421f-90c0-446c61afb4dd', name: 'Science Fiction' },
|
|
{ id: '004d484a-488e-478e-90f5-b37de3961527', name: 'Fantasy' },
|
|
{ id: '281857e3-0772-4d7d-b5a8-e460dde75b91', name: 'Thriller' },
|
|
{ id: '26703192-9875-456c-8bb6-6f7acaa8f0bf', name: 'Noir' },
|
|
{ id: 'f99f1239-2d6c-45e5-87ef-ea1df6a223dc', name: 'Musical' },
|
|
{ id: '62804361-7304-4de7-ae4a-bc3c742ec26b', name: 'War' },
|
|
{ id: '9568217b-affa-4859-a342-1ffeca0b7595', name: 'Sports' },
|
|
{ id: '21d8c163-88cc-414d-a381-78660065019d', name: 'Travel' },
|
|
{ id: '03342d8a-9fa0-4df1-9047-52c226b43b05', name: 'Biopic' },
|
|
];
|
|
|
|
for (const genre of genres) {
|
|
await queryRunner.query(
|
|
`INSERT INTO "genres" ("id", "name") VALUES ($1, $2) ON CONFLICT ("id") DO NOTHING`,
|
|
[genre.id, genre.name],
|
|
);
|
|
}
|
|
}
|
|
|
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
await queryRunner.query(`DELETE FROM "genres"`);
|
|
}
|
|
}
|