fast_schema_dumper 0.4.3 → 0.5.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: e9b478b3a2993c1fe6997b20825e9f4e3210c9d92398eafb4f52791397ff1585
4
- data.tar.gz: 5761bd4d938ee94ad5050820a9e03431a491c0b548b50d4125fd604ace2d3baf
3
+ metadata.gz: 67356310ddf238f27066fb0980ea10ff37b9ffcb5307f89c661fe81a1dc1a6c4
4
+ data.tar.gz: 8a5c15d6dff1209cd439dabf036ee3333bd08bee49e3481d7dd3ef233b07a679
5
5
  SHA512:
6
- metadata.gz: df2cad69755111f9b3576b000220a28e02db49b62bd7f5211d53aa39be8d03bfa63f6e86fe15ac2051bf3307dab41da72a56b68baad1b482ba3abb8d29fe2777
7
- data.tar.gz: 9717903a94fca3dc7ab94c3ea26ae347c6d98dadd6633f46726c78cb638e2d053cf7af85b79f3ff70978579d47fd43dae49e7b304c111f14057b5c2377aacb9a
6
+ metadata.gz: ad7aa63eaae977b3fa65e210e3a66a6074d8a0ceb31a6e21c35c3f4a97dcd3a0658afd1c64fc46e3bab3e0cac198a26fdad8df1c14846aa35936b2e9feac573e
7
+ data.tar.gz: 858e4903f02a8b12a0fc153c577bc137418b56be1ae4bc522c65920c5fc8774f00598e55e8086b60e769e7959cfd94ae1408cd41f12ba8823ee350587bd6b794
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.5.0] - 2026-04-09
4
+
5
+ - Handle generated columns in fast dumper. [#23](https://github.com/smartbank-inc/fast_schema_dumper/pull/23)
6
+ - Add frozen string literal pragmas and update README. [#25](https://github.com/smartbank-inc/fast_schema_dumper/pull/25)
7
+ - Add RubyGems version badge to README. [#17](https://github.com/smartbank-inc/fast_schema_dumper/pull/17)
8
+
3
9
  ## [0.4.3] - 2026-03-11
4
10
 
5
11
  - Introduce StandardRB for code linting. [#9](https://github.com/smartbank-inc/fast_schema_dumper/pull/9)
data/README.md CHANGED
@@ -1,17 +1,25 @@
1
1
  [![Test](https://github.com/smartbank-inc/fast_schema_dumper/actions/workflows/test.yml/badge.svg)](https://github.com/smartbank-inc/fast_schema_dumper/actions/workflows/test.yml)
2
+ [![Gem Version](https://badge.fury.io/rb/fast_schema_dumper.svg)](https://badge.fury.io/rb/fast_schema_dumper)
2
3
 
3
4
  # fast_schema_dumper
4
5
 
5
- A super fast alternative to ActiveRecord::SchemaDumper. Currently only MySQL is supported.
6
+ A super fast alternative to `ActiveRecord::SchemaDumper`. Currently only MySQL is supported.
7
+
8
+ ## What It Does
9
+
10
+ - Reads schema metadata directly from `INFORMATION_SCHEMA`
11
+ - Emits Rails-style `schema.rb` output
12
+ - Works as a standalone executable
13
+ - Can override `Ridgepole::Dumper.dump`
6
14
 
7
15
  ## Usage
8
16
 
9
17
  ### Ridgepole integration
10
18
 
11
- Requiring `fast_schema_dumper/ridgepole` will overwrite `Ridgepole::Dumper.dump`, which will force Ridgepole to use fast_schema_dumper.
19
+ Require `fast_schema_dumper/ridgepole` after loading `ridgepole` to replace `Ridgepole::Dumper.dump` with `fast_schema_dumper`.
12
20
 
13
- ```
14
- RUBYOPT='-rridgepole -rfast_schema_dumper' ridgepole ... --apply
21
+ ```bash
22
+ RUBYOPT='-rridgepole -rfast_schema_dumper/ridgepole' ridgepole --apply
15
23
  ```
16
24
 
17
25
  #### Environment variables for Ridgepole
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'erb'
2
4
  require 'active_record'
3
5
  require 'active_record/database_configurations'
@@ -10,7 +12,7 @@ module FastSchemaDumper
10
12
  new.run(...)
11
13
  end
12
14
 
13
- def run(argv)
15
+ def run(_argv)
14
16
  env = ENV['RAILS_ENV'] || 'development'
15
17
 
16
18
  database_yml_path = File.join(Dir.pwd, 'config', 'database.yml')
@@ -38,6 +38,7 @@ module FastSchemaDumper
38
38
  , NUMERIC_SCALE
39
39
  , COLUMN_TYPE
40
40
  , EXTRA
41
+ , GENERATION_EXPRESSION
41
42
  , COLUMN_COMMENT
42
43
  , DATETIME_PRECISION
43
44
  , COLLATION_NAME
@@ -364,6 +365,8 @@ module FastSchemaDumper
364
365
  end
365
366
 
366
367
  def format_column(column)
368
+ return format_generated_column(column) if generated_column?(column)
369
+
367
370
  col_def = "t.#{map_column_type(column)} \"#{column['COLUMN_NAME']}\""
368
371
 
369
372
  # limit (varchar, char)
@@ -433,6 +436,21 @@ module FastSchemaDumper
433
436
  col_def
434
437
  end
435
438
 
439
+ def format_generated_column(column)
440
+ col_def = "t.virtual \"#{column['COLUMN_NAME']}\", type: :#{map_column_type(column)}, as: \"#{escape_string(column['GENERATION_EXPRESSION'])}\""
441
+ col_def += ", stored: true" if stored_generated_column?(column)
442
+ col_def += ", comment: \"#{escape_string(column['COLUMN_COMMENT'])}\"" if column['COLUMN_COMMENT'] && !column['COLUMN_COMMENT'].empty?
443
+ col_def
444
+ end
445
+
446
+ def generated_column?(column)
447
+ column['EXTRA'].include?(' GENERATED')
448
+ end
449
+
450
+ def stored_generated_column?(column)
451
+ column['EXTRA'].include?('STORED GENERATED')
452
+ end
453
+
436
454
  def map_column_type(column)
437
455
  # Check for boolean (tinyint(1))
438
456
  if column['COLUMN_TYPE'] == 'tinyint(1)'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'fast_dumper'
2
4
 
3
5
  # Loading this file will overwrite `Ridgepole::Dumper.dump`.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FastSchemaDumper
4
- VERSION = "0.4.3"
4
+ VERSION = "0.5.0"
5
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "fast_schema_dumper/version"
2
4
 
3
5
  module FastSchemaDumper
@@ -1,9 +1,73 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "test_helper"
4
+ require "fast_schema_dumper/fast_dumper"
4
5
 
5
6
  class FastSchemaDumperTest < Minitest::Test
6
7
  def test_that_it_has_a_version_number
7
8
  refute_nil ::FastSchemaDumper::VERSION
8
9
  end
10
+
11
+ def test_format_generated_column
12
+ dumper = FastSchemaDumper::SchemaDumper.new
13
+ column = {
14
+ 'COLUMN_NAME' => 'active_unique_key',
15
+ 'DATA_TYPE' => 'int',
16
+ 'COLUMN_TYPE' => 'int',
17
+ 'EXTRA' => 'STORED GENERATED',
18
+ 'GENERATION_EXPRESSION' => 'if((`deleted_at` is null),1,NULL)',
19
+ 'COLUMN_COMMENT' => '',
20
+ 'IS_NULLABLE' => 'YES'
21
+ }
22
+
23
+ actual = dumper.send(:format_column, column)
24
+
25
+ assert_equal(
26
+ 't.virtual "active_unique_key", type: :integer, as: "if((`deleted_at` is null),1,NULL)", stored: true',
27
+ actual
28
+ )
29
+ end
30
+
31
+ def test_format_generated_column_with_comment
32
+ dumper = FastSchemaDumper::SchemaDumper.new
33
+ column = {
34
+ 'COLUMN_NAME' => 'full_name',
35
+ 'DATA_TYPE' => 'varchar',
36
+ 'COLUMN_TYPE' => 'varchar(255)',
37
+ 'EXTRA' => 'VIRTUAL GENERATED',
38
+ 'GENERATION_EXPRESSION' => 'concat(`first_name`,`last_name`)',
39
+ 'COLUMN_COMMENT' => 'generated name',
40
+ 'IS_NULLABLE' => 'YES'
41
+ }
42
+
43
+ actual = dumper.send(:format_column, column)
44
+
45
+ assert_equal(
46
+ 't.virtual "full_name", type: :string, as: "concat(`first_name`,`last_name`)", comment: "generated name"',
47
+ actual
48
+ )
49
+ end
50
+
51
+ def test_generated_column_detection_does_not_match_default_generated
52
+ dumper = FastSchemaDumper::SchemaDumper.new
53
+ column = {
54
+ 'COLUMN_NAME' => 'created_at',
55
+ 'DATA_TYPE' => 'datetime',
56
+ 'COLUMN_TYPE' => 'datetime',
57
+ 'EXTRA' => 'DEFAULT_GENERATED',
58
+ 'COLUMN_DEFAULT' => 'CURRENT_TIMESTAMP',
59
+ 'COLUMN_COMMENT' => '',
60
+ 'IS_NULLABLE' => 'NO',
61
+ 'COLUMN_KEY' => '',
62
+ 'CHARACTER_MAXIMUM_LENGTH' => nil,
63
+ 'NUMERIC_PRECISION' => nil,
64
+ 'NUMERIC_SCALE' => nil,
65
+ 'DATETIME_PRECISION' => nil,
66
+ 'COLLATION_NAME' => nil
67
+ }
68
+
69
+ actual = dumper.send(:format_column, column)
70
+
71
+ assert_equal('t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" }, null: false', actual)
72
+ end
9
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_schema_dumper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daisuke Aritomo