migrate-hack 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/migrate-hack.sh +52 -31
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2936e13dcdd668f14d5cd94d5e9011d3a76c351a5246f3aa03eb961de70d5cf
|
4
|
+
data.tar.gz: 8d150ef42b295b0bca94d7560bb8350e3f7ea9b428795bb68410d150fb9bf03f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d385f52a38e7e866ae557ab0b1115e9383229dc363d56acc7c69dcc5f037b32da3e603612df82699eb60009883c4099a094bdb579a6ef4c96ec0668013c7490
|
7
|
+
data.tar.gz: a3fe8bf68acc6ec1b8be14ae12cd342d85e9655c1a0a5862c452325d55f1a6b26b6c0479a1b6266b9fab81f35a718813fd7369027dd0b061c95d8f58a997f989
|
data/bin/migrate-hack.sh
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
# copying files from a specified directory to the current one.
|
7
7
|
# Usage: ./migrate-hack.sh [--env=FILE] [--copy=DIR] [--help] [--version]
|
8
8
|
|
9
|
-
VERSION="0.2.
|
9
|
+
VERSION="0.2.3"
|
10
10
|
ENV_FILE=""
|
11
11
|
COPY_DIR=""
|
12
12
|
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
@@ -60,6 +60,11 @@ renew_git() {
|
|
60
60
|
}
|
61
61
|
|
62
62
|
copy_files() {
|
63
|
+
if [ -z "$COPY_DIR" ]; then
|
64
|
+
echo "[copy] No copy directory specified. Skipping file copy."
|
65
|
+
return
|
66
|
+
fi
|
67
|
+
|
63
68
|
if [ -n "$COPY_DIR" ]; then
|
64
69
|
destination=$(pwd)
|
65
70
|
if [ -d "$COPY_DIR" ]; then
|
@@ -114,42 +119,58 @@ copy_files
|
|
114
119
|
echo "Detecting pending migrations..."
|
115
120
|
|
116
121
|
# GET PENDING MIGRATIONS
|
117
|
-
|
118
|
-
|
119
|
-
echo $PENDING_MIGRATIONS
|
120
|
-
MIGRATION_LIST=""
|
121
|
-
TEMP_FILE=$(mktemp)
|
122
|
-
|
123
|
-
# BUILD LIST OF MIGRATIONS AND COMMITS
|
124
|
-
for MIGRATION in $PENDING_MIGRATIONS; do
|
125
|
-
FILE=$(find db/migrate -name "${MIGRATION}_*.rb")
|
126
|
-
COMMIT_HASH=$(git log -n 1 --pretty=format:%H -- "$FILE")
|
127
|
-
COMMIT_DATE=$(git show -s --format=%ct "$COMMIT_HASH")
|
128
|
-
# [commit_date] [migration_id] [commit_hash]
|
129
|
-
echo "$COMMIT_DATE $MIGRATION $COMMIT_HASH" >> "$TEMP_FILE"
|
130
|
-
done
|
122
|
+
MAX_ATTEMPTS=5
|
123
|
+
ATTEMPT=0
|
131
124
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
125
|
+
while true; do
|
126
|
+
if [ "$ATTEMPT" -ge "$MAX_ATTEMPTS" ]; then
|
127
|
+
echo "⚠️ [WARNING] Please, if you have many newer migrations that fix older ones, run again."
|
128
|
+
break
|
129
|
+
fi
|
137
130
|
|
138
|
-
|
131
|
+
PENDING_MIGRATIONS=$(bundle exec rails db:migrate:status | grep down | awk '{ print $2 }')
|
139
132
|
|
140
|
-
|
141
|
-
|
142
|
-
|
133
|
+
if [ -z "$PENDING_MIGRATIONS" ]; then
|
134
|
+
echo "✅ All migrations applied successfully."
|
135
|
+
break
|
136
|
+
fi
|
143
137
|
|
138
|
+
echo -e "\033[1;32mPending Migrations:\033[0m"
|
139
|
+
echo $PENDING_MIGRATIONS
|
140
|
+
MIGRATION_LIST=""
|
141
|
+
TEMP_FILE=$(mktemp)
|
142
|
+
|
143
|
+
# BUILD LIST OF MIGRATIONS AND COMMITS
|
144
|
+
for MIGRATION in $PENDING_MIGRATIONS; do
|
145
|
+
FILE=$(find db/migrate -name "${MIGRATION}_*.rb")
|
146
|
+
COMMIT_HASH=$(git log -n 1 --pretty=format:%H -- "$FILE")
|
147
|
+
COMMIT_DATE=$(git show -s --format=%ct "$COMMIT_HASH")
|
148
|
+
# [commit_date] [migration_id] [commit_hash]
|
149
|
+
echo "$COMMIT_DATE $MIGRATION $COMMIT_HASH" >> "$TEMP_FILE"
|
150
|
+
done
|
151
|
+
|
152
|
+
# ORDER BY COMMIT DATE
|
153
|
+
while read -r TIMESTAMP MIGRATION COMMIT; do
|
154
|
+
echo -e "\033[1;32mRunning migration $MIGRATION on commit $COMMIT (timestamp $TIMESTAMP)...\033[0m"
|
155
|
+
renew_git
|
156
|
+
CHECKOUT=$(git -c advice.detachedHead=false checkout "$COMMIT")
|
157
|
+
|
158
|
+
copy_files
|
159
|
+
|
160
|
+
bundle install > /dev/null
|
161
|
+
echo -e "\033[1;32m - migrate\033[0m"
|
162
|
+
bundle exec rails db:migrate:up VERSION=$MIGRATION
|
163
|
+
|
164
|
+
renew_git
|
165
|
+
git checkout $CURRENT_BRANCH > /dev/null
|
166
|
+
done < <(sort -n "$TEMP_FILE")
|
167
|
+
|
168
|
+
# RESTORING YOUR REPO
|
144
169
|
renew_git
|
145
|
-
git checkout $CURRENT_BRANCH > /dev/null
|
146
|
-
done < <(sort -n "$TEMP_FILE")
|
147
170
|
|
148
|
-
#
|
149
|
-
|
150
|
-
|
151
|
-
# CHECKING STATUS
|
152
|
-
bundle exec rails db:migrate:status | grep down
|
171
|
+
# INCREMENT ATTEMPT COUNTER
|
172
|
+
ATTEMPT=$((ATTEMPT + 1))
|
173
|
+
done
|
153
174
|
|
154
175
|
# TRASH
|
155
176
|
rm -f "$TEMP_FILE"
|