migrate-hack 0.1.9 → 0.2.1
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 +71 -35
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dc2a35a68c4b43f0800a4ffc33e3c5da9d7e6307940183f4d713c82c7e9fb56
|
4
|
+
data.tar.gz: 74d254de5fc9e31981892a6c3bb869cfad2d04d0cecbc2bb596988d5c54699b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72da583afab23fb33910d78df230432324a1ad9487806aa78b8b36878165aabdd1ae57aeb1c2386175440fe01812689042fe0aeb298717ac242b0a636486331e
|
7
|
+
data.tar.gz: b6c01d2b095e8ad6bed6d18841f3c6ced40e856de8ff7574bf9bee31e144094bfc8b294097cb7262849c0b484471776694ba27463a6b8b27c03fb6c58451ee34
|
data/bin/migrate-hack.sh
CHANGED
@@ -1,33 +1,16 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
2
|
|
3
|
+
# This script is designed to run pending migrations in a Rails application
|
4
|
+
# by checking out the commit where each migration was created.
|
5
|
+
# It also allows loading environment variables from a specified file and
|
6
|
+
# copying files from a specified directory to the current one.
|
7
|
+
# Usage: ./migrate-hack.sh [--env=FILE] [--copy=DIR] [--help] [--version]
|
8
|
+
|
9
|
+
VERSION="0.2.1"
|
3
10
|
ENV_FILE=""
|
4
11
|
COPY_DIR=""
|
5
12
|
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
6
13
|
|
7
|
-
renew_git() {
|
8
|
-
if [[ -n $(git status --porcelain) ]]; then
|
9
|
-
git stash -u > /dev/null
|
10
|
-
git stash drop > /dev/null
|
11
|
-
fi
|
12
|
-
}
|
13
|
-
|
14
|
-
# BLOCKS
|
15
|
-
|
16
|
-
# UNCOMITTED CHANGES
|
17
|
-
if [[ -n $(git status --porcelain) ]]; then
|
18
|
-
echo "⚠️ [ERROR] - There are modified, deleted, or untracked files in the repository. Please resolve these changes to continue."
|
19
|
-
exit 1
|
20
|
-
fi
|
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
14
|
# GETTING ARGS
|
32
15
|
while [[ $# -gt 0 ]]; do
|
33
16
|
key="$1"
|
@@ -48,6 +31,20 @@ while [[ $# -gt 0 ]]; do
|
|
48
31
|
COPY_DIR="${key#*=}"
|
49
32
|
shift
|
50
33
|
;;
|
34
|
+
--help)
|
35
|
+
echo "Usage: migrate-hack [--env=FILE] [--copy=DIR] [--help] [--version]"
|
36
|
+
echo ""
|
37
|
+
echo "Options:"
|
38
|
+
echo " --env=FILE Load environment variables from the specified file"
|
39
|
+
echo " --copy=DIR Copy config and settings untracked files from the specified directory to the current one"
|
40
|
+
echo " --help Show this help message"
|
41
|
+
echo " --version Show script version"
|
42
|
+
exit 0
|
43
|
+
;;
|
44
|
+
--version)
|
45
|
+
echo "migrate-hack ($VERSION)"
|
46
|
+
exit 0
|
47
|
+
;;
|
51
48
|
*)
|
52
49
|
echo "[debug] Ignoring unknown argument: $1"
|
53
50
|
shift
|
@@ -55,6 +52,54 @@ while [[ $# -gt 0 ]]; do
|
|
55
52
|
esac
|
56
53
|
done
|
57
54
|
|
55
|
+
renew_git() {
|
56
|
+
if [[ -n $(git status --porcelain) ]]; then
|
57
|
+
git stash -u > /dev/null
|
58
|
+
git stash drop > /dev/null
|
59
|
+
fi
|
60
|
+
}
|
61
|
+
|
62
|
+
copy_files() {
|
63
|
+
if [ -n "$COPY_DIR" ]; then
|
64
|
+
destination=$(pwd)
|
65
|
+
if [ -d "$COPY_DIR" ]; then
|
66
|
+
echo "[copy] Copying files from $COPY_DIR to $destination..."
|
67
|
+
cp -r "$COPY_DIR/." "$destination"
|
68
|
+
else
|
69
|
+
echo "[copy] Directory not found: $COPY_DIR"
|
70
|
+
exit 1
|
71
|
+
fi
|
72
|
+
fi
|
73
|
+
}
|
74
|
+
|
75
|
+
# BLOCKS
|
76
|
+
|
77
|
+
# UNCOMITTED CHANGES
|
78
|
+
if [[ -n $(git status --porcelain) ]]; then
|
79
|
+
echo "⚠️ [ERROR] - There are modified, deleted, or untracked files in the repository. Please resolve these changes to continue."
|
80
|
+
exit 1
|
81
|
+
fi
|
82
|
+
|
83
|
+
# SERVER RUNNING
|
84
|
+
if [ -f tmp/pids/server.pid ]; then
|
85
|
+
PID=$(cat tmp/pids/server.pid)
|
86
|
+
if ps -p $PID > /dev/null; then
|
87
|
+
echo "🔍 Server is running on PID: $PID. Checking code reload settings..."
|
88
|
+
|
89
|
+
# Verifica se cache_classes está true ou false
|
90
|
+
CACHE_CLASSES=$(rails runner "puts Rails.application.config.cache_classes")
|
91
|
+
EAGER_LOAD=$(rails runner "puts Rails.application.config.eager_load")
|
92
|
+
|
93
|
+
if [ "$CACHE_CLASSES" = "false" ]; then
|
94
|
+
echo "⚠️ [ERROR] - Server Rails/Puma is running with cache_classes=false (code reload ENABLED)."
|
95
|
+
echo "💡 Please stop the server or use a separate repo/branch to avoid conflicts."
|
96
|
+
exit 1
|
97
|
+
else
|
98
|
+
echo "✅ Server is running, but code reload is DISABLED (cache_classes=$CACHE_CLASSES, eager_load=$EAGER_LOAD). Safe to continue."
|
99
|
+
fi
|
100
|
+
fi
|
101
|
+
fi
|
102
|
+
|
58
103
|
# LOAD ENVIRONMENT
|
59
104
|
if [ -n "$ENV_FILE" ]; then
|
60
105
|
echo "[env] Loading environment from $ENV_FILE"
|
@@ -64,16 +109,7 @@ if [ -n "$ENV_FILE" ]; then
|
|
64
109
|
fi
|
65
110
|
|
66
111
|
# COPY FILES
|
67
|
-
|
68
|
-
destination=$(pwd)
|
69
|
-
if [ -d "$COPY_DIR" ]; then
|
70
|
-
echo "[copy] Copying files from $COPY_DIR to $destination..."
|
71
|
-
cp -r "$COPY_DIR/." "$destination"
|
72
|
-
else
|
73
|
-
echo "[copy] Directory not found: $COPY_DIR"
|
74
|
-
exit 1
|
75
|
-
fi
|
76
|
-
fi
|
112
|
+
copy_files
|
77
113
|
|
78
114
|
echo "Detecting pending migrations..."
|
79
115
|
|
@@ -99,7 +135,7 @@ while read -r TIMESTAMP MIGRATION COMMIT; do
|
|
99
135
|
renew_git
|
100
136
|
CHECKOUT=$(git -c advice.detachedHead=false checkout "$COMMIT")
|
101
137
|
|
102
|
-
|
138
|
+
copy_files
|
103
139
|
|
104
140
|
bundle install > /dev/null
|
105
141
|
echo -e "\033[1;32m - migrate\033[0m"
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
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.2.1
|
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-04-01 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
|
-
description: "
|
13
|
-
|
12
|
+
description: "Run any amount of migrations. migrate-hack fixes your migrations. This
|
13
|
+
gem rewinds your commits to apply migrations safely, and then puts everything back
|
14
|
+
the way it was. This fixes a bunch of common issues.\n\n"
|
14
15
|
email:
|
15
16
|
- carlos@function.ws
|
16
17
|
executables:
|