Fix entity-based migrations that crash on missing columns
MusicVideosUpdate and AddEpisodicGenres migrations used TypeORM entity classes which reference columns that don't exist at their migration timestamp (e.g. trailer_old, later entity fields). Rewrote both to use raw SQL INSERT/UPDATE statements. Also bumped CACHEBUST to v3 to force backend image rebuild. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,32 +1,17 @@
|
||||
/* eslint-disable unicorn/no-array-method-this-argument */
|
||||
import { Project } from 'src/projects/entities/project.entity';
|
||||
import { Category } from 'src/projects/enums/category.enum';
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class MusicVideosUpdate1729096262567 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
// update all projects that have category music-video to have the category narrative and type music-video
|
||||
const projects = await queryRunner.manager.find(Project, {
|
||||
where: { category: 'music-video' as Category },
|
||||
});
|
||||
const updatedProjects = projects.map((project) => {
|
||||
project.category = 'narrative';
|
||||
project.type = 'music-video';
|
||||
return project;
|
||||
});
|
||||
await queryRunner.manager.save(updatedProjects);
|
||||
// Update all projects with category 'music-video' to category 'narrative' + type 'music-video'
|
||||
await queryRunner.query(
|
||||
`UPDATE "projects" SET "category" = 'narrative', "type" = 'music-video' WHERE "category" = 'music-video' AND "deleted_at" IS NULL`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
// update all projects that have category narrative and type music-video to have the category music-video
|
||||
const projects = await queryRunner.manager.find(Project, {
|
||||
where: { category: 'narrative' as Category, type: 'music-video' },
|
||||
});
|
||||
const updatedProjects = projects.map((project) => {
|
||||
project.category = 'music-video' as Category;
|
||||
project.type = 'film';
|
||||
return project;
|
||||
});
|
||||
await queryRunner.manager.save(updatedProjects);
|
||||
// Revert: projects with category 'narrative' and type 'music-video' back to category 'music-video', type 'film'
|
||||
await queryRunner.query(
|
||||
`UPDATE "projects" SET "category" = 'music-video', "type" = 'film' WHERE "category" = 'narrative' AND "type" = 'music-video' AND "deleted_at" IS NULL`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user