migrate-hack 0.1.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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/migrate-hack +3 -0
  3. data/bin/migrate-hack.sh +99 -0
  4. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f778e69f1f39921cd437b3290d35d221c372e4428527df204d60dbddf428f227
4
+ data.tar.gz: 35a197e56b0c35cf23dff17a6125f7a08d3153933329732a506e2ca341733be4
5
+ SHA512:
6
+ metadata.gz: 8d89832cfa1f26737ea9177486e0161b56c7cc4015781b8008858f06755f635cbf8cbb1c23acecf1dc4eaaf3cce02e78ef2dc9a511a42cea80ea08040c21c836
7
+ data.tar.gz: c64f3c06ac734031733411b3707fc1fa691d65a9ea5e0a3a863ed345589b84a8e5b6953e47f46b23df6c82ad0b685bf77ceb0157d4e71b4a4696f8b95b197d80
data/bin/migrate-hack ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ exec("bash", File.expand_path("migrate-hack.sh", __dir__), *ARGV)
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ENV_FILE=""
4
+ COPY_DIR=""
5
+
6
+ while [[ $# -gt 0 ]]; do
7
+ key="$1"
8
+ case $key in
9
+ --env)
10
+ ENV_FILE="$2"
11
+ shift 2
12
+ ;;
13
+ --env=*)
14
+ ENV_FILE="${key#*=}"
15
+ shift
16
+ ;;
17
+ --copy)
18
+ COPY_DIR="$2"
19
+ shift 2
20
+ ;;
21
+ --copy=*)
22
+ COPY_DIR="${key#*=}"
23
+ shift
24
+ ;;
25
+ *)
26
+ echo "[debug] Ignoring unknown argument: $1"
27
+ shift
28
+ ;;
29
+ esac
30
+ done
31
+
32
+ if [ -n "$ENV_FILE" ]; then
33
+ echo "[env] Loading environment from $ENV_FILE"
34
+ set -a
35
+ source "$ENV_FILE"
36
+ set +a
37
+ fi
38
+
39
+ if [ -n "$COPY_DIR" ]; then
40
+ destination=$(pwd)
41
+ if [ -d "$COPY_DIR" ]; then
42
+ echo "[copy] Copying files from $COPY_DIR to $destination..."
43
+ cp -r "$COPY_DIR/." "$destination"
44
+ else
45
+ echo "[copy] Directory not found: $COPY_DIR"
46
+ exit 1
47
+ fi
48
+ fi
49
+
50
+ if [[ -n $(git status --porcelain) ]]; then
51
+ echo "[error] There are modified, deleted, or untracked files in the repository. Please resolve these changes before continuing."
52
+ exit 1
53
+ fi
54
+
55
+ echo "Detecting pending migrations..."
56
+
57
+ # 1. Get pending migrations list
58
+ PENDING_MIGRATIONS=$(bundle exec rails db:migrate:status | grep down | awk '{ print $2 }')
59
+
60
+ # 2. [commit_date] [migration_id] [commit_hash]
61
+ MIGRATION_LIST=""
62
+
63
+ echo "Pending Migrations: $PENDING_MIGRATIONS"
64
+
65
+ TEMP_FILE=$(mktemp)
66
+
67
+ # Build the file
68
+ for MIGRATION in $PENDING_MIGRATIONS; do
69
+ FILE=$(find db/migrate -name "${MIGRATION}_*.rb")
70
+ COMMIT_HASH=$(git log -n 1 --pretty=format:%H -- "$FILE")
71
+ COMMIT_DATE=$(git show -s --format=%ct "$COMMIT_HASH")
72
+ echo "$COMMIT_DATE $MIGRATION $COMMIT_HASH" >> "$TEMP_FILE"
73
+ done
74
+
75
+ # 3. Order list by commit date
76
+ cat $TEMP_FILE
77
+
78
+ while read -r TIMESTAMP MIGRATION COMMIT; do
79
+ echo -e "\033[1;32mRunning migration $MIGRATION on commit $COMMIT (timestamp $TIMESTAMP)...\033[0m"
80
+ CHECKOUT=$(git -c advice.detachedHead=false checkout "$COMMIT")
81
+
82
+ cp -r "$COPY_DIR/." "$destination"
83
+
84
+ CHECKOUT=$(bundle install > /dev/null)
85
+ echo -e "\033[1;32m - migrate\033[0m"
86
+ bundle exec rails db:migrate:up VERSION=$MIGRATION
87
+
88
+ git stash -u > /dev/null
89
+ git stash drop > /dev/null
90
+ git checkout main > /dev/null
91
+ done < <(sort -n "$TEMP_FILE")
92
+
93
+ git stash -u > /dev/null
94
+ git checkout main > /dev/null
95
+
96
+ bundle exec rails db:migrate:status | grep down
97
+
98
+ # Remove temp file
99
+ rm -f "$TEMP_FILE"
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: migrate-hack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Carlos Zillner
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-03-25 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Ideal for deterministic pipelines, CI/CD, or containers that apply migrations
13
+ step by step.
14
+ email:
15
+ - carlos@function.ws
16
+ executables:
17
+ - migrate-hack
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/migrate-hack
22
+ - bin/migrate-hack.sh
23
+ homepage: https://rubygems.org/gems/migrate-hack
24
+ licenses:
25
+ - MIT
26
+ metadata:
27
+ source_code_uri: https://github.com/omelao/migrate-hack
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 2.7.0
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubygems_version: 3.6.6
43
+ specification_version: 4
44
+ summary: Runs old migrations without conflicts
45
+ test_files: []