exwiw 0.2.6 → 0.2.7

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: 2ff943aae77c0ed0f79dc80c2e68527badcae7c6b330e89aec6a019adf0dd1e5
4
- data.tar.gz: 8a146a76aea7ab0bd3aeabb27ccf789f575f86e1d965b64b2432c250addb003b
3
+ metadata.gz: 9ad123bcfe1cadde34a031d1db34fb4592892b88765d3b979c2fb827b53578f7
4
+ data.tar.gz: 59b2263b51e51f95e9f8d79cbc214dc0f385202e7ca120d108f3f64e18832a52
5
5
  SHA512:
6
- metadata.gz: 6dbd0212c4ca02aba3839f17bfe7fc45283f17cb7264d903527fbafda04a4cc9b5c756762a1422fae549b143a60ec825669581311ada63972c2288bdb744e47c
7
- data.tar.gz: 6364942e8ee51055eb2ed2bffc16995b1a19c64b977790fa8ff4222742f034ae6d4b0b7410f779f70655bb2d6d3ea33af7321853727a2c9300adcdcbd45fc763
6
+ metadata.gz: f79b7338d57d93eebbfba42d81ff6a3f3c232dbb9163118e42d4f67b73844c50234910d3add9eafe72ff4f854d5497191ac7cb37a4ec1da1647dfb1987c118be
7
+ data.tar.gz: 22c97b02f4cb68badb0bc3e404996af4a48f46f0c32f0366cf0845a6e683b5d4a6a1af3ed499dae425d9adafe131f5c86eca933d5f51eac3d3d4458e508f36a8
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.2.7] - 2026-05-30
6
+
7
+ ### Added
8
+
9
+ - `schema:generate` no longer crashes on models with a composite primary key (`primary_key` returns an Array). Such tables are emitted with `skip: true`, tagged `type: "unsupported_composite_primary_key"`, and annotated with a `comment` listing the key columns. `columns` / `belongs_tos` are retained so the entry can be wired up once composite-key support lands; for now `skip: true` excludes it from extraction. `skip: true` tables no longer require `primary_key` at load time.
10
+
11
+ ### Notes
12
+
13
+ - `schema:generate` multi-database support: each database keeps its own Rails migration history, so a per-database `schema_migrations` / `ar_internal_metadata` entry is emitted for every database that has one. Known limitation: the rails-managed table *name* is resolved from the global `ActiveRecord::Base.schema_migrations_table_name` / `internal_metadata_table_name` accessors, so a per-database override of those names is not detected and the table will be missing from that database's generated configs.
14
+
5
15
  ## [0.2.6] - 2026-05-29
6
16
 
7
17
  ### Added
data/README.md CHANGED
@@ -142,7 +142,11 @@ exwiw/
142
142
  analytics_events.json
143
143
  ```
144
144
 
145
- Rails-managed tables (`schema_migrations` / `ar_internal_metadata`) are emitted under whichever database actually contains them. Single-database applications are unaffected and continue to write files flat into the output directory.
145
+ Each database keeps its own Rails migration history, so a `schema_migrations` (and `ar_internal_metadata`) entry is emitted under every database that contains one — the example above shows `primary/schema_migrations.json` and would also produce `analytics/schema_migrations.json` when the analytics database has its own migration table. Single-database applications are unaffected and continue to write files flat into the output directory.
146
+
147
+ **Limitations**
148
+
149
+ - The rails-managed table *names* are resolved from the global `ActiveRecord::Base.schema_migrations_table_name` / `internal_metadata_table_name` accessors, which are shared across all connections. A per-database override of these names is not detected, so such a table will be missing from that database's generated configs.
146
150
 
147
151
  ### Configuration
148
152
 
@@ -268,6 +272,23 @@ Constraints:
268
272
  - A rails-managed table cannot be used as `--target-table`.
269
273
  - In multi-database setups, the rails-managed entry is emitted under whichever database's connection actually contains the table (see [Multiple databases](#multiple-databases)). The table name itself is still derived from the global `ActiveRecord::Base.schema_migrations_table_name` / `internal_metadata_table_name` (prefix/suffix) accessors.
270
274
 
275
+ ### Composite primary keys (unsupported)
276
+
277
+ exwiw does not yet support tables with a composite primary key. When `exwiw:schema:generate` encounters a model whose `primary_key` is an array, it still emits a config entry so the table is not silently dropped, but marks it `skip: true`, tags it `type: "unsupported_composite_primary_key"`, and records the key columns in a `comment`:
278
+
279
+ ```json
280
+ {
281
+ "name": "composite_pk_records",
282
+ "type": "unsupported_composite_primary_key",
283
+ "skip": true,
284
+ "comment": "exwiw does not support composite primary keys (organization_id, location_id); data extraction is skipped.",
285
+ "belongs_tos": [],
286
+ "columns": [{ "name": "organization_id" }, { "name": "location_id" }, { "name": "name" }]
287
+ }
288
+ ```
289
+
290
+ Unlike rails-managed entries, `columns` and `belongs_tos` are retained so the entry is ready to wire up once composite-key support lands. The `type` is purely a marker — `skip: true` is what actually excludes the table from extraction, so removing `skip` (and supplying a workable `primary_key`) lets you opt the table back in manually.
291
+
271
292
  ### Bulk insert chunk size
272
293
 
273
294
  `bulk_insert_chunk_size` splits the generated `INSERT` statement into multiple statements, each containing at most the specified number of rows. This is useful when the number of records per table is large enough to hit limits like MySQL's `max_allowed_packet`.
@@ -76,12 +76,31 @@ module Exwiw
76
76
  private def build_tables_for(models, conn)
77
77
  tables_from_models = models.group_by(&:table_name).map do |table_name, model_group|
78
78
  representative = model_group.first
79
- TableConfig.from_symbol_keys(
80
- name: table_name,
81
- primary_key: representative.primary_key,
82
- belongs_tos: aggregate_belongs_tos(model_group),
83
- columns: representative.column_names.map { |name| { name: name } },
84
- )
79
+ primary_key = representative.primary_key
80
+
81
+ # 複合主キー (`representative.primary_key` が Array) のテーブルは現状未対応。
82
+ # primary_key を省略し、type で非対応である旨を明示したうえで skip:true
83
+ # 付与して出力する。type を付けておくことで将来対応する際の目印になる。
84
+ # 利用者が必要に応じて手動で skip を外して設定し直せるよう、設定ファイル
85
+ # 自体は生成しておく。
86
+ if primary_key.is_a?(Array)
87
+ TableConfig.from_symbol_keys(
88
+ name: table_name,
89
+ type: TableConfig::UNSUPPORTED_COMPOSITE_PRIMARY_KEY,
90
+ skip: true,
91
+ comment: "exwiw does not support composite primary keys " \
92
+ "(#{primary_key.join(', ')}); data extraction is skipped.",
93
+ belongs_tos: aggregate_belongs_tos(model_group),
94
+ columns: representative.column_names.map { |name| { name: name } },
95
+ )
96
+ else
97
+ TableConfig.from_symbol_keys(
98
+ name: table_name,
99
+ primary_key: primary_key,
100
+ belongs_tos: aggregate_belongs_tos(model_group),
101
+ columns: representative.column_names.map { |name| { name: name } },
102
+ )
103
+ end
85
104
  end
86
105
 
87
106
  tables_from_models + build_rails_managed_tables(conn)
@@ -11,6 +11,11 @@ module Exwiw
11
11
  RAILS_MANAGED_INTERNAL_METADATA,
12
12
  ].freeze
13
13
 
14
+ # exwiw が現状サポートしていない複合主キーのテーブルを表す type。
15
+ # schema:generate が skip:true と併せて付与する。将来サポートする際の
16
+ # 目印になるよう、rails-managed とは異なり columns/belongs_tos は保持する。
17
+ UNSUPPORTED_COMPOSITE_PRIMARY_KEY = "unsupported_composite_primary_key"
18
+
14
19
  attribute :name, String
15
20
  attribute :primary_key, optional(String), skip_serializing_if_nil: true
16
21
  attribute :type, optional(String), skip_serializing_if_nil: true
@@ -138,7 +143,9 @@ module Exwiw
138
143
  "Table '#{name}' has type=#{type}; columns must not be defined."
139
144
  end
140
145
  else
141
- if primary_key.nil?
146
+ # skip:true のテーブルはデータ抽出を行わないため primary_key を要求しない。
147
+ # (例: exwiw 非対応の複合主キーテーブル)
148
+ if primary_key.nil? && !skip
142
149
  raise ArgumentError, "Table '#{name}' requires primary_key."
143
150
  end
144
151
  end
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.6"
4
+ VERSION = "0.2.7"
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.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shia