migrate-hack 0.2.3 → 0.2.5

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/migrate-hack.sh +36 -14
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2936e13dcdd668f14d5cd94d5e9011d3a76c351a5246f3aa03eb961de70d5cf
4
- data.tar.gz: 8d150ef42b295b0bca94d7560bb8350e3f7ea9b428795bb68410d150fb9bf03f
3
+ metadata.gz: 4fb52efde1318767a43752a9d6449f652b531a6c8764f51e83d72db565e1862d
4
+ data.tar.gz: 3a7a1a619e93e09dddbe54255fb9efe0c19e204fadacabf313fc1aef3b2c33ba
5
5
  SHA512:
6
- metadata.gz: 4d385f52a38e7e866ae557ab0b1115e9383229dc363d56acc7c69dcc5f037b32da3e603612df82699eb60009883c4099a094bdb579a6ef4c96ec0668013c7490
7
- data.tar.gz: a3fe8bf68acc6ec1b8be14ae12cd342d85e9655c1a0a5862c452325d55f1a6b26b6c0479a1b6266b9fab81f35a718813fd7369027dd0b061c95d8f58a997f989
6
+ metadata.gz: 4a771225f95358ff7e094a8e87fb921f0722b36ea3313a284df0396cc8bc1d9fab481e91f0ef78961eeba1094a445a2565e668f0c04a91fdc7c448f002b4f8c9
7
+ data.tar.gz: 4ae82fd2772db89022081f9bc162323c71df42ac71cf07dd4795961e2ae551b60c8e87b42845c88eab0ecbca9a8f5221d699ec4ed69904df5d85b83377c8582a
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.3"
9
+ VERSION="0.2.5"
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
@@ -66,20 +73,29 @@ copy_files() {
66
73
  fi
67
74
 
68
75
  if [ -n "$COPY_DIR" ]; then
76
+ if [ "$COPY_DIR" = "/" ]; then
77
+ echo "[copy] Refusing to copy from root directory"
78
+ exit 1
79
+ fi
69
80
  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
81
+ if [ ! -d "$COPY_DIR" ]; then
74
82
  echo "[copy] Directory not found: $COPY_DIR"
75
83
  exit 1
76
84
  fi
85
+ dir_size=$(du -sb "$COPY_DIR" | cut -f1)
86
+ MAX_SIZE=$((50 * 1024 * 1024))
87
+ if [ "$dir_size" -gt "$MAX_SIZE" ]; then
88
+ echo "[copy] Directory exceeds 50MB: $COPY_DIR"
89
+ exit 1
90
+ fi
91
+ echo "[copy] Copying files from $COPY_DIR to $destination..."
92
+ cp -r "$COPY_DIR/." "$destination"
77
93
  fi
78
94
  }
79
95
 
80
96
  # BLOCKS
81
97
 
82
- # UNCOMITTED CHANGES
98
+ # UNCOMMITTED CHANGES
83
99
  if [[ -n $(git status --porcelain) ]]; then
84
100
  echo "⚠️ [ERROR] - There are modified, deleted, or untracked files in the repository. Please resolve these changes to continue."
85
101
  exit 1
@@ -88,10 +104,10 @@ fi
88
104
  # SERVER RUNNING
89
105
  if [ -f tmp/pids/server.pid ]; then
90
106
  PID=$(cat tmp/pids/server.pid)
91
- if ps -p $PID > /dev/null; then
107
+ if ps -p "$PID" > /dev/null; then
92
108
  echo "🔍 Server is running on PID: $PID. Checking code reload settings..."
93
109
 
94
- # Verifica se cache_classes está true ou false
110
+ # Check whether cache_classes is true or false
95
111
  CACHE_CLASSES=$(rails runner "puts Rails.application.config.cache_classes")
96
112
  EAGER_LOAD=$(rails runner "puts Rails.application.config.eager_load")
97
113
 
@@ -107,8 +123,13 @@ fi
107
123
 
108
124
  # LOAD ENVIRONMENT
109
125
  if [ -n "$ENV_FILE" ]; then
126
+ if [ ! -f "$ENV_FILE" ]; then
127
+ echo "[env] File not found: $ENV_FILE"
128
+ exit 1
129
+ fi
110
130
  echo "[env] Loading environment from $ENV_FILE"
111
131
  set -a
132
+ # shellcheck source=/dev/null
112
133
  source "$ENV_FILE"
113
134
  set +a
114
135
  fi
@@ -136,8 +157,7 @@ while true; do
136
157
  fi
137
158
 
138
159
  echo -e "\033[1;32mPending Migrations:\033[0m"
139
- echo $PENDING_MIGRATIONS
140
- MIGRATION_LIST=""
160
+ echo "$PENDING_MIGRATIONS"
141
161
  TEMP_FILE=$(mktemp)
142
162
 
143
163
  # BUILD LIST OF MIGRATIONS AND COMMITS
@@ -153,16 +173,16 @@ while true; do
153
173
  while read -r TIMESTAMP MIGRATION COMMIT; do
154
174
  echo -e "\033[1;32mRunning migration $MIGRATION on commit $COMMIT (timestamp $TIMESTAMP)...\033[0m"
155
175
  renew_git
156
- CHECKOUT=$(git -c advice.detachedHead=false checkout "$COMMIT")
176
+ git -c advice.detachedHead=false checkout "$COMMIT" >/dev/null
157
177
 
158
178
  copy_files
159
179
 
160
180
  bundle install > /dev/null
161
181
  echo -e "\033[1;32m - migrate\033[0m"
162
- bundle exec rails db:migrate:up VERSION=$MIGRATION
182
+ bundle exec rails db:migrate:up VERSION="$MIGRATION"
163
183
 
164
184
  renew_git
165
- git checkout $CURRENT_BRANCH > /dev/null
185
+ git checkout "$CURRENT_BRANCH" > /dev/null
166
186
  done < <(sort -n "$TEMP_FILE")
167
187
 
168
188
  # RESTORING YOUR REPO
@@ -173,4 +193,6 @@ while true; do
173
193
  done
174
194
 
175
195
  # TRASH
176
- rm -f "$TEMP_FILE"
196
+ if [ -n "$TEMP_FILE" ]; then
197
+ rm -f "$TEMP_FILE"
198
+ fi
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.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Zillner
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-01 00:00:00.000000000 Z
10
+ date: 2025-10-31 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