Skip to content

Commit

Permalink
Make owner field of Program nullable (#1296)
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit authored May 31, 2023
1 parent ce5eeb6 commit ade2717
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion idea/indexer/src/database/entities/program.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class Program extends BaseEntity implements IProgram {
public id: string;

@Index()
@Column()
@Column({ nullable: true })
public owner: string;

@Column()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class nullableOwner1685519228764 implements MigrationInterface {
name = 'nullableOwner1685519228764'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE "program"
ALTER COLUMN "owner" DROP NOT NULL
`);
await queryRunner.query(`
ALTER TYPE "public"."program_type_enum"
RENAME TO "program_type_enum_old"
`);
await queryRunner.query(`
CREATE TYPE "public"."program_type_enum" AS ENUM(
'unknown',
'programSet',
'active',
'terminated',
'exited',
'paused'
)
`);
await queryRunner.query(`
ALTER TABLE "program"
ALTER COLUMN "type" DROP DEFAULT
`);
await queryRunner.query(`
ALTER TABLE "program"
ALTER COLUMN "type" TYPE "public"."program_type_enum" USING "type"::"text"::"public"."program_type_enum"
`);
await queryRunner.query(`
ALTER TABLE "program"
ALTER COLUMN "type"
SET DEFAULT 'unknown'
`);
await queryRunner.query(`
DROP TYPE "public"."program_type_enum_old"
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
CREATE TYPE "public"."program_type_enum_old" AS ENUM(
'unknown',
'active',
'terminated',
'exited',
'paused'
)
`);
await queryRunner.query(`
ALTER TABLE "program"
ALTER COLUMN "type" DROP DEFAULT
`);
await queryRunner.query(`
ALTER TABLE "program"
ALTER COLUMN "type" TYPE "public"."program_type_enum_old" USING "type"::"text"::"public"."program_type_enum_old"
`);
await queryRunner.query(`
ALTER TABLE "program"
ALTER COLUMN "type"
SET DEFAULT 'unknown'
`);
await queryRunner.query(`
DROP TYPE "public"."program_type_enum"
`);
await queryRunner.query(`
ALTER TYPE "public"."program_type_enum_old"
RENAME TO "program_type_enum"
`);
await queryRunner.query(`
ALTER TABLE "program"
ALTER COLUMN "owner"
SET NOT NULL
`);
}

}

0 comments on commit ade2717

Please sign in to comment.