-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathdev.sh
More file actions
116 lines (99 loc) · 2.95 KB
/
dev.sh
File metadata and controls
116 lines (99 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
set -e
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
PGDOG_BIN_PATH="${PGDOG_BIN:-${SCRIPT_DIR}/../../target/debug/pgdog}"
pushd ${SCRIPT_DIR}
dropdb pgdog1 || true
dropdb pgdog2 || true
createdb pgdog1
createdb pgdog2
export PGPASSWORD=pgdog
export PGUSER=pgdog
export PGHOST=127.0.0.1
export PGPORT=5432
psql -f ${SCRIPT_DIR}/ecommerce_schema.sql pgdog1
psql -c 'CREATE PUBLICATION pgdog FOR ALL TABLES' pgdog1 || true
${PGDOG_BIN_PATH} \
schema-sync \
--from-database source \
--to-database destination \
--publication pgdog
${PGDOG_BIN_PATH} \
schema-sync \
--from-database source \
--to-database destination \
--publication pgdog \
--data-sync-complete
${PGDOG_BIN_PATH} \
schema-sync \
--from-database source \
--to-database destination \
--publication pgdog \
--cutover
pg_dump \
--schema-only \
--exclude-schema pgdog \
--no-publications pgdog1 > source.sql
pg_dump \
--schema-only \
--exclude-schema pgdog \
--no-publications pgdog2 > destination.sql
for f in source.sql destination.sql; do
sed -i.bak '/^\\restrict.*$/d' $f
sed -i.bak '/^\\unrestrict.*$/d' $f
done
# Expected integer -> bigint conversions (normalized to just column_name and type)
# Format: column_name integer -> column_name bigint
EXPECTED_CONVERSIONS=$(cat <<EOF
audit_id integer
audit_id bigint
category_id integer
category_id bigint
document_id integer
document_id bigint
event_id integer
event_id bigint
flag_id integer
flag_id bigint
notification_id integer
notification_id bigint
override_id integer
override_id bigint
price_history_id integer
price_history_id bigint
session_id integer
session_id bigint
setting_id integer
setting_id bigint
ticket_id integer
ticket_id bigint
EOF
)
diff source.sql destination.sql > diff.txt || true
# Extract integer -> bigint conversions from the diff
# 1. Get removed (< integer) and added (> bigint) column lines
# 2. Only keep columns that appear as integer in source AND bigint in destination
REMOVED_INT=$(grep '^<' diff.txt | \
sed -E 's/.*[[:space:]]([a-z_]+)[[:space:]]+integer\b.*/\1/' | \
grep -E '^[a-z_]+$' | sort -u)
ADDED_BIGINT=$(grep '^>' diff.txt | \
sed -E 's/.*[[:space:]]([a-z_]+)[[:space:]]+bigint\b.*/\1/' | \
grep -E '^[a-z_]+$' | sort -u)
# Columns that changed from integer to bigint
CONVERTED=$(comm -12 <(echo "$REMOVED_INT") <(echo "$ADDED_BIGINT"))
# Build the expected format: column_name integer \n column_name bigint
ACTUAL_CONVERSIONS=$(echo "$CONVERTED" | while read col; do
echo "$col integer"
echo "$col bigint"
done | sort -u)
EXPECTED_SORTED=$(echo "$EXPECTED_CONVERSIONS" | sort -u)
if [ "$ACTUAL_CONVERSIONS" != "$EXPECTED_SORTED" ]; then
echo "Schema diff does not match expected integer -> bigint conversions"
echo "=== Expected ==="
echo "$EXPECTED_SORTED"
echo "=== Actual ==="
echo "$ACTUAL_CONVERSIONS"
exit 1
fi
rm source.sql destination.sql diff.txt
popd