Skip to content

Commit ee5068d

Browse files
committed
Python/Ruby: forward to generic prepare-db-upgrade.sh
1 parent 3170670 commit ee5068d

File tree

3 files changed

+10
-330
lines changed

3 files changed

+10
-330
lines changed

python/tools/prepare-db-downgrade.sh

Lines changed: 0 additions & 107 deletions
This file was deleted.

python/tools/prepare-db-upgrade.sh

Lines changed: 5 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,8 @@
11
#!/bin/sh
22
#
3-
# Prepare the upgrade script directory for a Python database schema upgrade.
3+
# Prepare the upgrade script directory for a Python database schema upgrade. Now
4+
# just forwards to the language-independent script.
45

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/semmlecode.python.dbscheme"
65-
upgrade_root="ql/upgrades"
66-
67-
check_hash_valid()
68-
{
69-
if [ ${#2} -ne 40 ]; then
70-
echo "Did not get expected $1 hash: $2" >&2
71-
exit 2
72-
fi
73-
}
74-
75-
# Get the hash of the previous and current DB Schema files
76-
prev_hash="$(git show "${prev_hash}:python/${scheme_file}" | git hash-object --stdin)"
77-
check_hash_valid previous "${prev_hash}"
78-
current_hash="$(git hash-object "${scheme_file}")"
79-
check_hash_valid current "${current_hash}"
80-
if [ "${current_hash}" = "${prev_hash}" ]; then
81-
echo "No work to be done."
82-
exit
83-
fi
84-
85-
# Copy current and new dbscheme into the upgrade dir
86-
upgradedir="${upgrade_root}/${prev_hash}"
87-
mkdir -p "${upgradedir}"
88-
89-
cp "${scheme_file}" "${upgradedir}"
90-
git cat-file blob "${prev_hash}" > "${upgradedir}/old.dbscheme"
91-
92-
# Create the template upgrade.properties file.
93-
cat <<EOF > "${upgradedir}/upgrade.properties"
94-
description: <INSERT DESCRIPTION HERE>
95-
compatibility: full|backwards|partial|breaking
96-
EOF
97-
98-
# Tell user what we've done
99-
cat <<EOF
100-
Created upgrade directory here:
101-
${upgradedir}
102-
103-
Please update:
104-
${upgradedir}/upgrade.properties
105-
with appropriate upgrade instructions
106-
EOF
6+
set -eu
7+
app_dir="$(dirname "$0")"
8+
"${app_dir}/../../misc/scripts/prepare-db-upgrade.sh" --lang python "$@"

ruby/scripts/prepare-db-upgrade.sh

Lines changed: 5 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,8 @@
11
#!/bin/sh
22
#
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.
45

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

Comments
 (0)