migrate-hack 0.2.0 → 0.2.2
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 +68 -38
- 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: 50bfc9223af6bc43f357ee277b61338d616ccbd31d931a6f1086bb1b1fb5be94
|
4
|
+
data.tar.gz: 6abf61ab8385976ee9258ad4b2997a1d51f81910d04be37149dca10bed156619
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7d656af0955ecaf6a230da107b3032a96204447ddee635065e11730828007b2de56c20714df7e1c3a3a2220a2c974519e02451a1ae0bcc69cbdd7e6d362b336
|
7
|
+
data.tar.gz: c96fb315967bf9b4757e66bd87325d57ba7873fba0e124a2f68ae7fb9b6dfd39334bb04d1b8bc8bed83508de2476974715b2bdd3bd4fb100449773784f8e308f
|
data/bin/migrate-hack.sh
CHANGED
@@ -1,9 +1,57 @@
|
|
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.2"
|
3
10
|
ENV_FILE=""
|
4
11
|
COPY_DIR=""
|
5
12
|
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
6
13
|
|
14
|
+
# GETTING ARGS
|
15
|
+
while [[ $# -gt 0 ]]; do
|
16
|
+
key="$1"
|
17
|
+
case $key in
|
18
|
+
--env)
|
19
|
+
ENV_FILE="$2"
|
20
|
+
shift 2
|
21
|
+
;;
|
22
|
+
--env=*)
|
23
|
+
ENV_FILE="${key#*=}"
|
24
|
+
shift
|
25
|
+
;;
|
26
|
+
--copy)
|
27
|
+
COPY_DIR="$2"
|
28
|
+
shift 2
|
29
|
+
;;
|
30
|
+
--copy=*)
|
31
|
+
COPY_DIR="${key#*=}"
|
32
|
+
shift
|
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
|
+
;;
|
48
|
+
*)
|
49
|
+
echo "[debug] Ignoring unknown argument: $1"
|
50
|
+
shift
|
51
|
+
;;
|
52
|
+
esac
|
53
|
+
done
|
54
|
+
|
7
55
|
renew_git() {
|
8
56
|
if [[ -n $(git status --porcelain) ]]; then
|
9
57
|
git stash -u > /dev/null
|
@@ -11,6 +59,24 @@ renew_git() {
|
|
11
59
|
fi
|
12
60
|
}
|
13
61
|
|
62
|
+
copy_files() {
|
63
|
+
if [ -z "$COPY_DIR" ]; then
|
64
|
+
echo "[copy] No copy directory specified. Skipping file copy."
|
65
|
+
return
|
66
|
+
fi
|
67
|
+
|
68
|
+
if [ -n "$COPY_DIR" ]; then
|
69
|
+
destination=$(pwd)
|
70
|
+
if [ -d "$COPY_DIR" ]; then
|
71
|
+
echo "[copy] Copying files from $COPY_DIR to $destination..."
|
72
|
+
cp -r "$COPY_DIR/." "$destination"
|
73
|
+
else
|
74
|
+
echo "[copy] Directory not found: $COPY_DIR"
|
75
|
+
exit 1
|
76
|
+
fi
|
77
|
+
fi
|
78
|
+
}
|
79
|
+
|
14
80
|
# BLOCKS
|
15
81
|
|
16
82
|
# UNCOMITTED CHANGES
|
@@ -39,33 +105,6 @@ if [ -f tmp/pids/server.pid ]; then
|
|
39
105
|
fi
|
40
106
|
fi
|
41
107
|
|
42
|
-
# GETTING ARGS
|
43
|
-
while [[ $# -gt 0 ]]; do
|
44
|
-
key="$1"
|
45
|
-
case $key in
|
46
|
-
--env)
|
47
|
-
ENV_FILE="$2"
|
48
|
-
shift 2
|
49
|
-
;;
|
50
|
-
--env=*)
|
51
|
-
ENV_FILE="${key#*=}"
|
52
|
-
shift
|
53
|
-
;;
|
54
|
-
--copy)
|
55
|
-
COPY_DIR="$2"
|
56
|
-
shift 2
|
57
|
-
;;
|
58
|
-
--copy=*)
|
59
|
-
COPY_DIR="${key#*=}"
|
60
|
-
shift
|
61
|
-
;;
|
62
|
-
*)
|
63
|
-
echo "[debug] Ignoring unknown argument: $1"
|
64
|
-
shift
|
65
|
-
;;
|
66
|
-
esac
|
67
|
-
done
|
68
|
-
|
69
108
|
# LOAD ENVIRONMENT
|
70
109
|
if [ -n "$ENV_FILE" ]; then
|
71
110
|
echo "[env] Loading environment from $ENV_FILE"
|
@@ -75,16 +114,7 @@ if [ -n "$ENV_FILE" ]; then
|
|
75
114
|
fi
|
76
115
|
|
77
116
|
# COPY FILES
|
78
|
-
|
79
|
-
destination=$(pwd)
|
80
|
-
if [ -d "$COPY_DIR" ]; then
|
81
|
-
echo "[copy] Copying files from $COPY_DIR to $destination..."
|
82
|
-
cp -r "$COPY_DIR/." "$destination"
|
83
|
-
else
|
84
|
-
echo "[copy] Directory not found: $COPY_DIR"
|
85
|
-
exit 1
|
86
|
-
fi
|
87
|
-
fi
|
117
|
+
copy_files
|
88
118
|
|
89
119
|
echo "Detecting pending migrations..."
|
90
120
|
|
@@ -110,7 +140,7 @@ while read -r TIMESTAMP MIGRATION COMMIT; do
|
|
110
140
|
renew_git
|
111
141
|
CHECKOUT=$(git -c advice.detachedHead=false checkout "$COMMIT")
|
112
142
|
|
113
|
-
|
143
|
+
copy_files
|
114
144
|
|
115
145
|
bundle install > /dev/null
|
116
146
|
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.2.
|
4
|
+
version: 0.2.2
|
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:
|