-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hasSport, hasBoulder, hasMultipitch fields to crag.
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/migration/1708077643082-addHasSportHasBoulderHasMultipitchToCrag.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"`); | ||
} | ||
} |