pronto-rails_migrations_annotated 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5270eebfc0ad05c95f238584e149069712818b382a49cb42f7efbe0d300e631
4
- data.tar.gz: c44948d8bd1d701e5a737c3c8c77f604135b3e6d4984bd3e5a96cd95a272d933
3
+ metadata.gz: 89475a6adfbe75efa5ddedde4bf3a3903fa0af08a785d87a879e41f1cee58736
4
+ data.tar.gz: 19a2822864b7098ea985950b20a25980fc8ef4139d82172a6734eea1041941fc
5
5
  SHA512:
6
- metadata.gz: 47a6007b846b61c7dc51b32e839c7e31d743e40070a92c2155d22cffff3580843cb3d628c130f1b5a22033590004eb385282d6a9455a9590c8e24770a0160a18
7
- data.tar.gz: 115d1367976f343abb9167f43bde15a8096500ce849fb4b0699cad3b43b1bc56d7070a61d5eee73cb9ae2651b3cf658116425b2fe5eda9a4b99a59ecc7d4f503
6
+ metadata.gz: 5a945a8d9e39a13b05826b34766efbdd634ce3529f7e937987e78933152d3fa1e9752df40debc0f82d83664a703c389df33975617009c9bb601c11bbb5e4eb50
7
+ data.tar.gz: 123f8d704e85d0748e1abea9d2bcc491fd2d2d788a4f18fddbe6e7a0a68fe1fc30212c13725e3fa0b5936d6b428657e92871990f92f767a40802ff4e4b96d5ac
data/Gemfile.lock CHANGED
@@ -1,61 +1,45 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pronto-rails_migrations_annotated (0.0.4)
4
+ pronto-rails_migrations_annotated (0.0.6)
5
5
  pronto (~> 0.11)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.8.0)
11
- public_suffix (>= 2.0.2, < 5.0)
10
+ addressable (2.8.6)
11
+ public_suffix (>= 2.0.2, < 6.0)
12
12
  ast (2.4.2)
13
13
  diff-lcs (1.4.4)
14
- faraday (1.8.0)
15
- faraday-em_http (~> 1.0)
16
- faraday-em_synchrony (~> 1.0)
17
- faraday-excon (~> 1.1)
18
- faraday-httpclient (~> 1.0.1)
19
- faraday-net_http (~> 1.0)
20
- faraday-net_http_persistent (~> 1.1)
21
- faraday-patron (~> 1.0)
22
- faraday-rack (~> 1.0)
23
- multipart-post (>= 1.2, < 3)
24
- ruby2_keywords (>= 0.0.4)
25
- faraday-em_http (1.0.0)
26
- faraday-em_synchrony (1.0.0)
27
- faraday-excon (1.1.0)
28
- faraday-httpclient (1.0.1)
29
- faraday-net_http (1.0.1)
30
- faraday-net_http_persistent (1.2.0)
31
- faraday-patron (1.0.0)
32
- faraday-rack (1.0.0)
33
- gitlab (4.17.0)
34
- httparty (~> 0.18)
35
- terminal-table (~> 1.5, >= 1.5.1)
36
- httparty (0.20.0)
37
- mime-types (~> 3.0)
14
+ faraday (2.9.0)
15
+ faraday-net_http (>= 2.0, < 3.2)
16
+ faraday-net_http (3.1.0)
17
+ net-http
18
+ gitlab (4.19.0)
19
+ httparty (~> 0.20)
20
+ terminal-table (>= 1.5.1)
21
+ httparty (0.21.0)
22
+ mini_mime (>= 1.0.0)
38
23
  multi_xml (>= 0.5.2)
39
- mime-types (3.4.1)
40
- mime-types-data (~> 3.2015)
41
- mime-types-data (3.2021.1115)
24
+ mini_mime (1.1.5)
42
25
  multi_xml (0.6.0)
43
- multipart-post (2.1.1)
44
- octokit (4.21.0)
45
- faraday (>= 0.9)
46
- sawyer (~> 0.8.0, >= 0.5.3)
26
+ net-http (0.4.1)
27
+ uri
28
+ octokit (7.2.0)
29
+ faraday (>= 1, < 3)
30
+ sawyer (~> 0.9)
47
31
  parallel (1.21.0)
48
32
  parser (3.0.2.0)
49
33
  ast (~> 2.4.1)
50
- pronto (0.11.0)
51
- gitlab (~> 4.4, >= 4.4.0)
52
- httparty (>= 0.13.7)
53
- octokit (~> 4.7, >= 4.7.0)
34
+ pronto (0.11.2)
35
+ gitlab (>= 4.4.0, < 5.0)
36
+ httparty (>= 0.13.7, < 1.0)
37
+ octokit (>= 4.7.0, < 8.0)
54
38
  rainbow (>= 2.2, < 4.0)
55
- rexml (~> 3.2)
56
- rugged (>= 0.23.0, < 1.1.0)
39
+ rexml (>= 3.2.5, < 4.0)
40
+ rugged (>= 0.23.0, < 2.0)
57
41
  thor (>= 0.20.3, < 2.0)
58
- public_suffix (4.0.6)
42
+ public_suffix (5.0.4)
59
43
  rainbow (3.0.0)
60
44
  rake (13.0.6)
61
45
  regexp_parser (2.1.1)
@@ -92,17 +76,18 @@ GEM
92
76
  rubocop-rspec (2.6.0)
93
77
  rubocop (~> 1.19)
94
78
  ruby-progressbar (1.11.0)
95
- ruby2_keywords (0.0.5)
96
- rugged (1.0.1)
97
- sawyer (0.8.2)
79
+ rugged (1.7.1)
80
+ sawyer (0.9.2)
98
81
  addressable (>= 2.3.5)
99
- faraday (> 0.8, < 2.0)
100
- terminal-table (1.8.0)
101
- unicode-display_width (~> 1.1, >= 1.1.1)
102
- thor (1.1.0)
82
+ faraday (>= 0.17.3, < 3)
83
+ terminal-table (3.0.2)
84
+ unicode-display_width (>= 1.1.1, < 3)
85
+ thor (1.3.0)
103
86
  unicode-display_width (1.8.0)
87
+ uri (0.13.0)
104
88
 
105
89
  PLATFORMS
90
+ arm64-darwin-22
106
91
  x86_64-darwin-21
107
92
 
108
93
  DEPENDENCIES
@@ -115,4 +100,4 @@ DEPENDENCIES
115
100
  rubocop-rspec
116
101
 
117
102
  BUNDLED WITH
118
- 2.2.31
103
+ 2.3.10
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Pronto
4
4
  module RailsMigrationsAnnotatedVersion
5
- VERSION = "0.0.4"
5
+ VERSION = "0.0.6"
6
6
  end
7
7
  end
@@ -25,7 +25,9 @@ module Pronto
25
25
  private
26
26
 
27
27
  def add_message_at_patch(patches, message, level = :warning, line: :first)
28
- patches = [patches] unless patches.is_a?(Array)
28
+ patches = [patches].compact unless patches.is_a?(Array)
29
+ raise "Patch not found for message (#{message.inspect})" if patches.empty?
30
+
29
31
  patches.each do |patch|
30
32
  target_line = case line
31
33
  when :first then patch.added_lines.first || patch.lines.first
@@ -97,7 +99,7 @@ module Pronto
97
99
  end
98
100
 
99
101
  def check_structure_migration_version_numbers
100
- return unless migration_patches.any?
102
+ # return unless migration_patches.any?
101
103
 
102
104
  structure_file_name = "db/structure.sql"
103
105
  return if !File.exist?(structure_file_name) || gitignored?(structure_file_name)
@@ -108,7 +110,7 @@ module Pronto
108
110
  check_structure_versions_present(versions_from_schema)
109
111
  check_structure_migration_missing
110
112
 
111
- check_structure_versions_syntax(versions_from_schema)
113
+ check_structure_versions_syntax(versions_from_schema) if versions_from_schema.any?
112
114
  check_structure_versions_sorted(versions_from_schema)
113
115
  check_structure_ending(structure_file_lines)
114
116
  end
@@ -122,28 +124,51 @@ module Pronto
122
124
  "Migration #{wrong_version} is missing from structure.sql", :error)
123
125
  end
124
126
 
125
- return if structure_patches.any? || found_missing_migration
127
+ return if structure_patches.any? || found_missing_migration || migration_patches.none?
126
128
 
127
129
  add_message_at_patch(migration_patches, "Migration file detected, but no changes in structure.sql")
128
130
  end
129
131
 
130
132
  def check_structure_migration_missing
131
133
  structure_patches.each do |patch|
134
+ next if patch.delta.old_file[:oid] == "0000000000000000000000000000000000000000" # new structure.sql file
135
+
136
+ triggered = false
132
137
  patch.added_lines.select { |line| line.content.match?(migration_line_regex) }.each do |line|
133
138
  version = line.content.match(migration_line_regex)[:version]
134
139
  next if migration_version_numbers.include?(version)
135
140
  next if line.content.end_with?(",\n") &&
136
141
  patch.deleted_lines.any? { |del| del.content.include?("#{version}');") }
137
142
 
143
+ triggered = true
138
144
  add_message_at_patch(patch, "Migration #{version} is not present in this changeset", :error, line: line)
139
145
  end
146
+
147
+ if !triggered && migration_version_numbers.none?
148
+ add_message_at_patch(patch, "structure.sql changed without migrations", :error, line: patch.lines.first)
149
+ end
140
150
  end
141
151
  end
142
152
 
143
153
  def check_structure_versions_sorted(versions_from_schema)
144
154
  return if versions_from_schema == versions_from_schema.sort
155
+ return if versions_from_schema == versions_from_schema.sort.reverse
156
+
157
+ # guess sort order by lower offending migrations count
158
+ offending = [
159
+ versions_from_schema.each_cons(2).select { |(a, b)| a > b }, # if ascending
160
+ versions_from_schema.each_cons(2).select { |(a, b)| a < b } # if sort is desc
161
+ ].min_by(&:size).flat_map { |pair| pair.map { |line| line.gsub(/[^0-9]+/, "") } }
162
+
163
+ if structure_patches.none?
164
+ puts "WARNING: structure.sql migrations are not sorted (not in changes, offending #{offending.join(', ')})"
165
+ return
166
+ end
167
+
168
+ offending_regex = Regexp.union(offending)
145
169
 
146
170
  add_message_at_patch(
171
+ structure_patches.first { |patch| patch.lines.any? { |line| line.content.match?(offending_regex) } } ||
147
172
  structure_patches.first { |patch| patch.lines.any? { |line| line.content.match?(migration_line_regex) } },
148
173
  "Migration versions must be sorted and have correct syntax"
149
174
  )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pronto-rails_migrations_annotated
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasily Fedoseyev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-17 00:00:00.000000000 Z
11
+ date: 2024-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pronto
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  - !ruby/object:Gem::Version
65
65
  version: '0'
66
66
  requirements: []
67
- rubygems_version: 3.0.9
67
+ rubygems_version: 3.4.10
68
68
  signing_key:
69
69
  specification_version: 4
70
70
  summary: Pronto runner to check rails migrations to be separate from other code, but