migrate-hack 0.1.8 → 0.2.0

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 +35 -7
  3. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd1e9189d0d4d8ffdf396f4a67a453b4bce62c7a94a06bd94bfb638b864adb2e
4
- data.tar.gz: ff5f571a5bc7de78aec490956d629caa47eaf275909d48f728a52a3aa8f8116a
3
+ metadata.gz: f551b4db0a438604977b1e5e1c1924e62257a9123802b95e30cbd21cbe3e362c
4
+ data.tar.gz: 0e79f977b2e13a4a6f7940816ca0d15998ad761a81c059d0d9d1d5d6ef87f99b
5
5
  SHA512:
6
- metadata.gz: 7efaca36920ccbafb4550bc0fe297e30c116a222375a39b77f59abad3ccd9ef7d8544084f08b0bf61ee9e2c1fe0dc5427ed31e59b8d052488666554d7a71a739
7
- data.tar.gz: 536254792554299cb78ae5c5898238df773cf3b43cb36bf1561845d9813491f532444cfca11d02d45c03eacf3821445148ec507e8f27b9df53ca1d804e2784e7
6
+ metadata.gz: 0dd0211befddde1a366f474b197a22fa4d744e0b7135d492eeebbf2a32fd12d1b1c8d0ad4b9cfe31b6cac9946580091ed90a8376e7abec7b0cb859bc139284c3
7
+ data.tar.gz: 2b31c74f49df7878cae1170fc828b443a27a726223bc4c245c8327d44b7caf401cc9525a0466f4bfea0f9863829311b118b60c0e4df002f5cab6b61aeb986a0b
data/bin/migrate-hack.sh CHANGED
@@ -11,11 +11,35 @@ 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 "[error] There are modified, deleted, or untracked files in the repository. Please resolve these changes before continuing."
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 "🔍 Server is running on PID: $PID. Checking code reload settings..."
27
+
28
+ # Verifica se cache_classes está true ou false
29
+ CACHE_CLASSES=$(rails runner "puts Rails.application.config.cache_classes")
30
+ EAGER_LOAD=$(rails runner "puts Rails.application.config.eager_load")
31
+
32
+ if [ "$CACHE_CLASSES" = "false" ]; then
33
+ echo "⚠️ [ERROR] - Server Rails/Puma is running with cache_classes=false (code reload ENABLED)."
34
+ echo "💡 Please stop the server or use a separate repo/branch to avoid conflicts."
35
+ exit 1
36
+ else
37
+ echo "✅ Server is running, but code reload is DISABLED (cache_classes=$CACHE_CLASSES, eager_load=$EAGER_LOAD). Safe to continue."
38
+ fi
39
+ fi
40
+ fi
41
+
42
+ # GETTING ARGS
19
43
  while [[ $# -gt 0 ]]; do
20
44
  key="$1"
21
45
  case $key in
@@ -42,6 +66,7 @@ while [[ $# -gt 0 ]]; do
42
66
  esac
43
67
  done
44
68
 
69
+ # LOAD ENVIRONMENT
45
70
  if [ -n "$ENV_FILE" ]; then
46
71
  echo "[env] Loading environment from $ENV_FILE"
47
72
  set -a
@@ -49,6 +74,7 @@ if [ -n "$ENV_FILE" ]; then
49
74
  set +a
50
75
  fi
51
76
 
77
+ # COPY FILES
52
78
  if [ -n "$COPY_DIR" ]; then
53
79
  destination=$(pwd)
54
80
  if [ -d "$COPY_DIR" ]; then
@@ -62,24 +88,23 @@ fi
62
88
 
63
89
  echo "Detecting pending migrations..."
64
90
 
65
- # 1. Get pending migrations list
91
+ # GET PENDING MIGRATIONS
66
92
  PENDING_MIGRATIONS=$(bundle exec rails db:migrate:status | grep down | awk '{ print $2 }')
67
93
  echo -e "\033[1;32mPending Migrations:\033[0m"
68
94
  echo $PENDING_MIGRATIONS
69
-
70
- # 2. [commit_date] [migration_id] [commit_hash]
71
95
  MIGRATION_LIST=""
72
96
  TEMP_FILE=$(mktemp)
73
97
 
74
- # Build the file
98
+ # BUILD LIST OF MIGRATIONS AND COMMITS
75
99
  for MIGRATION in $PENDING_MIGRATIONS; do
76
100
  FILE=$(find db/migrate -name "${MIGRATION}_*.rb")
77
101
  COMMIT_HASH=$(git log -n 1 --pretty=format:%H -- "$FILE")
78
102
  COMMIT_DATE=$(git show -s --format=%ct "$COMMIT_HASH")
103
+ # [commit_date] [migration_id] [commit_hash]
79
104
  echo "$COMMIT_DATE $MIGRATION $COMMIT_HASH" >> "$TEMP_FILE"
80
105
  done
81
106
 
82
- # 3. Order list by commit date
107
+ # ORDER BY COMMIT DATE
83
108
  while read -r TIMESTAMP MIGRATION COMMIT; do
84
109
  echo -e "\033[1;32mRunning migration $MIGRATION on commit $COMMIT (timestamp $TIMESTAMP)...\033[0m"
85
110
  renew_git
@@ -95,8 +120,11 @@ while read -r TIMESTAMP MIGRATION COMMIT; do
95
120
  git checkout $CURRENT_BRANCH > /dev/null
96
121
  done < <(sort -n "$TEMP_FILE")
97
122
 
123
+ # RESTORING YOUR REPO
98
124
  renew_git
125
+
126
+ # CHECKING STATUS
99
127
  bundle exec rails db:migrate:status | grep down
100
128
 
101
- # Remove temp file
129
+ # TRASH
102
130
  rm -f "$TEMP_FILE"
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: migrate-hack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Zillner
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-03-28 00:00:00.000000000 Z
10
+ date: 2025-03-31 00:00:00.000000000 Z
11
11
  dependencies: []
12
- description: "This gem checks out previous commits to run migrations, then restores
13
- everything back to normal.\n\n"
12
+ description: "This gem rewinds your commits to apply migrations safely, fixes a bunch
13
+ of common issues, and then puts everything back the way it was.\n\n"
14
14
  email:
15
15
  - carlos@function.ws
16
16
  executables:
@@ -42,5 +42,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
42
  requirements: []
43
43
  rubygems_version: 3.6.6
44
44
  specification_version: 4
45
- summary: Runs old migrations without conflicts
45
+ summary: Run any amount of migrations without conflicts
46
46
  test_files: []