Skip to content

Commit 9d27583

Browse files
committed
doc(schema-diff): Add documentation on schema-diff script
This also will include a link to this documentation when leaving a comment on a pull request.
1 parent 04a6c31 commit 9d27583

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

.github/workflows/schema-diff.yml

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ jobs:
5959
cat << EOF > github-comment.txt
6060
$gh_comment_prefix \`${GITHUB_BASE_REF}\` and \`${GITHUB_HEAD_REF}\` @ ${{ github.event.pull_request.head.sha }}
6161
62+
To understand how these diffs are generated and some limitations see the
63+
[documentation](https://github.com/hashicorp/boundary/blob/main/scripts/schema-diff.sh) of the script.
64+
6265
#### Functions
6366
$(getdiff .schema-diff/funcs.diff)
6467

scripts/schema-diff.sh

+34
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
11
#!/usr/bin/env bash
22
# Copyright (c) HashiCorp, Inc.
33
# SPDX-License-Identifier: MPL-2.0
4+
#
5+
# This script can aid in comparing the database schema between two commits.
6+
# It will:
7+
#
8+
# 1. Create a docker postgres database.
9+
# 2. Apply the schema migrations for the current commit.
10+
# 3. Create a dump of the database using pg_dump
11+
# 4. Destroy the database container
12+
# 5. Extract the definitions of specific database objects from the dump.
13+
# These are extracted to place each definition into a separeate .sql file,
14+
# which aids in the performing a diff that can detect renames.
15+
# 6. Switch to the provided base branch (defaults to main)
16+
# 7. Repeate the dump and extract process.
17+
# 8. Create diffs for each kind of database object using `git diff` to compare
18+
# directories which helps with detecting renames.
19+
#
20+
# The dumps and extracted .sql files are left in place so they can be examined
21+
# and compared using other tools. For example an alternate diff tool like delta
22+
# could be used to view the diff to the functions:
23+
#
24+
# delta .schema-diff/funcs_$(git rev-parse main) .schema-diff/funcs_$(git rev-parse HEAD)
25+
#
26+
# These files get removed if the script is run again, or can be manually removed with:
27+
#
28+
# rm -r .schema-diff
29+
#
30+
# Limitations:
31+
#
32+
# Since this script is extracting specifc parts of the schema from
33+
# a database dump, there may be some differences that are not extracted and therefore
34+
# not reported. Some notable limitations follow:
35+
#
36+
# - domain definitions: These are not easily extracted from a pg_dump. Therefore
37+
# changes to domain types or new domain definitions will not be present in the diff.
438

539
die() {
640
echo "$@"

0 commit comments

Comments
 (0)