Skip to content

Commit 5565159

Browse files
committed
Add create_fixture.sh
1 parent 86cd5ec commit 5565159

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
# Naming the fixture is optional, if missing, the name of the latest
4+
# migration will be used.
5+
#
6+
# Usage:
7+
# ./create_fixture
8+
# ./create_fixture name of fixture
9+
# ./create_fixture "name of fixture"
10+
# ./create_fixture name_of_fixture
11+
12+
set -euo pipefail
13+
14+
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
15+
(
16+
cd "$SCRIPT_DIR"
17+
18+
# if migration name is an empty string exit
19+
[[ -z "${*}" ]] && (echo "Must provide a fixture name" && exit 1)
20+
21+
latest_migration=$(basename "$(find . -maxdepth 1 -name "*.up.sql" | sort -n | tail -n 1)")
22+
if [[ -n "${*}" ]]; then
23+
name=$*
24+
name=${name// /_}
25+
num=${latest_migration%%_*}
26+
latest_migration="${num}_${name}.up.sql"
27+
fi
28+
29+
filename="$(pwd)/testdata/fixtures/$latest_migration"
30+
touch "$filename"
31+
echo "$filename"
32+
echo "Edit fixture and commit it."
33+
)

0 commit comments

Comments
 (0)