Path: blob/main/components/gitpod-db/scripts/generate-latest-migration.sh
2498 views
#!/bin/bash1# Copyright (c) 2023 Gitpod GmbH. All rights reserved.2# Licensed under the GNU Affero General Public License (AGPL).3# See License.AGPL.txt in the project root for license information.45get_latest_migration() {6# List all migrations and sort7migrations=$(find ./src/typeorm/migration/*.ts | sort -n | sed 's/\.\/src\/typeorm\/migration\///g' | sed 's/\.ts//g')89# Get the latest migration and format its name {ts}-{name} into {name}{ts}10# To align to the generated TypeORM class name which used as migration name11latest_migration=$(echo "$migrations" | tail -n 1 | sed 's/\([0-9]\{13\}\)-\(.*\)/\2\1/g')1213# Echo the latest migration14echo "$latest_migration"15}1617test() {18if [ -z "$(get_latest_migration)" ]; then19echo "Error: get_latest_migration() should not be empty" 1>&2;20exit 121fi22}2324if [ "$1" == "test" ]; then25test26else27get_latest_migration28fi293031