|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 | # Copyright (c) HashiCorp, Inc.
|
3 | 3 | # 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. |
4 | 38 |
|
5 | 39 | die() {
|
6 | 40 | echo "$@"
|
|
0 commit comments