migrate-hack 0.2.2 → 0.2.4
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 +54 -31
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da3b0046f715aba0efbc74d2a20dff172086186b5f02d5b7c37324cb0d05183c
|
4
|
+
data.tar.gz: c64defed493fe3369a2c47114efb10b72e59952dcd7a227415117ee3d479a399
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67c9e0c9c8b2c09a4aa76c453f61b055bf7fd61269a0978d647f26a401ec9587f92690600ccdf7ec4c2f923918add87d5a1e312bc250a6fdb63b412e1350ff42
|
7
|
+
data.tar.gz: dbf44f84e52571991e165e51337792a28ad37161ab6fb12f73ba9b361d831945d88041fe0263877c7e373603924a16c97aa22bfe7fb1bce045f713d09c3694e0
|
data/bin/migrate-hack.sh
CHANGED
@@ -6,9 +6,16 @@
|
|
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.4"
|
10
10
|
ENV_FILE=""
|
11
11
|
COPY_DIR=""
|
12
|
+
|
13
|
+
# VERIFY GIT REPO
|
14
|
+
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
|
15
|
+
echo "❌ [ERROR] - migrate-hack must be run inside a Git repository."
|
16
|
+
exit 1
|
17
|
+
fi
|
18
|
+
|
12
19
|
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
13
20
|
|
14
21
|
# GETTING ARGS
|
@@ -119,42 +126,58 @@ copy_files
|
|
119
126
|
echo "Detecting pending migrations..."
|
120
127
|
|
121
128
|
# 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
|
129
|
+
MAX_ATTEMPTS=5
|
130
|
+
ATTEMPT=0
|
136
131
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
132
|
+
while true; do
|
133
|
+
if [ "$ATTEMPT" -ge "$MAX_ATTEMPTS" ]; then
|
134
|
+
echo "⚠️ [WARNING] Please, if you have many newer migrations that fix older ones, run again."
|
135
|
+
break
|
136
|
+
fi
|
142
137
|
|
143
|
-
|
138
|
+
PENDING_MIGRATIONS=$(bundle exec rails db:migrate:status | grep down | awk '{ print $2 }')
|
144
139
|
|
145
|
-
|
146
|
-
|
147
|
-
|
140
|
+
if [ -z "$PENDING_MIGRATIONS" ]; then
|
141
|
+
echo "✅ All migrations applied successfully."
|
142
|
+
break
|
143
|
+
fi
|
148
144
|
|
145
|
+
echo -e "\033[1;32mPending Migrations:\033[0m"
|
146
|
+
echo $PENDING_MIGRATIONS
|
147
|
+
MIGRATION_LIST=""
|
148
|
+
TEMP_FILE=$(mktemp)
|
149
|
+
|
150
|
+
# BUILD LIST OF MIGRATIONS AND COMMITS
|
151
|
+
for MIGRATION in $PENDING_MIGRATIONS; do
|
152
|
+
FILE=$(find db/migrate -name "${MIGRATION}_*.rb")
|
153
|
+
COMMIT_HASH=$(git log -n 1 --pretty=format:%H -- "$FILE")
|
154
|
+
COMMIT_DATE=$(git show -s --format=%ct "$COMMIT_HASH")
|
155
|
+
# [commit_date] [migration_id] [commit_hash]
|
156
|
+
echo "$COMMIT_DATE $MIGRATION $COMMIT_HASH" >> "$TEMP_FILE"
|
157
|
+
done
|
158
|
+
|
159
|
+
# ORDER BY COMMIT DATE
|
160
|
+
while read -r TIMESTAMP MIGRATION COMMIT; do
|
161
|
+
echo -e "\033[1;32mRunning migration $MIGRATION on commit $COMMIT (timestamp $TIMESTAMP)...\033[0m"
|
162
|
+
renew_git
|
163
|
+
CHECKOUT=$(git -c advice.detachedHead=false checkout "$COMMIT")
|
164
|
+
|
165
|
+
copy_files
|
166
|
+
|
167
|
+
bundle install > /dev/null
|
168
|
+
echo -e "\033[1;32m - migrate\033[0m"
|
169
|
+
bundle exec rails db:migrate:up VERSION=$MIGRATION
|
170
|
+
|
171
|
+
renew_git
|
172
|
+
git checkout $CURRENT_BRANCH > /dev/null
|
173
|
+
done < <(sort -n "$TEMP_FILE")
|
174
|
+
|
175
|
+
# RESTORING YOUR REPO
|
149
176
|
renew_git
|
150
|
-
git checkout $CURRENT_BRANCH > /dev/null
|
151
|
-
done < <(sort -n "$TEMP_FILE")
|
152
177
|
|
153
|
-
#
|
154
|
-
|
155
|
-
|
156
|
-
# CHECKING STATUS
|
157
|
-
bundle exec rails db:migrate:status | grep down
|
178
|
+
# INCREMENT ATTEMPT COUNTER
|
179
|
+
ATTEMPT=$((ATTEMPT + 1))
|
180
|
+
done
|
158
181
|
|
159
182
|
# TRASH
|
160
183
|
rm -f "$TEMP_FILE"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: migrate-hack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Zillner
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-05-12 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: "Run any amount of migrations. migrate-hack fixes your migrations. This
|
13
13
|
gem rewinds your commits to apply migrations safely, and then puts everything back
|