-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: delete position type inconnue #496
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
clock: yarn start:cron | ||
postdeploy: yarn typeorm:migration:run | ||
clock: yarn start:cron | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class DeletePositionInconnue1736244568004 implements MigrationInterface { | ||
name = 'DeletePositionInconnue1736244568004'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`UPDATE positions SET type = 'entrée' WHERE type = 'inconnue'`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TYPE "public"."positions_type_enum" RENAME TO "positions_type_enum_old"`, | ||
); | ||
await queryRunner.query( | ||
`CREATE TYPE "public"."positions_type_enum" AS ENUM('entrée', 'bâtiment', 'cage d’escalier', 'logement', 'service technique', 'délivrance postale', 'parcelle', 'segment')`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "positions" ALTER COLUMN "type" DROP DEFAULT`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "positions" ALTER COLUMN "type" TYPE "public"."positions_type_enum" USING "type"::"text"::"public"."positions_type_enum"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "positions" ALTER COLUMN "type" SET DEFAULT 'entrée'`, | ||
); | ||
await queryRunner.query(`DROP TYPE "public"."positions_type_enum_old"`); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`CREATE TYPE "public"."positions_type_enum_old" AS ENUM('entrée', 'bâtiment', 'cage d’escalier', 'logement', 'service technique', 'délivrance postale', 'parcelle', 'segment', 'inconnue')`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "positions" ALTER COLUMN "type" DROP DEFAULT`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "positions" ALTER COLUMN "type" TYPE "public"."positions_type_enum_old" USING "type"::"text"::"public"."positions_type_enum_old"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "positions" ALTER COLUMN "type" SET DEFAULT 'entrée'`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pour le down, il faudrait set le default à "inconnue" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ça me parait compliqué toutes ces manipulations de l'enum... Y'a pas juste moyen de supprimer / ajouter une valeur dans l'enum? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alors pour la première remarque, le type par DEFAULT est deja |
||
); | ||
await queryRunner.query(`DROP TYPE "public"."positions_type_enum"`); | ||
await queryRunner.query( | ||
`ALTER TYPE "public"."positions_type_enum_old" RENAME TO "positions_type_enum"`, | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On pourrait pas se servir d'une variable d'env pour lancer les migrations en mode auto ou non?
Je vois dans la doc de Scalingo qu'on peut faire ce genre de chose : https://doc.scalingo.com/platform/app/procfile
Le Procfile :
clock: yarn start:cron
postdeploy: bash bin/postdeploy.sh
et le script postdeploy.sh =>
#!/bin/bash
if [ "$LAUNCH_MIGRATION_AT_START" = "true" ] ; then
exec yarn typeorm:migration:run
fi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je suis pas très fan de la solution mais c'est peut être mieux que a l'heure actuelle