Skip to content

Commit 5be6607

Browse files
authored
fixing DB migration script to ignore extension and prevent error (#592)
1 parent c4201a0 commit 5be6607

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Diff for: db-migration.sh

+13-8
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ fi
117117

118118
echo "${YELLOW}Dumping source database data from '$SOURCE_URL' to '$OUTPUT'...${RESET}"
119119
# clean (drop) database objects before creation but only if exists
120-
# no owner, no grant privileges, includes blobs, use directory format, jobs for parallel tasks
121-
pg_dump -v --clean --if-exists --no-owner --no-privileges --blobs --format d --jobs "$JOBS" -f "$OUTPUT" "$SOURCE_URL"
120+
# no owner, no grant privileges, no comment extensions, includes blobs, use directory format, jobs for parallel tasks
121+
pg_dump -v --clean --if-exists --no-owner --no-privileges --no-comments --blobs --format d --jobs "$JOBS" -f "$OUTPUT" "$SOURCE_URL"
122122

123123
if ! [ "$?" == "0" ]
124124
then
@@ -129,14 +129,19 @@ fi
129129
echo "${GREEN}Source database dump to '$OUTPUT' successful.${RESET}"
130130
echo "${YELLOW}Restoring target database with data from '$OUTPUT' to '$TARGET_URL'...${RESET}"
131131

132-
# creates database before restore, no ownership, use directory format, jobs for parallel tasks
133-
pg_restore -v --clean --if-exists --no-owner --no-privileges --jobs "$JOBS" --dbname "$TARGET_URL" "$OUTPUT"
132+
# creates database before restore, no ownership, no privileges, only restore public schema and analytics, use directory format, jobs for parallel tasks
133+
pg_restore -v --clean --if-exists --no-owner --no-privileges -n public -n analytics --jobs "$JOBS" --dbname "$TARGET_URL" "$OUTPUT"
134134

135-
if ! [ "$?" == "0" ]
135+
EXIT_CODE=$?
136+
if [ "$EXIT_CODE" == "0" ]
136137
then
138+
echo "${GREEN}Target database restore from '$OUTPUT' successful.${RESET}"
139+
echo "${GREEN}Database migration complete!${RESET}"
140+
else
137141
echo "${RED}Database restore failure, stopping migration.${RESET}"
138-
exit 1
139142
fi
140143

141-
echo "${GREEN}Target database restore from '$OUTPUT' successful.${RESET}"
142-
echo "${GREEN}Database migration complete!${RESET}"
144+
echo "${YELLOW}Deleting temporary data folder '$OUTPUT'.${RESET}"
145+
rm -R "$OUTPUT"
146+
echo "${GREEN}Temporary data folder '$OUTPUT' deleted.${RESET}"
147+
exit $EXIT_CODE

0 commit comments

Comments
 (0)