verbose_migrations 0.0.1 → 1.0.1
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/CHANGELOG.md +8 -0
- data/README.md +100 -13
- data/lib/verbose_migrations/ext.rb +22 -0
- data/lib/verbose_migrations/railtie.rb +8 -0
- data/lib/verbose_migrations/version.rb +1 -1
- data/lib/verbose_migrations.rb +7 -2
- metadata +51 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46016287293e9f2266c8b54d6a517502c5574aef77538f1a1fd40328b91566eb
|
4
|
+
data.tar.gz: 3c73fac2184feaa70d1fc86697bddba6e7b86143943152ea55dadc9b1ed5f4db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83c379ae1c1fc8cc7cb1163253ce09740b627b10700a75997d242d0a7e11874e17fbff95ac6075d1646754904cef83727dbded3f636623bb0dbc4b268338b6f5
|
7
|
+
data.tar.gz: 8c4e5eb736d08ad411de79d987e7f4333a90070b3e5c138b23aaa6422d195323ef5bb6c3bc089f618073b80a47cb522a9d8e117b5b7355cf0bfff3fa087d2ede
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,31 +1,118 @@
|
|
1
|
-
#
|
1
|
+
# verbose_migrations
|
2
2
|
|
3
|
-
|
3
|
+
[](https://github.com/keygen-sh/verbose_migrations/actions)
|
4
|
+
[](https://badge.fury.io/rb/verbose_migrations)
|
4
5
|
|
5
|
-
|
6
|
+
Enable verbose logging for Active Record migrations, regardless of configured
|
7
|
+
log level. Monitor query speed, query execution, and overall progress when
|
8
|
+
executing long running or otherwise risky migrations.
|
9
|
+
|
10
|
+
This gem was extracted from [Keygen](https://keygen.sh).
|
11
|
+
|
12
|
+
Sponsored by:
|
13
|
+
|
14
|
+
<a href="https://keygen.sh?ref=verbose_migrations">
|
15
|
+
<div>
|
16
|
+
<img src="https://keygen.sh/images/logo-pill.png" width="200" alt="Keygen">
|
17
|
+
</div>
|
18
|
+
</a>
|
19
|
+
|
20
|
+
_A fair source software licensing and distribution API._
|
6
21
|
|
7
22
|
## Installation
|
8
23
|
|
9
|
-
|
24
|
+
Add this line to your application's `Gemfile`:
|
10
25
|
|
11
|
-
|
26
|
+
```ruby
|
27
|
+
gem 'verbose_migrations'
|
28
|
+
```
|
12
29
|
|
13
|
-
|
30
|
+
And then execute:
|
14
31
|
|
15
|
-
|
32
|
+
```bash
|
33
|
+
$ bundle
|
34
|
+
```
|
16
35
|
|
17
|
-
|
36
|
+
Or install it yourself as:
|
37
|
+
|
38
|
+
```bash
|
39
|
+
$ gem install verbose_migrations
|
40
|
+
```
|
18
41
|
|
19
42
|
## Usage
|
20
43
|
|
21
|
-
|
44
|
+
Use the `verbose!` class method to enable debug logging. It accepts an optional log
|
45
|
+
`level:` and `logger:`.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
class SeedTagsFromPosts < ActiveRecord::Migration[7.2]
|
49
|
+
disable_ddl_transaction!
|
50
|
+
verbose!
|
51
|
+
|
52
|
+
def up
|
53
|
+
update_count = nil
|
54
|
+
batch_count = 0
|
55
|
+
|
56
|
+
until update_count == 0
|
57
|
+
batch_count += 1
|
58
|
+
update_count = exec_update(<<~SQL.squish, batch_count:, batch_size: 10_000)
|
59
|
+
WITH batch AS (
|
60
|
+
SELECT id, unnest(tags) AS tag_name
|
61
|
+
FROM posts
|
62
|
+
WHERE tags IS NOT NULL
|
63
|
+
LIMIT :batch_size
|
64
|
+
), inserted_tags AS (
|
65
|
+
INSERT INTO tags (name)
|
66
|
+
SELECT DISTINCT tag_name
|
67
|
+
FROM batch
|
68
|
+
ON CONFLICT (name) DO NOTHING
|
69
|
+
RETURNING id, name
|
70
|
+
)
|
71
|
+
INSERT INTO post_tags (post_id, tag_id)
|
72
|
+
SELECT batch.id, tags.id
|
73
|
+
FROM batch
|
74
|
+
JOIN tags ON tags.name = batch.tag_name
|
75
|
+
/* batch=:batch_count */
|
76
|
+
SQL
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
22
80
|
|
23
|
-
|
81
|
+
```
|
24
82
|
|
25
|
-
|
83
|
+
Before, you have a black box:
|
26
84
|
|
27
|
-
|
85
|
+
```
|
86
|
+
== 20240817010101 SeedTagsFromPosts: migrating ================================
|
87
|
+
== 20240817010101 SeedTagsFromPosts: migrated (42.0312s) =======================
|
88
|
+
```
|
89
|
+
|
90
|
+
After, you see progress:
|
91
|
+
|
92
|
+
```
|
93
|
+
== 20240817010101 SeedTagsFromPosts: migrating ================================
|
94
|
+
==> DEBUG -- : (2.2ms) WITH batch AS ( SELECT id, unnest(tags) AS tag_name FROM posts WHERE tags IS NOT NULL LIMIT 10000 ), inserted_tags AS ( INSERT INTO tags (name) SELECT DISTINCT tag_name FROM batch ON CONFLICT (name) DO NOTHING RETURNING id, name ) INSERT INTO post_tags (post_id, tag_id) SELECT batch.id, tags.id FROM batch JOIN tags ON tags.name = batch.tag_name /* batch=1 */
|
95
|
+
==> DEBUG -- : (1.1ms) WITH batch AS ( SELECT id, unnest(tags) AS tag_name FROM posts WHERE tags IS NOT NULL LIMIT 10000 ), inserted_tags AS ( INSERT INTO tags (name) SELECT DISTINCT tag_name FROM batch ON CONFLICT (name) DO NOTHING RETURNING id, name ) INSERT INTO post_tags (post_id, tag_id) SELECT batch.id, tags.id FROM batch JOIN tags ON tags.name = batch.tag_name /* batch=2 */
|
96
|
+
==> DEBUG -- : (1.3ms) WITH batch AS ( SELECT id, unnest(tags) AS tag_name FROM posts WHERE tags IS NOT NULL LIMIT 10000 ), inserted_tags AS ( INSERT INTO tags (name) SELECT DISTINCT tag_name FROM batch ON CONFLICT (name) DO NOTHING RETURNING id, name ) INSERT INTO post_tags (post_id, tag_id) SELECT batch.id, tags.id FROM batch JOIN tags ON tags.name = batch.tag_name /* batch=3 */
|
97
|
+
==> DEBUG -- : (1.7ms) ...
|
98
|
+
== 20240817010101 SeedTagsFromPosts: migrated (42.0312s) =======================
|
99
|
+
```
|
100
|
+
|
101
|
+
## Supported Rubies
|
102
|
+
|
103
|
+
**`verbose_migrations` supports Ruby 3.1 and above.** We encourage you to upgrade
|
104
|
+
if you're on an older version. Ruby 3 provides a lot of great features, like
|
105
|
+
better pattern matching and a new shorthand hash syntax.
|
106
|
+
|
107
|
+
## Is it any good?
|
108
|
+
|
109
|
+
Yes.
|
28
110
|
|
29
111
|
## Contributing
|
30
112
|
|
31
|
-
|
113
|
+
If you have an idea, or have discovered a bug, please open an issue or create a
|
114
|
+
pull request.
|
115
|
+
|
116
|
+
## License
|
117
|
+
|
118
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module VerboseMigrations
|
4
|
+
module MigrationExtension
|
5
|
+
cattr_accessor :verbose_logger, default: nil
|
6
|
+
cattr_accessor :verbosity, default: nil
|
7
|
+
|
8
|
+
def verbose? = verbosity.present? && verbose_logger.present?
|
9
|
+
def verbose!(logger: ActiveRecord::Base.logger, level: Logger::DEBUG)
|
10
|
+
self.verbose_logger = logger
|
11
|
+
self.verbosity = level
|
12
|
+
end
|
13
|
+
|
14
|
+
def migrate(...)
|
15
|
+
verbosity_was, verbose_logger.level = verbose_logger.level, verbosity if verbose?
|
16
|
+
|
17
|
+
super
|
18
|
+
ensure
|
19
|
+
verbose_logger.level = verbosity_was if verbose?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/verbose_migrations.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_record'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
require_relative 'verbose_migrations/ext'
|
3
8
|
require_relative 'verbose_migrations/version'
|
9
|
+
require_relative 'verbose_migrations/railtie'
|
4
10
|
|
5
|
-
module VerboseMigrations
|
6
|
-
end
|
11
|
+
module VerboseMigrations; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: verbose_migrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zeke Gabrielse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,9 +38,51 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: transition_through
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: prism
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Enable verbose logging for Active Record migrations, regardless of configured
|
84
|
+
log level. Monitor query speed, query execution, and overall progress when executing
|
85
|
+
long running or otherwise risky migrations.
|
44
86
|
email:
|
45
87
|
- oss@keygen.sh
|
46
88
|
executables: []
|
@@ -53,6 +95,8 @@ files:
|
|
53
95
|
- README.md
|
54
96
|
- SECURITY.md
|
55
97
|
- lib/verbose_migrations.rb
|
98
|
+
- lib/verbose_migrations/ext.rb
|
99
|
+
- lib/verbose_migrations/railtie.rb
|
56
100
|
- lib/verbose_migrations/version.rb
|
57
101
|
homepage: https://github.com/keygen-sh/verbose_migrations
|
58
102
|
licenses:
|
@@ -76,5 +120,6 @@ requirements: []
|
|
76
120
|
rubygems_version: 3.4.13
|
77
121
|
signing_key:
|
78
122
|
specification_version: 4
|
79
|
-
summary:
|
123
|
+
summary: Enable verbose logging for Active Record migrations, regardless of configured
|
124
|
+
log level, to monitor query speed and execution.
|
80
125
|
test_files: []
|