Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-db/scripts/generate-latest-migration.sh
2498 views
1
#!/bin/bash
2
# Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
# Licensed under the GNU Affero General Public License (AGPL).
4
# See License.AGPL.txt in the project root for license information.
5
6
get_latest_migration() {
7
# List all migrations and sort
8
migrations=$(find ./src/typeorm/migration/*.ts | sort -n | sed 's/\.\/src\/typeorm\/migration\///g' | sed 's/\.ts//g')
9
10
# Get the latest migration and format its name {ts}-{name} into {name}{ts}
11
# To align to the generated TypeORM class name which used as migration name
12
latest_migration=$(echo "$migrations" | tail -n 1 | sed 's/\([0-9]\{13\}\)-\(.*\)/\2\1/g')
13
14
# Echo the latest migration
15
echo "$latest_migration"
16
}
17
18
test() {
19
if [ -z "$(get_latest_migration)" ]; then
20
echo "Error: get_latest_migration() should not be empty" 1>&2;
21
exit 1
22
fi
23
}
24
25
if [ "$1" == "test" ]; then
26
test
27
else
28
get_latest_migration
29
fi
30
31