exwiw 0.2.3 → 0.2.4

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: db5d466378dd55180ac229c2276c4e5e228a067a69b648ed7979d142f5b12ce7
4
- data.tar.gz: 2be8b1ffe33cdaa1d9443ec7a3f36f7108f506addfbadb3fa06ac8ba312a89a8
3
+ metadata.gz: 95749db3a2093fe305a67c6caacf1b6861f791d99f70283a7fa63ce765b9f846
4
+ data.tar.gz: '087a7260b7d5cd3809fc72c8a783f408e87091e1e6bc816eab4a965e489b4404'
5
5
  SHA512:
6
- metadata.gz: 17ae95279fe11b231c50a2c0d2e2ead9adcf2db6eb3fb79f7ee54f1af816c26dae23ace12d6fa901655817b26101777af04d70fd76751c6e45bc576d99ef7503
7
- data.tar.gz: 99415623bdf900053d466d58c8a45fb1be380167a9d66cf9d265c8122c9fd6e3c96c8e48cb5e9e971e2783db595b63b1d525a850a3871e294a751263747b12b1
6
+ metadata.gz: cafb2801b708bf26124f12f6a13799f35d6b5f17ec2977fc49464ae56bb6482434bf9d1a155b176968d4f7b545f172a1fc56c3114958206da0605c426194aebf
7
+ data.tar.gz: c9c05f6da15c12ee45963d0552122310cda5a3261f210d2dbb069986751b9d245bad9661ef9ca5d8ed7fbec04afbe00e637bc9b852d0d15b0eea4429db4c6ec2
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.2.4] - 2026-05-28
6
+
7
+ ### Added
8
+
9
+ - Dump/explain queries issued against the source DB now carry an identifying comment (e.g. `/* exwiw table=shops */`) so exwiw-originated queries can be spotted in `processlist` / slow query log / `db.currentOp()` and killed by table when they run long. Added to the SELECT/EXPLAIN of the `mysql2`, `postgresql`, and `sqlite3` adapters and to MongoDB `find` (via `.comment(...)`); the `explain` subcommand's printed SQL matches the emitted form. The comment is applied only at the query-issuing boundary, so generated `insert-*` / `delete-*` files (and `to_bulk_delete` subqueries) stay comment-free, and the version is intentionally omitted to keep snapshots/diffs stable. ([#35](https://github.com/heyinc/exwiw/pull/35))
10
+
5
11
  ## [0.2.3] - 2026-05-27
6
12
 
7
13
  ### Fixed
@@ -73,7 +73,11 @@ module Exwiw
73
73
  def execute(query)
74
74
  @logger.debug(" Executing Mongo find on '#{query.collection}': filter=#{query.filter.inspect} projection=#{query.projection.inspect}")
75
75
 
76
- docs = db[query.collection].find(query.filter).projection(query.projection).to_a
76
+ docs = db[query.collection]
77
+ .find(query.filter)
78
+ .projection(query.projection)
79
+ .comment(query_comment_text("collection=#{query.collection}"))
80
+ .to_a
77
81
 
78
82
  @state[query.collection] = docs.map { |doc| doc[query.primary_key] }
79
83
 
@@ -8,14 +8,14 @@ module Exwiw
8
8
  end
9
9
 
10
10
  def execute(query_ast)
11
- sql = compile_ast(query_ast)
11
+ sql = commented_sql(query_ast)
12
12
 
13
13
  @logger.debug(" Executing SQL: \n#{sql}")
14
14
  connection.query(sql, cast: false, as: :array).to_a
15
15
  end
16
16
 
17
17
  def explain(query_ast)
18
- sql = compile_ast(query_ast)
18
+ sql = commented_sql(query_ast)
19
19
 
20
20
  @logger.debug(" Executing EXPLAIN: \n#{sql}")
21
21
  rows = connection.query("EXPLAIN #{sql}", cast: false).to_a
@@ -8,14 +8,14 @@ module Exwiw
8
8
  end
9
9
 
10
10
  def execute(query_ast)
11
- sql = compile_ast(query_ast)
11
+ sql = commented_sql(query_ast)
12
12
 
13
13
  @logger.debug(" Executing SQL: \n#{sql}")
14
14
  connection.exec(sql).values
15
15
  end
16
16
 
17
17
  def explain(query_ast)
18
- sql = compile_ast(query_ast)
18
+ sql = commented_sql(query_ast)
19
19
 
20
20
  @logger.debug(" Executing EXPLAIN: \n#{sql}")
21
21
  connection.exec("EXPLAIN #{sql}").values.map(&:first).join("\n")
@@ -8,14 +8,14 @@ module Exwiw
8
8
  end
9
9
 
10
10
  def execute(query_ast)
11
- sql = compile_ast(query_ast)
11
+ sql = commented_sql(query_ast)
12
12
 
13
13
  @logger.debug(" Executing SQL: \n#{sql}")
14
14
  connection.execute(sql)
15
15
  end
16
16
 
17
17
  def explain(query_ast)
18
- sql = compile_ast(query_ast)
18
+ sql = commented_sql(query_ast)
19
19
 
20
20
  @logger.debug(" Executing EXPLAIN QUERY PLAN: \n#{sql}")
21
21
  rows = connection.execute("EXPLAIN QUERY PLAN #{sql}")
data/lib/exwiw/adapter.rb CHANGED
@@ -81,6 +81,34 @@ module Exwiw
81
81
  def explain(_query_ast)
82
82
  raise NotImplementedError, "#{self.class.name} does not implement #explain"
83
83
  end
84
+
85
+ # Identifier text prepended to every query exwiw sends to the (often
86
+ # production) source DB, so the statement is recognizable in the
87
+ # processlist / slow-query log / db.currentOp() and can be killed if it
88
+ # runs long. e.g. "exwiw table=shops". `label` is "table=..." /
89
+ # "collection=...". The version is intentionally omitted to keep the
90
+ # comment stable across releases (snapshots / diffs). Strips `*/` to
91
+ # avoid breaking out of the comment.
92
+ def query_comment_text(label = nil)
93
+ parts = ["exwiw"]
94
+ parts << label if label
95
+ parts.join(' ').gsub('*/', '')
96
+ end
97
+
98
+ # SQL block-comment form, prefixed to SELECT / EXPLAIN.
99
+ def sql_query_comment(query_ast)
100
+ label =
101
+ if query_ast.respond_to?(:from_table_name) && query_ast.from_table_name
102
+ "table=#{query_ast.from_table_name}"
103
+ end
104
+ "/* #{query_comment_text(label)} */"
105
+ end
106
+
107
+ # Comment-prefixed SELECT. Relies on the SQL adapter's #compile_ast
108
+ # (dispatched to the subclass at runtime).
109
+ def commented_sql(query_ast)
110
+ "#{sql_query_comment(query_ast)} #{compile_ast(query_ast)}"
111
+ end
84
112
  end
85
113
 
86
114
  # @params [Exwiw::QueryAst] query_ast
@@ -40,7 +40,7 @@ module Exwiw
40
40
  @logger.debug("Explaining '#{table_name}'... (#{idx + 1}/#{total_size})")
41
41
 
42
42
  query_ast = adapter.build_query(table, @dump_target, table_by_name)
43
- sql = adapter.compile_ast(query_ast)
43
+ sql = adapter.commented_sql(query_ast)
44
44
  explain_text = adapter.explain(query_ast)
45
45
 
46
46
  @io.puts "-- [#{idx + 1}/#{total_size}] #{table_name}"
data/lib/exwiw/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Exwiw
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exwiw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shia