migrate-hack 0.2.2 → 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 +47 -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)
|
@@ -119,42 +119,58 @@ copy_files
|
|
119
119
|
echo "Detecting pending migrations..."
|
120
120
|
|
121
121
|
# GET PENDING MIGRATIONS
|
122
|
-
|
123
|
-
|
124
|
-
echo $PENDING_MIGRATIONS
|
125
|
-
MIGRATION_LIST=""
|
126
|
-
TEMP_FILE=$(mktemp)
|
127
|
-
|
128
|
-
# BUILD LIST OF MIGRATIONS AND COMMITS
|
129
|
-
for MIGRATION in $PENDING_MIGRATIONS; do
|
130
|
-
FILE=$(find db/migrate -name "${MIGRATION}_*.rb")
|
131
|
-
COMMIT_HASH=$(git log -n 1 --pretty=format:%H -- "$FILE")
|
132
|
-
COMMIT_DATE=$(git show -s --format=%ct "$COMMIT_HASH")
|
133
|
-
# [commit_date] [migration_id] [commit_hash]
|
134
|
-
echo "$COMMIT_DATE $MIGRATION $COMMIT_HASH" >> "$TEMP_FILE"
|
135
|
-
done
|
122
|
+
MAX_ATTEMPTS=5
|
123
|
+
ATTEMPT=0
|
136
124
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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
|
142
130
|
|
143
|
-
|
131
|
+
PENDING_MIGRATIONS=$(bundle exec rails db:migrate:status | grep down | awk '{ print $2 }')
|
144
132
|
|
145
|
-
|
146
|
-
|
147
|
-
|
133
|
+
if [ -z "$PENDING_MIGRATIONS" ]; then
|
134
|
+
echo "✅ All migrations applied successfully."
|
135
|
+
break
|
136
|
+
fi
|
148
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
|
149
169
|
renew_git
|
150
|
-
git checkout $CURRENT_BRANCH > /dev/null
|
151
|
-
done < <(sort -n "$TEMP_FILE")
|
152
|
-
|
153
|
-
# RESTORING YOUR REPO
|
154
|
-
renew_git
|
155
170
|
|
156
|
-
#
|
157
|
-
|
171
|
+
# INCREMENT ATTEMPT COUNTER
|
172
|
+
ATTEMPT=$((ATTEMPT + 1))
|
173
|
+
done
|
158
174
|
|
159
175
|
# TRASH
|
160
176
|
rm -f "$TEMP_FILE"
|