verbose_migrations 1.0.0 → 1.0.1

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: 7d2c1d35a9c0ebcba2ea106766e8ed501397b3c24941c5f54c74ca028bdfa776
4
- data.tar.gz: 03ea6cc33ac78bbffc2b69c0908abe59798227dcb237a97705a957e859485e93
3
+ metadata.gz: 46016287293e9f2266c8b54d6a517502c5574aef77538f1a1fd40328b91566eb
4
+ data.tar.gz: 3c73fac2184feaa70d1fc86697bddba6e7b86143943152ea55dadc9b1ed5f4db
5
5
  SHA512:
6
- metadata.gz: 386bc10f3b9baba1a5468fc825105900223970127c6a62991fda5431cb588c614d5569dd5d78752bebe655848ee53687fd038f05b9b3feda891d4dde1bc5c436
7
- data.tar.gz: f293b5b9faf86c3965cf0487144d53a54a533ca2921a740977a23aed44a66065895f4f134ff670594e493d3a536699b2d0c7319125a83bf3576c22e9bdcc8666
6
+ metadata.gz: 83c379ae1c1fc8cc7cb1163253ce09740b627b10700a75997d242d0a7e11874e17fbff95ac6075d1646754904cef83727dbded3f636623bb0dbc4b268338b6f5
7
+ data.tar.gz: 8c4e5eb736d08ad411de79d987e7f4333a90070b3e5c138b23aaa6422d195323ef5bb6c3bc089f618073b80a47cb522a9d8e117b5b7355cf0bfff3fa087d2ede
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## v1.0.1
6
+
7
+ Fix load order: [#1](https://github.com/keygen-sh/verbose_migrations/issues/1).
8
+
5
9
  ## v1.0.0
6
10
 
7
11
  Initial release.
data/README.md CHANGED
@@ -41,14 +41,61 @@ $ gem install verbose_migrations
41
41
 
42
42
  ## Usage
43
43
 
44
+ Use the `verbose!` class method to enable debug logging. It accepts an optional log
45
+ `level:` and `logger:`.
46
+
44
47
  ```ruby
45
- class SeedTagsFromPosts < ActiveRecord::Migration[7.1]
48
+ class SeedTagsFromPosts < ActiveRecord::Migration[7.2]
49
+ disable_ddl_transaction!
46
50
  verbose!
47
51
 
48
52
  def up
49
- # ...
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
50
78
  end
51
79
  end
80
+
81
+ ```
82
+
83
+ Before, you have a black box:
84
+
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) =======================
52
99
  ```
53
100
 
54
101
  ## Supported Rubies
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VerboseMigrations
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
@@ -4,26 +4,8 @@ require 'active_support'
4
4
  require 'active_record'
5
5
  require 'logger'
6
6
 
7
+ require_relative 'verbose_migrations/ext'
7
8
  require_relative 'verbose_migrations/version'
8
9
  require_relative 'verbose_migrations/railtie'
9
10
 
10
- module VerboseMigrations
11
- module MigrationExtension
12
- cattr_accessor :verbose_logger, default: nil
13
- cattr_accessor :verbosity, default: nil
14
-
15
- def verbose? = verbosity.present? && verbose_logger.present?
16
- def verbose!(logger: ActiveRecord::Base.logger, level: Logger::DEBUG)
17
- self.verbose_logger = logger
18
- self.verbosity = level
19
- end
20
-
21
- def migrate(...)
22
- verbosity_was, verbose_logger.level = verbose_logger.level, verbosity if verbose?
23
-
24
- super
25
- ensure
26
- verbose_logger.level = verbosity_was if verbose?
27
- end
28
- end
29
- 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: 1.0.0
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-08-15 00:00:00.000000000 Z
11
+ date: 2024-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -95,6 +95,7 @@ files:
95
95
  - README.md
96
96
  - SECURITY.md
97
97
  - lib/verbose_migrations.rb
98
+ - lib/verbose_migrations/ext.rb
98
99
  - lib/verbose_migrations/railtie.rb
99
100
  - lib/verbose_migrations/version.rb
100
101
  homepage: https://github.com/keygen-sh/verbose_migrations