Skip to content

Commit

Permalink
Add hasSport, hasBoulder, hasMultipitch fields to crag.
Browse files Browse the repository at this point in the history
  • Loading branch information
salamca committed Feb 16, 2024
1 parent 642fa1e commit 62272c1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/crags/entities/crag.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,16 @@ export class Crag extends BaseEntity {
@Column({ type: 'jsonb', nullable: true })
@Field((type) => GraphQLJSON, { nullable: true })
nrRoutesByGrade: JSON;

@Column({ default: false })
@Field()
hasSport: boolean;

@Column({ default: false })
@Field()
hasBoulder: boolean;

@Column({ default: false })
@Field()
hasMultipitch: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

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

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "crag" ADD "has_sport" boolean NOT NULL DEFAULT false`,
);

await queryRunner.query(
`ALTER TABLE "crag" ADD "has_boulder" boolean NOT NULL DEFAULT false`,
);
await queryRunner.query(
`ALTER TABLE "crag" ADD "has_multipitch" boolean NOT NULL DEFAULT false`,
);

const crags = await queryRunner.query(
`SELECT c.id, r.route_type_id FROM crag c
INNER JOIN route r on r.crag_id = c.id
GROUP BY r.route_type_id, c.id`,
);

for (const crag of crags) {
if (['sport', 'boulder', 'multipitch'].includes(crag.route_type_id)) {
await queryRunner.query(
`UPDATE crag SET has_${crag.route_type_id} = true WHERE id = '${crag.id}'`,
);
}
}
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "crag" DROP COLUMN "has_multipitch"`);
await queryRunner.query(`ALTER TABLE "crag" DROP COLUMN "has_boulder"`);
await queryRunner.query(`ALTER TABLE "crag" DROP COLUMN "has_sport"`);
}
}

0 comments on commit 62272c1

Please sign in to comment.