fix: ensure requests are not disassociated with media

This commit is contained in:
dr-carrot
2024-01-27 19:58:58 -05:00
committed by GitHub
2 changed files with 6 additions and 33 deletions

View File

@@ -1108,32 +1108,12 @@ export class MediaRequest {
sonarr
.addSeries(sonarrSeriesOptions)
.then(async (sonarrSeries) => {
const reqCheck1 = await getRepository(MediaRequest).find({
where: { media: { id: this.media.id } },
});
logger.debug(
`Before running the find the DB claims we have ${
reqCheck1?.length ?? 0
} relations`
);
// We grab media again here to make sure we have the latest version of it
const media = await mediaRepository.findOne({
where: { id: this.media.id },
relations: { requests: true },
});
logger.debug(
`Typeorm claims ${
media?.requests?.length ?? 0
} relations are loaded`
);
const reqCheck = await getRepository(MediaRequest).find({
where: { media: { id: this.media.id } },
});
logger.debug(
`The DB claims we have ${reqCheck?.length ?? 0} relations`
);
if (!media) {
throw new Error('Media data not found');
}
@@ -1143,15 +1123,8 @@ export class MediaRequest {
media[this.is4k ? 'externalServiceSlug4k' : 'externalServiceSlug'] =
sonarrSeries.titleSlug;
media[this.is4k ? 'serviceId4k' : 'serviceId'] = sonarrSettings?.id;
await mediaRepository.save(media);
const reqCheck3 = await getRepository(MediaRequest).find({
where: { media: { id: this.media.id } },
});
logger.debug(
`After save, the DB claims we have ${
reqCheck3?.length ?? 0
} relations`
);
})
.catch(async () => {
const requestRepository = getRepository(MediaRequest);

View File

@@ -56,7 +56,7 @@ export class InitialMigration1705599190375 implements MigrationInterface {
status int default '1'::int,
"createdAt" timestamp with time zone default CURRENT_TIMESTAMP,
"updatedAt" timestamp with time zone default CURRENT_TIMESTAMP,
"mediaId" int,
"mediaId" int not null,
status4k int default '1'::int,
constraint idx_194715_season_pkey
primary key (id),
@@ -141,7 +141,7 @@ export class InitialMigration1705599190375 implements MigrationInterface {
"problemEpisode" int default '0'::int,
"createdAt" timestamp with time zone default CURRENT_TIMESTAMP,
"updatedAt" timestamp with time zone default CURRENT_TIMESTAMP,
"mediaId" int,
"mediaId" int not null,
"createdById" int,
"modifiedById" int,
constraint idx_194747_issue_pkey
@@ -208,7 +208,7 @@ export class InitialMigration1705599190375 implements MigrationInterface {
"createdAt" timestamp with time zone default CURRENT_TIMESTAMP,
"updatedAt" timestamp with time zone default CURRENT_TIMESTAMP,
type text,
"mediaId" int,
"mediaId" int not null,
"requestedById" int,
"modifiedById" int,
is4k boolean default false,
@@ -231,7 +231,7 @@ export class InitialMigration1705599190375 implements MigrationInterface {
await queryRunner.query(
`create table if not exists season_request
(
id serial,
id serial NOT NULL,
"seasonNumber" int,
status int default '1'::int,
"createdAt" timestamp with time zone default now(),
@@ -270,7 +270,7 @@ export class InitialMigration1705599190375 implements MigrationInterface {
"createdAt" timestamp with time zone default CURRENT_TIMESTAMP,
"updatedAt" timestamp with time zone default CURRENT_TIMESTAMP,
"requestedById" int,
"mediaId" int,
"mediaId" int not null,
constraint idx_194788_watchlist_pkey
primary key (id)
);`