mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Add database fixtures for testing migrations (#4858)
This commit is contained in:
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Naming the fixture is optional, if missing, the name of the latest
|
||||
# migration will be used.
|
||||
#
|
||||
# Usage:
|
||||
# ./create_fixture
|
||||
# ./create_fixture name of fixture
|
||||
# ./create_fixture "name of fixture"
|
||||
# ./create_fixture name_of_fixture
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
|
||||
(
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
latest_migration=$(basename "$(find . -maxdepth 1 -name "*.up.sql" | sort -n | tail -n 1)")
|
||||
if [[ -n "${*}" ]]; then
|
||||
name=$*
|
||||
name=${name// /_}
|
||||
num=${latest_migration%%_*}
|
||||
latest_migration="${num}_${name}.up.sql"
|
||||
fi
|
||||
|
||||
filename="$(pwd)/testdata/fixtures/$latest_migration"
|
||||
touch "$filename"
|
||||
echo "$filename"
|
||||
echo "Edit fixture and commit it."
|
||||
)
|
||||
Reference in New Issue
Block a user