exwiw 0.2.2 → 0.2.3

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: 369701f0b142d0660d988630013e5f421c1d4ad817a834615e25177721700abc
4
- data.tar.gz: 950edc07255a1520bfa9bae067c028160219790ecc84379210e6532054de0ddb
3
+ metadata.gz: db5d466378dd55180ac229c2276c4e5e228a067a69b648ed7979d142f5b12ce7
4
+ data.tar.gz: 2be8b1ffe33cdaa1d9443ec7a3f36f7108f506addfbadb3fa06ac8ba312a89a8
5
5
  SHA512:
6
- metadata.gz: 852cd30d5121dbbbf8d7abeb1fd486c188c4ab177339620d2129ebfed10ef1dfe13a928c34840f082c295e255d0a15e3a72cf1e71151292dce50657bbf125ac5
7
- data.tar.gz: a57d914dd5794caa00df4323ab84df3c9fcdec5694c0e32fde68d44cc7f78369b3d8359614c55a35608eb2b9d7202af2078ffc1ee0a3a566d69cf1eb5141de72
6
+ metadata.gz: 17ae95279fe11b231c50a2c0d2e2ead9adcf2db6eb3fb79f7ee54f1af816c26dae23ace12d6fa901655817b26101777af04d70fd76751c6e45bc576d99ef7503
7
+ data.tar.gz: 99415623bdf900053d466d58c8a45fb1be380167a9d66cf9d265c8122c9fd6e3c96c8e48cb5e9e971e2783db595b63b1d525a850a3871e294a751263747b12b1
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.2.3] - 2026-05-27
6
+
7
+ ### Fixed
8
+
9
+ - PostgreSQL: schema dump now includes `CREATE TYPE ... AS ENUM` for custom enum types referenced by dumped tables. Previously `pg_dump --table` excluded schema-level type definitions, causing `type "..." does not exist` errors on import. ([#22](https://github.com/heyinc/exwiw/pull/22))
10
+
5
11
  ## [0.2.2] - 2026-05-26
6
12
 
7
13
  ### Changed
data/README.md CHANGED
@@ -347,7 +347,12 @@ At runtime:
347
347
 
348
348
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
349
349
 
350
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
350
+ To install this gem onto your local machine, run `bundle exec rake install`.
351
+
352
+ To release a new version:
353
+
354
+ 1. Run the **Release PR** workflow from the Actions tab with the new version number (e.g. `0.2.3`). This creates a PR that bumps `version.rb` and `CHANGELOG.md`.
355
+ 2. Merge the PR. The **Release** workflow runs automatically, creating a git tag and publishing the gem to [rubygems.org](https://rubygems.org).
351
356
 
352
357
  ## Contributing
353
358
 
@@ -52,6 +52,13 @@ module Exwiw
52
52
  raise "pg_dump failed (exit #{status.exitstatus}): #{stderr}"
53
53
  end
54
54
 
55
+ enum_types = query_enum_types(table_names)
56
+ unless enum_types.empty?
57
+ enum_ddl = DdlPostprocessor.create_type_enum_statements(enum_types)
58
+ @logger.debug(" Found #{enum_types.size} enum type(s) to prepend.")
59
+ stdout = enum_ddl + stdout
60
+ end
61
+
55
62
  idempotent = stdout
56
63
  idempotent = DdlPostprocessor.add_if_not_exists_to_create_schema(idempotent)
57
64
  idempotent = DdlPostprocessor.add_if_not_exists_to_create_sequence(idempotent)
@@ -264,6 +271,40 @@ module Exwiw
264
271
  end
265
272
  end
266
273
 
274
+ private def query_enum_types(table_names)
275
+ return [] if table_names.empty?
276
+
277
+ placeholders = table_names.each_with_index.map { |_, i| "$#{i + 1}" }.join(', ')
278
+ sql = <<~SQL
279
+ SELECT DISTINCT
280
+ n.nspname AS type_schema,
281
+ t.typname AS type_name,
282
+ array_agg(e.enumlabel ORDER BY e.enumsortorder) AS enum_labels
283
+ FROM pg_attribute a
284
+ JOIN pg_class c ON c.oid = a.attrelid
285
+ JOIN pg_namespace cn ON cn.oid = c.relnamespace
286
+ JOIN pg_type t ON t.oid = a.atttypid
287
+ JOIN pg_namespace n ON n.oid = t.typnamespace
288
+ JOIN pg_enum e ON e.enumtypid = t.oid
289
+ WHERE c.relname IN (#{placeholders})
290
+ AND a.attnum > 0
291
+ AND NOT a.attisdropped
292
+ AND t.typtype = 'e'
293
+ GROUP BY n.nspname, t.typname
294
+ ORDER BY n.nspname, t.typname
295
+ SQL
296
+
297
+ result = connection.exec_params(sql, table_names)
298
+ decoder = PG::TextDecoder::Array.new
299
+ result.map do |row|
300
+ {
301
+ schema: row['type_schema'],
302
+ name: row['type_name'],
303
+ labels: decoder.decode(row['enum_labels']),
304
+ }
305
+ end
306
+ end
307
+
267
308
  private def connection
268
309
  @connection ||=
269
310
  begin
@@ -57,5 +57,24 @@ module Exwiw
57
57
  SQL
58
58
  end
59
59
  end
60
+
61
+ # Generate idempotent CREATE TYPE ... AS ENUM statements.
62
+ # +enum_types+ is an Array of Hashes with keys :schema, :name, :labels.
63
+ def create_type_enum_statements(enum_types)
64
+ return "" if enum_types.empty?
65
+
66
+ stmts = enum_types.map do |t|
67
+ qualified_name = "\"#{t[:schema]}\".\"#{t[:name]}\""
68
+ labels_sql = t[:labels].map { |l| "'#{l.gsub("'", "''")}'" }.join(', ')
69
+ <<~SQL.chomp
70
+ DO $exwiw$ BEGIN
71
+ CREATE TYPE #{qualified_name} AS ENUM (#{labels_sql});
72
+ EXCEPTION WHEN duplicate_object THEN NULL;
73
+ END $exwiw$;
74
+ SQL
75
+ end
76
+
77
+ stmts.join("\n\n") + "\n\n"
78
+ end
60
79
  end
61
80
  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.2"
4
+ VERSION = "0.2.3"
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.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shia