migrate-hack 0.2.4 → 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 +29 -14
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da3b0046f715aba0efbc74d2a20dff172086186b5f02d5b7c37324cb0d05183c
4
- data.tar.gz: c64defed493fe3369a2c47114efb10b72e59952dcd7a227415117ee3d479a399
3
+ metadata.gz: 4fb52efde1318767a43752a9d6449f652b531a6c8764f51e83d72db565e1862d
4
+ data.tar.gz: 3a7a1a619e93e09dddbe54255fb9efe0c19e204fadacabf313fc1aef3b2c33ba
5
5
  SHA512:
6
- metadata.gz: 67c9e0c9c8b2c09a4aa76c453f61b055bf7fd61269a0978d647f26a401ec9587f92690600ccdf7ec4c2f923918add87d5a1e312bc250a6fdb63b412e1350ff42
7
- data.tar.gz: dbf44f84e52571991e165e51337792a28ad37161ab6fb12f73ba9b361d831945d88041fe0263877c7e373603924a16c97aa22bfe7fb1bce045f713d09c3694e0
6
+ metadata.gz: 4a771225f95358ff7e094a8e87fb921f0722b36ea3313a284df0396cc8bc1d9fab481e91f0ef78961eeba1094a445a2565e668f0c04a91fdc7c448f002b4f8c9
7
+ data.tar.gz: 4ae82fd2772db89022081f9bc162323c71df42ac71cf07dd4795961e2ae551b60c8e87b42845c88eab0ecbca9a8f5221d699ec4ed69904df5d85b83377c8582a
data/bin/migrate-hack.sh CHANGED
@@ -6,7 +6,7 @@
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.4"
9
+ VERSION="0.2.5"
10
10
  ENV_FILE=""
11
11
  COPY_DIR=""
12
12
 
@@ -73,20 +73,29 @@ copy_files() {
73
73
  fi
74
74
 
75
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
76
80
  destination=$(pwd)
77
- if [ -d "$COPY_DIR" ]; then
78
- echo "[copy] Copying files from $COPY_DIR to $destination..."
79
- cp -r "$COPY_DIR/." "$destination"
80
- else
81
+ if [ ! -d "$COPY_DIR" ]; then
81
82
  echo "[copy] Directory not found: $COPY_DIR"
82
83
  exit 1
83
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"
84
93
  fi
85
94
  }
86
95
 
87
96
  # BLOCKS
88
97
 
89
- # UNCOMITTED CHANGES
98
+ # UNCOMMITTED CHANGES
90
99
  if [[ -n $(git status --porcelain) ]]; then
91
100
  echo "⚠️ [ERROR] - There are modified, deleted, or untracked files in the repository. Please resolve these changes to continue."
92
101
  exit 1
@@ -95,10 +104,10 @@ fi
95
104
  # SERVER RUNNING
96
105
  if [ -f tmp/pids/server.pid ]; then
97
106
  PID=$(cat tmp/pids/server.pid)
98
- if ps -p $PID > /dev/null; then
107
+ if ps -p "$PID" > /dev/null; then
99
108
  echo "🔍 Server is running on PID: $PID. Checking code reload settings..."
100
109
 
101
- # Verifica se cache_classes está true ou false
110
+ # Check whether cache_classes is true or false
102
111
  CACHE_CLASSES=$(rails runner "puts Rails.application.config.cache_classes")
103
112
  EAGER_LOAD=$(rails runner "puts Rails.application.config.eager_load")
104
113
 
@@ -114,8 +123,13 @@ fi
114
123
 
115
124
  # LOAD ENVIRONMENT
116
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
117
130
  echo "[env] Loading environment from $ENV_FILE"
118
131
  set -a
132
+ # shellcheck source=/dev/null
119
133
  source "$ENV_FILE"
120
134
  set +a
121
135
  fi
@@ -143,8 +157,7 @@ while true; do
143
157
  fi
144
158
 
145
159
  echo -e "\033[1;32mPending Migrations:\033[0m"
146
- echo $PENDING_MIGRATIONS
147
- MIGRATION_LIST=""
160
+ echo "$PENDING_MIGRATIONS"
148
161
  TEMP_FILE=$(mktemp)
149
162
 
150
163
  # BUILD LIST OF MIGRATIONS AND COMMITS
@@ -160,16 +173,16 @@ while true; do
160
173
  while read -r TIMESTAMP MIGRATION COMMIT; do
161
174
  echo -e "\033[1;32mRunning migration $MIGRATION on commit $COMMIT (timestamp $TIMESTAMP)...\033[0m"
162
175
  renew_git
163
- CHECKOUT=$(git -c advice.detachedHead=false checkout "$COMMIT")
176
+ git -c advice.detachedHead=false checkout "$COMMIT" >/dev/null
164
177
 
165
178
  copy_files
166
179
 
167
180
  bundle install > /dev/null
168
181
  echo -e "\033[1;32m - migrate\033[0m"
169
- bundle exec rails db:migrate:up VERSION=$MIGRATION
182
+ bundle exec rails db:migrate:up VERSION="$MIGRATION"
170
183
 
171
184
  renew_git
172
- git checkout $CURRENT_BRANCH > /dev/null
185
+ git checkout "$CURRENT_BRANCH" > /dev/null
173
186
  done < <(sort -n "$TEMP_FILE")
174
187
 
175
188
  # RESTORING YOUR REPO
@@ -180,4 +193,6 @@ while true; do
180
193
  done
181
194
 
182
195
  # TRASH
183
- 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.4
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-05-12 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