diff --git a/db/migration/1706317870929-DatasetsFieldNameMandatory.ts b/db/migration/1706317870929-DatasetsFieldNameMandatory.ts new file mode 100644 index 00000000000..b74487d6396 --- /dev/null +++ b/db/migration/1706317870929-DatasetsFieldNameMandatory.ts @@ -0,0 +1,19 @@ +import { MigrationInterface, QueryRunner } from "typeorm" + +export class DatasetsFieldNameMandatory1706317870929 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + // The name field is nullable in the DB schema but null is never used in the values in the DB, + // so it's better to make it mandatory in the DB schema. + await queryRunner.query( + `ALTER TABLE datasets MODIFY COLUMN name VARCHAR(512) NOT NULL` + ) + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE datasets MODIFY COLUMN name VARCHAR(512)` + ) + } +} diff --git a/packages/@ourworldindata/types/src/dbTypes/Datasets.ts b/packages/@ourworldindata/types/src/dbTypes/Datasets.ts index 4bb4c01579d..eb2121a8d26 100644 --- a/packages/@ourworldindata/types/src/dbTypes/Datasets.ts +++ b/packages/@ourworldindata/types/src/dbTypes/Datasets.ts @@ -10,7 +10,7 @@ export interface DbInsertDataset { isPrivate?: number metadataEditedAt: Date metadataEditedByUserId: number - name?: string | null + name: string namespace: string nonRedistributable?: number shortName?: string | null