gitpod/components/gitpod-db/scripts/generate-latest-migration.sh
Huiwen 700b6050ba
Make db waiter to wait latest migration (#18455)
* Make db waiter to wait latest migration

* Move generate out of build

* Remove conn require

* Allow to ignore migration check

* Use shell

* Use fail and remote useless log

* Generate service-waiter txt when create migration

* Revert "Generate service-waiter txt when create migration"

This reverts commit 11c12b83544a448f9784f8aa94cdfd69cfb15f45.

* Add log
2023-08-10 13:51:36 +02:00

30 lines
923 B
Bash
Executable File

#!/bin/bash
# Copyright (c) 2023 Gitpod GmbH. All rights reserved.
# Licensed under the GNU Affero General Public License (AGPL).
# See License.AGPL.txt in the project root for license information.
get_latest_migration() {
# List all migrations and sort
migrations=$(find ./src/typeorm/migration/*.ts | sort -n | sed 's/\.\/src\/typeorm\/migration\///g' | sed 's/\.ts//g')
# Get the latest migration and format its name {ts}-{name} into {name}{ts}
# To align to the generated TypeORM class name which used as migration name
latest_migration=$(echo "$migrations" | tail -n 1 | sed 's/\([0-9]\{13\}\)-\(.*\)/\2\1/g')
# Echo the latest migration
echo "$latest_migration"
}
test() {
if [ -z "$(get_latest_migration)" ]; then
echo "Error: get_latest_migration() should not be empty" 1>&2;
exit 1
fi
}
if [ "$1" == "test" ]; then
test
else
get_latest_migration
fi