Skip to content

Commit

Permalink
fix: remove non-null requirement for some fields (#1175)
Browse files Browse the repository at this point in the history
PR #628 changed some fields to disallow null values, causing issues with some older SQLite database
having null values. This PR reverts this change.
  • Loading branch information
gauthier-th authored Dec 22, 2024
1 parent 59b7859 commit 13d15d1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 382 deletions.
1 change: 0 additions & 1 deletion server/entity/MediaRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ export class MediaRequest {
@ManyToOne(() => Media, (media) => media.requests, {
eager: true,
onDelete: 'CASCADE',
nullable: false,
})
public media: Media;

Expand Down
1 change: 0 additions & 1 deletion server/entity/Season.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Season {

@ManyToOne(() => Media, (media) => media.seasons, {
onDelete: 'CASCADE',
nullable: false,
})
public media: Promise<Media>;

Expand Down
1 change: 0 additions & 1 deletion server/entity/Watchlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export class Watchlist implements WatchlistItem {
@ManyToOne(() => Media, (media) => media.watchlists, {
eager: true,
onDelete: 'CASCADE',
nullable: false,
})
public media: Media;

Expand Down
65 changes: 65 additions & 0 deletions server/migration/postgres/1734809898562-FixNullFields.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import type { MigrationInterface, QueryRunner } from 'typeorm';

export class FixNullFields1734809898562 implements MigrationInterface {
name = 'FixNullFields1734809898562';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "watchlist" DROP CONSTRAINT "FK_6641da8d831b93dfcb429f8b8bc"`
);
await queryRunner.query(
`ALTER TABLE "watchlist" ALTER COLUMN "mediaId" DROP NOT NULL`
);
await queryRunner.query(
`ALTER TABLE "media_request" DROP CONSTRAINT "FK_a1aa713f41c99e9d10c48da75a0"`
);
await queryRunner.query(
`ALTER TABLE "media_request" ALTER COLUMN "mediaId" DROP NOT NULL`
);
await queryRunner.query(
`ALTER TABLE "season" DROP CONSTRAINT "FK_087099b39600be695591da9a49c"`
);
await queryRunner.query(
`ALTER TABLE "season" ALTER COLUMN "mediaId" DROP NOT NULL`
);
await queryRunner.query(
`ALTER TABLE "watchlist" ADD CONSTRAINT "FK_6641da8d831b93dfcb429f8b8bc" FOREIGN KEY ("mediaId") REFERENCES "media"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
);
await queryRunner.query(
`ALTER TABLE "media_request" ADD CONSTRAINT "FK_a1aa713f41c99e9d10c48da75a0" FOREIGN KEY ("mediaId") REFERENCES "media"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
);
await queryRunner.query(
`ALTER TABLE "season" ADD CONSTRAINT "FK_087099b39600be695591da9a49c" FOREIGN KEY ("mediaId") REFERENCES "media"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "season" DROP CONSTRAINT "FK_087099b39600be695591da9a49c"`
);
await queryRunner.query(
`ALTER TABLE "media_request" DROP CONSTRAINT "FK_a1aa713f41c99e9d10c48da75a0"`
);
await queryRunner.query(
`ALTER TABLE "watchlist" DROP CONSTRAINT "FK_6641da8d831b93dfcb429f8b8bc"`
);
await queryRunner.query(
`ALTER TABLE "season" ALTER COLUMN "mediaId" SET NOT NULL`
);
await queryRunner.query(
`ALTER TABLE "season" ADD CONSTRAINT "FK_087099b39600be695591da9a49c" FOREIGN KEY ("mediaId") REFERENCES "media"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
);
await queryRunner.query(
`ALTER TABLE "media_request" ALTER COLUMN "mediaId" SET NOT NULL`
);
await queryRunner.query(
`ALTER TABLE "media_request" ADD CONSTRAINT "FK_a1aa713f41c99e9d10c48da75a0" FOREIGN KEY ("mediaId") REFERENCES "media"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
);
await queryRunner.query(
`ALTER TABLE "watchlist" ALTER COLUMN "mediaId" SET NOT NULL`
);
await queryRunner.query(
`ALTER TABLE "watchlist" ADD CONSTRAINT "FK_6641da8d831b93dfcb429f8b8bc" FOREIGN KEY ("mediaId") REFERENCES "media"("id") ON DELETE CASCADE ON UPDATE NO ACTION`
);
}
}
Loading

0 comments on commit 13d15d1

Please sign in to comment.