Skip to content

Automatic migrations are causing issues when running our app on an ECS cluster in AWS #3400

@johndenverscar

Description

@johndenverscar

Issue type:

[X] question
[ ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[X] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[X] latest
[ ] @next
[ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

I have inherited an application running an Express service that uses TypeORM.
On app startup, the migrations are automatically run, which, for the most part, doesn't cause an issue.
However, I have a rather large migration that inserts a bunch of data and takes about 5 minutes to run.
When deploying changes to the application, it's deployed to 3 or more containers at the same time using a CICD tool and pipeline that I'm not allowed to change.
When all of the applications start up, the long-running migration causes a race condition where all three try to run the migration at the same time, causing duplicate date to be inserted into the DB.

Things I can't change:

  1. The number of instances we deploy to at once. This has to be 3 or more at a single time.
  2. The timing of the deployments. All containers have to be deployed simultaneously.

Is there a way I can use TypeORM such that only one of these app containers tries to run the migrations? Or do I need to write my migrations so that they are entirely idempotent?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions