rails-rebase-migrations 1.0.0 → 1.1.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/{rebase_migrations.rb → rails_rebase_migrations.rb} +19 -16
 - metadata +10 -10
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: f79db527980388ea6c6f5698697f2f66e4c4be9b41a1ec913882b8f189c7a0bd
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: e67332a3333de2cbeb10fac6f9c38369f3eed6105b6ad8a9ec3434299e05a063
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: c216288bd6e547687f6aeff84ad7d3bb3f3bce2d636179a5a838eb68ea18910470a50d3bbdbabdc49b4f236c837f80e5b0c7912bd154c0bdcf0f99a11d3d72b1
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: cced489ea2630bd3f5abbc01176dbf856602374f59d6416fb4f46ffc0f3085a5807c372ba1818014b472eff5d0312428d0f20a2ef9cce2acff6bf50f36c0b49c
         
     | 
| 
         @@ -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).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. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.1.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-04 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,20 +78,20 @@ 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: []
         
     | 
| 
       85 
85 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       86 
86 
     | 
    
         
             
            files:
         
     | 
| 
       87 
87 
     | 
    
         
             
            - bin/rebase-migrations
         
     | 
| 
       88 
     | 
    
         
            -
            - lib/ 
     | 
| 
      
 88 
     | 
    
         
            +
            - lib/rails_rebase_migrations.rb
         
     | 
| 
       89 
89 
     | 
    
         
             
            homepage: https://github.com/Pioneer-Valley-Books/rebase-migrations
         
     | 
| 
       90 
90 
     | 
    
         
             
            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: []
         
     |