migrate-hack 0.1.7 → 0.1.9
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 +24 -7
- metadata +4 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2bedfddc47b4a9a7731ef1f1b1a019f01b4a4017c45459dedcc96c855934a0a6
|
4
|
+
data.tar.gz: 6d4bc85df94bd1743291efeac977dbbcfb1106c703304096cdf4e3f0b7b9188f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2ea7a038ec8ec2a9b0f72f64a1d7f21d701537076b1d4b174ae7cf5dfc0c971938cd16e514616465d911884242e7e58c43e4dd6b23b1d2525023927806c665d
|
7
|
+
data.tar.gz: '082bfdc1a476841f34af80119b6e66783ccdd729b17e30f2fc80da8a97091ecb358161a8318c525e669f117695dc379acb76905a03e92f97e9c59bc2bd9232e4'
|
data/bin/migrate-hack.sh
CHANGED
@@ -11,11 +11,24 @@ renew_git() {
|
|
11
11
|
fi
|
12
12
|
}
|
13
13
|
|
14
|
+
# BLOCKS
|
15
|
+
|
16
|
+
# UNCOMITTED CHANGES
|
14
17
|
if [[ -n $(git status --porcelain) ]]; then
|
15
|
-
echo "[
|
18
|
+
echo "⚠️ [ERROR] - There are modified, deleted, or untracked files in the repository. Please resolve these changes to continue."
|
16
19
|
exit 1
|
17
20
|
fi
|
18
21
|
|
22
|
+
# SERVER RUNNING
|
23
|
+
if [ -f tmp/pids/server.pid ]; then
|
24
|
+
PID=$(cat tmp/pids/server.pid)
|
25
|
+
if ps -p $PID > /dev/null; then
|
26
|
+
echo "⚠️ [ERROR] - Server Rails/Puma running on (PID: $PID). Please, stop it or run on a parallel repository."
|
27
|
+
exit 1
|
28
|
+
fi
|
29
|
+
fi
|
30
|
+
|
31
|
+
# GETTING ARGS
|
19
32
|
while [[ $# -gt 0 ]]; do
|
20
33
|
key="$1"
|
21
34
|
case $key in
|
@@ -42,6 +55,7 @@ while [[ $# -gt 0 ]]; do
|
|
42
55
|
esac
|
43
56
|
done
|
44
57
|
|
58
|
+
# LOAD ENVIRONMENT
|
45
59
|
if [ -n "$ENV_FILE" ]; then
|
46
60
|
echo "[env] Loading environment from $ENV_FILE"
|
47
61
|
set -a
|
@@ -49,6 +63,7 @@ if [ -n "$ENV_FILE" ]; then
|
|
49
63
|
set +a
|
50
64
|
fi
|
51
65
|
|
66
|
+
# COPY FILES
|
52
67
|
if [ -n "$COPY_DIR" ]; then
|
53
68
|
destination=$(pwd)
|
54
69
|
if [ -d "$COPY_DIR" ]; then
|
@@ -62,24 +77,23 @@ fi
|
|
62
77
|
|
63
78
|
echo "Detecting pending migrations..."
|
64
79
|
|
65
|
-
#
|
80
|
+
# GET PENDING MIGRATIONS
|
66
81
|
PENDING_MIGRATIONS=$(bundle exec rails db:migrate:status | grep down | awk '{ print $2 }')
|
67
82
|
echo -e "\033[1;32mPending Migrations:\033[0m"
|
68
83
|
echo $PENDING_MIGRATIONS
|
69
|
-
|
70
|
-
# 2. [commit_date] [migration_id] [commit_hash]
|
71
84
|
MIGRATION_LIST=""
|
72
85
|
TEMP_FILE=$(mktemp)
|
73
86
|
|
74
|
-
#
|
87
|
+
# BUILD LIST OF MIGRATIONS AND COMMITS
|
75
88
|
for MIGRATION in $PENDING_MIGRATIONS; do
|
76
89
|
FILE=$(find db/migrate -name "${MIGRATION}_*.rb")
|
77
90
|
COMMIT_HASH=$(git log -n 1 --pretty=format:%H -- "$FILE")
|
78
91
|
COMMIT_DATE=$(git show -s --format=%ct "$COMMIT_HASH")
|
92
|
+
# [commit_date] [migration_id] [commit_hash]
|
79
93
|
echo "$COMMIT_DATE $MIGRATION $COMMIT_HASH" >> "$TEMP_FILE"
|
80
94
|
done
|
81
95
|
|
82
|
-
#
|
96
|
+
# ORDER BY COMMIT DATE
|
83
97
|
while read -r TIMESTAMP MIGRATION COMMIT; do
|
84
98
|
echo -e "\033[1;32mRunning migration $MIGRATION on commit $COMMIT (timestamp $TIMESTAMP)...\033[0m"
|
85
99
|
renew_git
|
@@ -95,8 +109,11 @@ while read -r TIMESTAMP MIGRATION COMMIT; do
|
|
95
109
|
git checkout $CURRENT_BRANCH > /dev/null
|
96
110
|
done < <(sort -n "$TEMP_FILE")
|
97
111
|
|
112
|
+
# RESTORING YOUR REPO
|
98
113
|
renew_git
|
114
|
+
|
115
|
+
# CHECKING STATUS
|
99
116
|
bundle exec rails db:migrate:status | grep down
|
100
117
|
|
101
|
-
#
|
118
|
+
# TRASH
|
102
119
|
rm -f "$TEMP_FILE"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: migrate-hack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Zillner
|
@@ -9,15 +9,8 @@ bindir: bin
|
|
9
9
|
cert_chain: []
|
10
10
|
date: 2025-03-28 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
|
-
description:
|
13
|
-
|
14
|
-
|
15
|
-
--------------------------------
|
16
|
-
|
17
|
-
⚠️ Warning: This gem modifies the files in the repository where it is executed according to git history, but then restores everything to normal.
|
18
|
-
Do not run it on servers that are actively serving the application.
|
19
|
-
Run it in parallel.
|
20
|
-
|
12
|
+
description: "This gem checks out previous git commits to run migrations, then restores
|
13
|
+
everything back to normal.\n\n"
|
21
14
|
email:
|
22
15
|
- carlos@function.ws
|
23
16
|
executables:
|
@@ -49,6 +42,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
42
|
requirements: []
|
50
43
|
rubygems_version: 3.6.6
|
51
44
|
specification_version: 4
|
52
|
-
summary:
|
45
|
+
summary: Run any amount of migrations without conflicts
|
53
46
|
test_files: []
|
54
|
-
...
|