8000 feat: Add database fixtures for testing migrations by mafredri · Pull Request #4858 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: Add database fixtures for testing migrations #4858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Nov 8, 2022
Prev Previous commit
Next Next commit
Add create_fixture.sh
  • Loading branch information
mafredri committed Nov 4, 2022
commit 55651597cf90075c419bfe55db5caef77539b262
33 changes: 33 additions & 0 deletions coderd/database/migrations/create_fixture.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/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"

# if migration name is an empty string exit
[[ -z "${*}" ]] && (echo "Must provide a fixture name" && exit 1)

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."
)
0