migration_history 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 939d54d3a47ba4b2e86591968420ba616f74e52f588a961eb593204ad3d80009
4
+ data.tar.gz: '0994b62be7cc54dcd8a627a134a020810ed416c6024ec5e29d3152904879b3d9'
5
+ SHA512:
6
+ metadata.gz: 84fe1b9580d4aee9cd1338118db2e8de377572bc0402a8af025921d1bf3270300daf91925bf9106fb33bd15eda5d09e5aa7dba3bfbbc5d23f7ecc5279eedad32
7
+ data.tar.gz: e0f7e0a0cf8cd3beeacabceb9aa464ecdb28d6e417478ef612a7502365f3919f341173c5bba7f007303508400173122cb116f3f8be73b265d9060d99dec55155
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
13
+ .vscode
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,291 @@
1
+ AllCops:
2
+ # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
3
+ # to ignore them, so only the ones explicitly set in this file are enabled.
4
+ DisabledByDefault: true
5
+ SuggestExtensions: false
6
+ Exclude:
7
+
8
+ # Prefer &&/|| over and/or.
9
+ Style/AndOr:
10
+ Enabled: true
11
+
12
+ Layout/ClosingHeredocIndentation:
13
+ Enabled: true
14
+
15
+ Layout/ClosingParenthesisIndentation:
16
+ Enabled: true
17
+
18
+ # Align comments with method definitions.
19
+ Layout/CommentIndentation:
20
+ Enabled: true
21
+
22
+ Layout/DefEndAlignment:
23
+ Enabled: true
24
+
25
+ Layout/ElseAlignment:
26
+ Enabled: true
27
+
28
+ # Align `end` with the matching keyword or starting expression except for
29
+ # assignments, where it should be aligned with the LHS.
30
+ Layout/EndAlignment:
31
+ Enabled: true
32
+ EnforcedStyleAlignWith: variable
33
+ AutoCorrect: true
34
+
35
+ Layout/EndOfLine:
36
+ Enabled: true
37
+
38
+ Layout/EmptyLineAfterMagicComment:
39
+ Enabled: true
40
+
41
+ Layout/EmptyLinesAroundAccessModifier:
42
+ Enabled: true
43
+ EnforcedStyle: only_before
44
+
45
+ Layout/EmptyLinesAroundBlockBody:
46
+ Enabled: true
47
+
48
+ # In a regular class definition, no empty lines around the body.
49
+ Layout/EmptyLinesAroundClassBody:
50
+ Enabled: true
51
+
52
+ # In a regular method definition, no empty lines around the body.
53
+ Layout/EmptyLinesAroundMethodBody:
54
+ Enabled: true
55
+
56
+ # In a regular module definition, no empty lines around the body.
57
+ Layout/EmptyLinesAroundModuleBody:
58
+ Enabled: true
59
+
60
+ # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
61
+ Style/HashSyntax:
62
+ Enabled: true
63
+ EnforcedShorthandSyntax: either
64
+
65
+ # Method definitions after `private` or `protected` isolated calls need one
66
+ # extra level of indentation.
67
+ Layout/IndentationConsistency:
68
+ Enabled: true
69
+ EnforcedStyle: indented_internal_methods
70
+ Exclude:
71
+ - '**/*.md'
72
+
73
+ # Two spaces, no tabs (for indentation).
74
+ Layout/IndentationWidth:
75
+ Enabled: true
76
+
77
+ Layout/LeadingCommentSpace:
78
+ Enabled: true
79
+
80
+ Layout/SpaceAfterColon:
81
+ Enabled: true
82
+
83
+ Layout/SpaceAfterComma:
84
+ Enabled: true
85
+
86
+ Layout/SpaceAfterSemicolon:
87
+ Enabled: true
88
+
89
+ Layout/SpaceAroundEqualsInParameterDefault:
90
+ Enabled: true
91
+
92
+ Layout/SpaceAroundKeyword:
93
+ Enabled: true
94
+
95
+ Layout/SpaceAroundOperators:
96
+ Enabled: true
97
+
98
+ Layout/SpaceBeforeComma:
99
+ Enabled: true
100
+
101
+ Layout/SpaceBeforeComment:
102
+ Enabled: true
103
+
104
+ Layout/SpaceBeforeFirstArg:
105
+ Enabled: true
106
+
107
+ Style/DefWithParentheses:
108
+ Enabled: true
109
+
110
+ # Defining a method with parameters needs parentheses.
111
+ Style/MethodDefParentheses:
112
+ Enabled: true
113
+
114
+ Style/ExplicitBlockArgument:
115
+ Enabled: true
116
+
117
+ Style/FrozenStringLiteralComment:
118
+ Enabled: true
119
+ EnforcedStyle: always
120
+ Exclude:
121
+ - 'actionview/test/**/*.builder'
122
+ - 'actionview/test/**/*.ruby'
123
+ - 'actionpack/test/**/*.builder'
124
+ - 'actionpack/test/**/*.ruby'
125
+ - 'activestorage/db/migrate/**/*.rb'
126
+ - 'activestorage/db/update_migrate/**/*.rb'
127
+ - 'actionmailbox/db/migrate/**/*.rb'
128
+ - 'actiontext/db/migrate/**/*.rb'
129
+ - '**/*.md'
130
+
131
+ Style/MapToHash:
132
+ Enabled: true
133
+
134
+ Style/RedundantFreeze:
135
+ Enabled: true
136
+
137
+ # Use `foo {}` not `foo{}`.
138
+ Layout/SpaceBeforeBlockBraces:
139
+ Enabled: true
140
+
141
+ # Use `foo { bar }` not `foo {bar}`.
142
+ Layout/SpaceInsideBlockBraces:
143
+ Enabled: true
144
+ EnforcedStyleForEmptyBraces: space
145
+
146
+ # Use `{ a: 1 }` not `{a:1}`.
147
+ Layout/SpaceInsideHashLiteralBraces:
148
+ Enabled: true
149
+
150
+ Layout/SpaceInsideParens:
151
+ Enabled: true
152
+
153
+ # Check quotes usage according to lint rule below.
154
+ Style/StringLiterals:
155
+ Enabled: true
156
+ EnforcedStyle: double_quotes
157
+
158
+ # Detect hard tabs, no hard tabs.
159
+ Layout/IndentationStyle:
160
+ Enabled: true
161
+
162
+ # Empty lines should not have any spaces.
163
+ Layout/TrailingEmptyLines:
164
+ Enabled: true
165
+
166
+ # No trailing whitespace.
167
+ Layout/TrailingWhitespace:
168
+ Enabled: true
169
+
170
+ # Use quotes for string literals when they are enough.
171
+ Style/RedundantPercentQ:
172
+ Enabled: true
173
+
174
+ Lint/NestedMethodDefinition:
175
+ Enabled: true
176
+
177
+ Lint/AmbiguousOperator:
178
+ Enabled: true
179
+
180
+ Lint/AmbiguousRegexpLiteral:
181
+ Enabled: true
182
+
183
+ Lint/Debugger:
184
+ Enabled: true
185
+ DebuggerRequires:
186
+ - debug
187
+
188
+ Lint/DuplicateRequire:
189
+ Enabled: true
190
+
191
+ Lint/DuplicateMagicComment:
192
+ Enabled: true
193
+
194
+ Lint/DuplicateMethods:
195
+ Enabled: true
196
+
197
+ Lint/ErbNewArguments:
198
+ Enabled: true
199
+
200
+ Lint/EnsureReturn:
201
+ Enabled: true
202
+
203
+ Lint/MissingCopEnableDirective:
204
+ Enabled: true
205
+
206
+ # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
207
+ Lint/RequireParentheses:
208
+ Enabled: true
209
+
210
+ Lint/RedundantCopDisableDirective:
211
+ Enabled: true
212
+
213
+ Lint/RedundantCopEnableDirective:
214
+ Enabled: true
215
+
216
+ Lint/RedundantRequireStatement:
217
+ Enabled: true
218
+
219
+ Lint/RedundantStringCoercion:
220
+ Enabled: true
221
+
222
+ Lint/RedundantSafeNavigation:
223
+ Enabled: true
224
+
225
+ Lint/UriEscapeUnescape:
226
+ Enabled: true
227
+
228
+ Lint/UselessAssignment:
229
+ Enabled: true
230
+
231
+ Lint/DeprecatedClassMethods:
232
+ Enabled: true
233
+
234
+ Lint/InterpolationCheck:
235
+ Enabled: true
236
+ Exclude:
237
+ - '**/test/**/*'
238
+
239
+ Lint/SafeNavigationChain:
240
+ Enabled: true
241
+
242
+ Style/EvalWithLocation:
243
+ Enabled: true
244
+ Exclude:
245
+ - '**/test/**/*'
246
+
247
+ Style/ParenthesesAroundCondition:
248
+ Enabled: true
249
+
250
+ Style/HashTransformKeys:
251
+ Enabled: true
252
+
253
+ Style/HashTransformValues:
254
+ Enabled: true
255
+
256
+ Style/RedundantBegin:
257
+ Enabled: true
258
+
259
+ Style/RedundantReturn:
260
+ Enabled: true
261
+ AllowMultipleReturnValues: true
262
+
263
+ Style/RedundantRegexpEscape:
264
+ Enabled: true
265
+
266
+ Style/Semicolon:
267
+ Enabled: true
268
+ AllowAsExpressionSeparator: true
269
+
270
+ # Prefer Foo.method over Foo::method
271
+ Style/ColonMethodCall:
272
+ Enabled: true
273
+
274
+ Style/TrivialAccessors:
275
+ Enabled: true
276
+
277
+ # Prefer a = b || c over a = b ? b : c
278
+ Style/RedundantCondition:
279
+ Enabled: true
280
+
281
+ Style/RedundantDoubleSplatHashBraces:
282
+ Enabled: true
283
+
284
+ Style/OpenStructUse:
285
+ Enabled: true
286
+
287
+ Style/ArrayIntersect:
288
+ Enabled: true
289
+
290
+ Style/KeywordArgumentsMerging:
291
+ Enabled: true
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.10
7
+ before_install: gem install bundler -v 1.17.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sh07e1916@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in migration_history.gemspec
8
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 a5-stable
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # MigrationHistory
2
+
3
+ `migration_history` is a gem that helps track migration history in Rails projects. It provides a simple way to see when tables and columns were added, along with other details from your migration files. You can view this information in either CLI or HTML format.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'migration_history'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install migration_history
20
+
21
+ ## Usage
22
+
23
+ ### Track When a Table or Column Was Added with Filters
24
+ With the filter command, you can query the migration history to find out when a specific table or column was added to your database. This allows you to focus on specific changes to your schema, such as the creation of a table or the addition of a column.
25
+
26
+ Example: Filter by Table Name
27
+ To find out when a specific table, such as users, was created, you can filter the migration history by table name. For example:
28
+ ```ruby
29
+ bundle exec migration_history filter --table users
30
+ ```
31
+ Example Output:
32
+ ```ruby
33
+ ClassName: AddUsersTable, Timestamp: 2020-01-02 12:30:45
34
+ ```
35
+
36
+ Example: Filter by Table Name and Column Name
37
+ To find out when a specific column, such as email, was added to a table, you can filter the migration history by table and column name. For example:
38
+ ```ruby
39
+ bundle exec migration_history filter --table users --column email
40
+ ```
41
+ Example Output:
42
+ ```ruby
43
+ ClassName: AddEmailColumnToUsersTable, Timestamp: 2020-01-02 12:30:45
44
+ ```
45
+
46
+ Example: No Filter, All migration history
47
+ To view the entire migration history in the terminal:
48
+
49
+ ```ruby
50
+ bundle exec migration_history all
51
+ ```
52
+
53
+ ### HTML and JSON Output
54
+ You can have more readable output by using the `--format` option to output the result in HTML or JSON formats.
55
+
56
+ Example: with HTML Output
57
+ ```ruby
58
+ bundle exec migration_history all --format=html
59
+ ```
60
+
61
+ By default, the output file name will be `migration_history.html`. You can specify the output file name by using the `--output` option.
62
+ The generated HTML file looks like this:
63
+ ![sample HTML file image created by migration_history](migration_history_sample.png)
64
+ In this HTML file, you can filter the migration history by table name, column name, keyword search, target table, action, and date range.
65
+
66
+ Example: with JSON Output
67
+ ```ruby
68
+ bundle exec migration_history all --format=json
69
+ ```
70
+
71
+ ## Development
72
+
73
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
74
+
75
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/a5-stable/migration_history. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
80
+
81
+ ## License
82
+
83
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
84
+
85
+ ## Code of Conduct
86
+
87
+ Everyone interacting in the MigrationHistory project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/a5-stable/migration_history/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "migration_history"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "migration_history"
5
+
6
+ MigrationHistory::CLI.start
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+ require "erb"
5
+ require "migration_history"
6
+ require "migration_history/formatter/html_formatter"
7
+ require "migration_history/formatter/json_formatter"
8
+ require "time"
9
+
10
+ module MigrationHistory
11
+ class CLI < Thor
12
+ desc "filter", "Retrieve migration history with filtering"
13
+ option :table, required: true, desc: "Table name"
14
+ option :column, required: false, desc: "Column name"
15
+ option :action, required: false, desc: "Action name"
16
+ option :output, required: false, desc: "HTML output file name"
17
+ def filter
18
+ table_name = options[:table]
19
+ column_name = options[:column]
20
+ action_name = options[:action]
21
+
22
+ result = MigrationHistory.filter(table_name, column_name, action_name)
23
+
24
+ if options[:output]
25
+ generate_html(result, options[:output])
26
+ else
27
+ result.original_result.each do |_, entry|
28
+ timestamp = Time.strptime(entry[:timestamp], "%Y%m%d%H%M%S") rescue entry[:timestamp]
29
+ puts "ClassName: #{entry[:class_name]}, Timestamp: #{timestamp}"
30
+ end
31
+ end
32
+ end
33
+
34
+ desc "all", "Retrieve all migration history"
35
+ option :format, required: false, desc: "Output format"
36
+ option :output, required: false, desc: "HTML output file name"
37
+ def all
38
+ result = MigrationHistory.all
39
+
40
+ if options[:format]
41
+ formatter = find_formatter(options[:format])
42
+ formatter.output_file_name = options[:output] if options[:output]
43
+
44
+ formatter.format(result)
45
+ puts "Output to #{formatter.output_file_name_with_extension}"
46
+ else
47
+ result.original_result.each do |_, entry|
48
+ timestamp = Time.strptime(entry[:timestamp], "%Y%m%d%H%M%S") rescue entry[:timestamp]
49
+ puts "ClassName: #{entry[:class_name]}, Timestamp: #{timestamp}"
50
+ end
51
+ end
52
+ end
53
+
54
+ private
55
+ def find_formatter(format)
56
+ Object.const_get("MigrationHistory::Formatter::#{format.capitalize}Formatter").new
57
+ rescue
58
+ raise ArgumentError, "Invalid format: #{format}, available formats: html, json"
59
+ end
60
+ end
61
+ end