rails-rebase-migrations 1.0.1 → 1.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.
- checksums.yaml +4 -4
- data/lib/rails_rebase_migrations.rb +19 -16
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 149586aa30a8a973134792134bf10161d182dca6f7e4dedeade559eb69c6e94b
|
4
|
+
data.tar.gz: e9ce9804c4732d2cff593fb5c2743b6514e010f44493b006cf44cde583088e14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 812711df02461db5d757203817142a1c28272672813d3e4f7794d96a12a9a95ad13605126b4726380b9eb916ee84066163ff9bdcbbde55093f27c2642d9ecb97
|
7
|
+
data.tar.gz: f4c1c9a5a2a74024710b0f744386b07c0ec8c11a492592ae2ef92ec2039f95c15bf3784ed1e906d7b06d8b542d3374b09e7a0ee146c1e86bcb2db2115b82bfde
|
@@ -1,32 +1,37 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
1
|
# frozen_string_literal: true
|
3
2
|
|
4
3
|
require 'open3'
|
5
4
|
require 'optparse'
|
6
5
|
require 'shellwords'
|
6
|
+
require 'time'
|
7
7
|
|
8
8
|
class RebaseMigrations
|
9
9
|
SKIP_REBASE = '_skip_rebase_'
|
10
10
|
|
11
11
|
MIGRATIONS_DIR = 'db/migrate/'
|
12
|
-
MIGRATION_NAME_RE =
|
12
|
+
MIGRATION_NAME_RE = /\A(\d+)(.*)\z/
|
13
|
+
|
14
|
+
TIME_FORMAT = '%Y%m%d%H%M%S'
|
13
15
|
|
14
16
|
def main
|
15
17
|
ref, options = parse_args
|
16
18
|
|
17
19
|
out = subprocess('git', 'ls-files', '--', MIGRATIONS_DIR)
|
18
|
-
all_migrations = out.
|
20
|
+
all_migrations = out.lines(chomp: true).to_a.sort
|
19
21
|
|
20
|
-
out = subprocess('git', '
|
21
|
-
|
22
|
+
out = subprocess('git', 'ls-tree', '--name-only', ref, '--', MIGRATIONS_DIR)
|
23
|
+
ref_migrations = out.lines(chomp: true).to_a.sort
|
22
24
|
|
23
|
-
starting_index =
|
25
|
+
starting_index = ref_migrations.length
|
24
26
|
|
25
|
-
|
27
|
+
basename = File.basename(ref_migrations.last)
|
28
|
+
match = MIGRATION_NAME_RE.match(basename)
|
29
|
+
last_timestamp = match[1]
|
30
|
+
now = [Time.now.utc, Time.strptime("#{last_timestamp}Z", "#{TIME_FORMAT}%Z")].max.to_i
|
26
31
|
|
27
|
-
|
32
|
+
all_migrations.each do |path|
|
33
|
+
next if ref_migrations.include?(path)
|
28
34
|
|
29
|
-
new_migrations.each do |path|
|
30
35
|
basename = File.basename(path)
|
31
36
|
match = MIGRATION_NAME_RE.match(File.basename(path))
|
32
37
|
migration_timestamp = match[1]
|
@@ -42,26 +47,24 @@ class RebaseMigrations
|
|
42
47
|
Migration #{basename} is out of order. It should come after
|
43
48
|
pre-existing migrations. To fix, run the command:
|
44
49
|
|
45
|
-
$
|
50
|
+
$ bundle exec rebase-migrations
|
46
51
|
|
47
52
|
If the migration is intentionally out of order, add the magic
|
48
53
|
string "#{SKIP_REBASE}" to the beginning of the migration name:
|
49
54
|
|
50
55
|
$ git mv #{path} #{MIGRATIONS_DIR}#{skip_migration_name}
|
51
|
-
|
52
|
-
If this pull request is merging across branches prod, staging, or
|
53
|
-
main, then add the "review-merge" label.
|
54
56
|
MSG
|
55
57
|
|
56
58
|
exit 1
|
57
59
|
end
|
58
60
|
else
|
59
|
-
new_timestamp = Time.at(now).utc.strftime('%Y%m%d%H%M%S')
|
60
|
-
new_migration_name = "#{new_timestamp}#{migration_name_base}"
|
61
|
-
subprocess('git', 'mv', path, "#{MIGRATIONS_DIR}#{new_migration_name}")
|
62
61
|
# Add 120s so the new migrations maintain the same order and provides
|
63
62
|
# room between the migrations to inject new ones.
|
64
63
|
now += 120
|
64
|
+
|
65
|
+
new_timestamp = Time.at(now, in: 'Z').strftime(TIME_FORMAT)
|
66
|
+
new_migration_name = "#{new_timestamp}#{migration_name_base}"
|
67
|
+
subprocess('git', 'mv', path, "#{MIGRATIONS_DIR}#{new_migration_name}")
|
65
68
|
end
|
66
69
|
end
|
67
70
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-rebase-migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pioneer Valley Books
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -39,7 +39,7 @@ description: |
|
|
39
39
|
## Installation
|
40
40
|
|
41
41
|
```console
|
42
|
-
$ bundle add rebase-migrations --group=development,test
|
42
|
+
$ bundle add rails-rebase-migrations --group=development,test
|
43
43
|
```
|
44
44
|
|
45
45
|
## Scenario
|
@@ -78,7 +78,7 @@ description: |
|
|
78
78
|
|
79
79
|
To skip a specific migration files from the `--check` include `_skip_rebase` in
|
80
80
|
its filename.
|
81
|
-
email:
|
81
|
+
email:
|
82
82
|
executables:
|
83
83
|
- rebase-migrations
|
84
84
|
extensions: []
|
@@ -91,7 +91,7 @@ licenses:
|
|
91
91
|
- MIT
|
92
92
|
metadata:
|
93
93
|
rubygems_mfa_required: 'true'
|
94
|
-
post_install_message:
|
94
|
+
post_install_message:
|
95
95
|
rdoc_options: []
|
96
96
|
require_paths:
|
97
97
|
- lib
|
@@ -99,15 +99,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
99
|
requirements:
|
100
100
|
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '3.
|
102
|
+
version: '3.2'
|
103
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
104
|
requirements:
|
105
105
|
- - ">="
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
|
-
rubygems_version: 3.3
|
110
|
-
signing_key:
|
109
|
+
rubygems_version: 3.5.3
|
110
|
+
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: Rebase Rails migrations to be the latest
|
113
113
|
test_files: []
|