migration_queries 1.0.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d841a636d5ad72e9991f1f87ed98bb4a0a1b51098a674db5dae93f5d2f94ccaa
4
- data.tar.gz: aa79169e44d9ce5adbbf1142d738d49b3aee19048f86baa82be747695b653c8a
3
+ metadata.gz: 4fe2d8b45857c284b34c0d35e9e4a16de7f5f7905e6e4b5d202ca01d2cbe15ce
4
+ data.tar.gz: 750c7da86a1ba4054250b344f9eff15a0fd26ba1334c582a9c732d1289100724
5
5
  SHA512:
6
- metadata.gz: 65e15bb1a441237afbc72d50a9206334dd7dafee4e0f4af3cbbbb949106e3e3e57088bada8464b781071177219ca366f1ffb1e34b3ef30675ce8117a09d59a27
7
- data.tar.gz: b0cecb473508ad96399022335b6ff0e9decc6951f6f7f6b82f6bdd45a7acd70733a16358a8906f4279a93d8697ba8e9240bef4f0e77798a39d8845ac640ff29c
6
+ metadata.gz: baf3884c48a8dd6948d803850b67904f0dd2198bbc40eb4c8e2992c18ef26173135abe25be30eef04ba0e9d971b57f76a653b9235100a98c6e988d1f27bcd60d
7
+ data.tar.gz: 2832d3d040c98170901f7c1001217f96ffb0846593510bff3ff40f4e18648670493445ebaab01bb70c4d749459e853e33abe274a197d44234721ddbf825f4d0b
data/README.md CHANGED
@@ -32,7 +32,6 @@ end
32
32
  =begin Migration Queries
33
33
  CREATE TABLE "example" ("id" bigserial primary key, "name" character varying, "created_at" timestamp(6) NOT NULL, "updated_at" timestamp(6) NOT NULL)
34
34
 
35
- # Migration Queries written on 2025-07-04 12:36:54 +0200
36
35
  =end
37
36
  ```
38
37
 
@@ -44,7 +43,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
44
43
 
45
44
  ## Contributing
46
45
 
47
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/migration_queries. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/migration_queries/blob/master/CODE_OF_CONDUCT.md).
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/szymonlipka/migration_queries. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/migration_queries/blob/master/CODE_OF_CONDUCT.md).
48
47
 
49
48
  ## License
50
49
 
@@ -7,19 +7,38 @@ module MigrationQueries
7
7
  # with logic to capture SQL queries executed during migrations.
8
8
  module Executer
9
9
  def execute(sql, *_args)
10
- stack_trace = caller.detect { |path| path.include?(Rails.root.to_s) && path.include?("db/migrate") }
11
- file_path = stack_trace.match(/(.+):\d+:in/)[1] if stack_trace
12
- if defined?(file_path) && file_path
13
- data_object = MigrationQueries.gatherer.queries_data_objects.detect do |data_object|
14
- data_object.file_path == file_path
15
- end || MigrationQueries::Data.new(file_path: file_path)
16
- data_object.sql_queries << sql
17
-
18
- unless MigrationQueries.gatherer.queries_data_objects.include?(data_object)
19
- MigrationQueries.gatherer.queries_data_objects << data_object
20
- end
21
- end
10
+ gather_queries(sql, caller)
22
11
  super
23
12
  end
13
+
14
+ private
15
+
16
+ def gather_queries(sql, caller)
17
+ stack_trace = detect_stack_trace(caller)
18
+ file_path = extract_file_path(stack_trace) if stack_trace
19
+ gatherer = load_gatherer
20
+ return unless defined?(file_path) && file_path
21
+
22
+ data_object = gatherer.queries_data_objects.detect do |data_object|
23
+ data_object.file_path == file_path
24
+ end || MigrationQueries::Data.new(file_path: file_path)
25
+ data_object.sql_queries << sql
26
+
27
+ return if gatherer.queries_data_objects.include?(data_object)
28
+
29
+ MigrationQueries.gatherer.queries_data_objects << data_object
30
+ end
31
+
32
+ def load_gatherer
33
+ MigrationQueries.gatherer
34
+ end
35
+
36
+ def detect_stack_trace(caller)
37
+ caller.detect { |path| path.include?(Rails.root.to_s) && path.include?("db/migrate") }
38
+ end
39
+
40
+ def extract_file_path(stack_trace)
41
+ stack_trace.match(/(.+):\d+:in/)[1]
42
+ end
24
43
  end
25
44
  end
@@ -36,7 +36,6 @@ module MigrationQueries
36
36
  sql_queries.each do |query|
37
37
  file.puts query
38
38
  end
39
- file.puts "\n# Migration Queries written on #{Time.now}"
40
39
  file.puts "=end"
41
40
  file.flush
42
41
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MigrationQueries
4
- VERSION = "1.0.0"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -1,5 +1,15 @@
1
1
  module MigrationQueries
2
2
  module Executer
3
3
  def execute: -> untyped
4
+
5
+ private
6
+
7
+ def detect_stack_trace: -> String
8
+
9
+ def extract_file_path: -> String
10
+
11
+ def gather_queries: -> untyped
12
+
13
+ def load_gatherer: -> MigrationQueries::Gatherer
4
14
  end
5
15
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: migration_queries
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Szymon Lipka
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2025-07-24 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: activerecord
@@ -59,6 +60,7 @@ metadata:
59
60
  homepage_uri: https://github.com/szymonlipka/migration_queries
60
61
  source_code_uri: https://github.com/szymonlipka/migration_queries
61
62
  changelog_uri: https://github.com/szymonlipka/migration_queries/blob/master/CHANGELOG.md
63
+ post_install_message:
62
64
  rdoc_options: []
63
65
  require_paths:
64
66
  - lib
@@ -73,7 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
75
  - !ruby/object:Gem::Version
74
76
  version: '0'
75
77
  requirements: []
76
- rubygems_version: 3.6.9
78
+ rubygems_version: 3.4.1
79
+ signing_key:
77
80
  specification_version: 4
78
81
  summary: Migrations queries for ActiveRecord
79
82
  test_files: []