|
1 | 1 | #!/bin/sh |
2 | 2 | # |
3 | | -# Prepare the upgrade script directory for a Ruby database schema upgrade. |
| 3 | +# Prepare the upgrade script directory for a Ruby database schema upgrade. Now |
| 4 | +# just forwards to the language-independent script. |
4 | 5 |
|
5 | | -set -e |
6 | | -set -u |
7 | | - |
8 | | -app_name="$(basename "$0")" |
9 | | - |
10 | | -usage() |
11 | | -{ |
12 | | - exit_code="$1" |
13 | | - shift |
14 | | - |
15 | | - cat >&2 <<EOF |
16 | | -${app_name}: $@ |
17 | | -${app_name}: Generate skeleton upgrade script. |
18 | | -Usage: ${app_name} [--prev_hash <COMMITISH>]" |
19 | | -
|
20 | | ---prev-hash <COMMITISH> |
21 | | - Hash/branch to use to get SHA1 for previous DB scheme. |
22 | | - Default: origin/main |
23 | | -
|
24 | | -Must be run within the git repo needing an update. |
25 | | -EOF |
26 | | - exit "${exit_code}" |
27 | | -} |
28 | | - |
29 | | -prev_hash="origin/main" |
30 | | - |
31 | | -while [ $# -gt 0 ]; do |
32 | | - case "$1" in |
33 | | - -x) |
34 | | - set -x |
35 | | - ;; |
36 | | - -h | --help) |
37 | | - usage 0 |
38 | | - ;; |
39 | | - --prev-hash) |
40 | | - if [ $# -eq 1 ]; then |
41 | | - usage 2 "--prev-hash requires Commit/Branch option" |
42 | | - fi |
43 | | - shift |
44 | | - prev_hash="$1" |
45 | | - ;; |
46 | | - --) |
47 | | - shift |
48 | | - break |
49 | | - ;; |
50 | | - -*) |
51 | | - usage 2 "Unrecognised option: $1" |
52 | | - ;; |
53 | | - *) |
54 | | - break |
55 | | - ;; |
56 | | - esac |
57 | | - shift |
58 | | -done |
59 | | - |
60 | | -if [ $# -gt 0 ]; then |
61 | | - usage 2 "Unrecognised operand: $1" |
62 | | -fi |
63 | | - |
64 | | -scheme_file="ql/lib/ruby.dbscheme" |
65 | | -upgrade_root="ql/lib/upgrades" |
66 | | -downgrade_root="downgrades" |
67 | | - |
68 | | -check_hash_valid() |
69 | | -{ |
70 | | - if [ ${#2} -ne 40 ]; then |
71 | | - echo "Did not get expected $1 hash: $2" >&2 |
72 | | - exit 2 |
73 | | - fi |
74 | | -} |
75 | | - |
76 | | -# Get the hash of the previous and current DB Schema files |
77 | | -prev_hash="$(git show "${prev_hash}:ruby/${scheme_file}" | git hash-object --stdin)" |
78 | | -check_hash_valid previous "${prev_hash}" |
79 | | -current_hash="$(git hash-object "${scheme_file}")" |
80 | | -check_hash_valid current "${current_hash}" |
81 | | -if [ "${current_hash}" = "${prev_hash}" ]; then |
82 | | - echo "No work to be done." |
83 | | - exit |
84 | | -fi |
85 | | - |
86 | | -# Copy current and new dbscheme into the upgrade dir |
87 | | -upgradedir="${upgrade_root}/${prev_hash}" |
88 | | -mkdir -p "${upgradedir}" |
89 | | - |
90 | | -cp "${scheme_file}" "${upgradedir}" |
91 | | -git cat-file blob "${prev_hash}" > "${upgradedir}/old.dbscheme" |
92 | | - |
93 | | -# Create the template upgrade.properties file. |
94 | | -cat <<EOF > "${upgradedir}/upgrade.properties" |
95 | | -description: <INSERT DESCRIPTION HERE> |
96 | | -compatibility: full|backwards|partial|breaking |
97 | | -EOF |
98 | | - |
99 | | -# Copy current and new dbscheme into the downgrade dir |
100 | | -downgradedir="${downgrade_root}/${current_hash}" |
101 | | -mkdir -p "${downgradedir}" |
102 | | - |
103 | | -cp "${scheme_file}" "${downgradedir}/old.dbscheme" |
104 | | -git cat-file blob "${prev_hash}" > "${downgradedir}/$(basename "${scheme_file}")" |
105 | | - |
106 | | -# Create the template upgrade.properties file. |
107 | | -cat <<EOF > "${downgradedir}/upgrade.properties" |
108 | | -description: <INSERT DESCRIPTION HERE> |
109 | | -compatibility: full|backwards|partial|breaking |
110 | | -EOF |
111 | | - |
112 | | -# Tell user what we've done |
113 | | -cat <<EOF |
114 | | -Created upgrade directory here: |
115 | | - ${upgradedir} |
116 | | -Created downgrade directory here: |
117 | | - ${downgradedir} |
118 | | -
|
119 | | -Please update: |
120 | | - ${upgradedir}/upgrade.properties |
121 | | - ${downgradedir}/upgrade.properties |
122 | | -with appropriate instructions |
123 | | -EOF |
| 6 | +set -eu |
| 7 | +app_dir="$(dirname "$0")" |
| 8 | +"${app_dir}/../../misc/scripts/prepare-db-upgrade.sh" --lang ruby "$@" |
0 commit comments