fast_schema_dumper 0.4.1 → 0.4.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 +4 -4
- data/.standard.yml +5 -0
- data/CHANGELOG.md +6 -0
- data/README.md +3 -1
- data/Rakefile +10 -1
- data/lib/fast_schema_dumper/cli.rb +2 -4
- data/lib/fast_schema_dumper/fast_dumper.rb +27 -21
- data/lib/fast_schema_dumper/ridgepole.rb +1 -1
- data/lib/fast_schema_dumper/version.rb +3 -1
- data/test/fast_schema_dumper_test.rb +9 -0
- data/test/test_helper.rb +6 -0
- metadata +18 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e9b478b3a2993c1fe6997b20825e9f4e3210c9d92398eafb4f52791397ff1585
|
|
4
|
+
data.tar.gz: 5761bd4d938ee94ad5050820a9e03431a491c0b548b50d4125fd604ace2d3baf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: df2cad69755111f9b3576b000220a28e02db49b62bd7f5211d53aa39be8d03bfa63f6e86fe15ac2051bf3307dab41da72a56b68baad1b482ba3abb8d29fe2777
|
|
7
|
+
data.tar.gz: 9717903a94fca3dc7ab94c3ea26ae347c6d98dadd6633f46726c78cb638e2d053cf7af85b79f3ff70978579d47fd43dae49e7b304c111f14057b5c2377aacb9a
|
data/.standard.yml
ADDED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.4.3] - 2026-03-11
|
|
4
|
+
|
|
5
|
+
- Introduce StandardRB for code linting. [#9](https://github.com/smartbank-inc/fast_schema_dumper/pull/9)
|
|
6
|
+
- Test setup. [#10](https://github.com/smartbank-inc/fast_schema_dumper/pull/10)
|
|
7
|
+
- Add `.github/dependabot.yml`. [#12](https://github.com/smartbank-inc/fast_schema_dumper/pull/12)
|
|
8
|
+
|
|
3
9
|
## [0.4.0] - 2025-11-06
|
|
4
10
|
|
|
5
11
|
## [0.3.0] - 2025-10-31
|
data/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
[](https://github.com/smartbank-inc/fast_schema_dumper/actions/workflows/test.yml)
|
|
2
|
+
|
|
1
3
|
# fast_schema_dumper
|
|
2
4
|
|
|
3
5
|
A super fast alternative to ActiveRecord::SchemaDumper. Currently only MySQL is supported.
|
|
@@ -46,7 +48,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
|
46
48
|
|
|
47
49
|
## Contributing
|
|
48
50
|
|
|
49
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
|
51
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/smartbank-inc/fast_schema_dumper.
|
|
50
52
|
|
|
51
53
|
## Releasing
|
|
52
54
|
|
data/Rakefile
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "bundler/gem_tasks"
|
|
4
|
-
|
|
4
|
+
require "rake/testtask"
|
|
5
|
+
require "standard/rake"
|
|
6
|
+
|
|
7
|
+
Rake::TestTask.new(:test) do |t|
|
|
8
|
+
t.libs << "test"
|
|
9
|
+
t.libs << "lib"
|
|
10
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
task default: :test
|
|
@@ -2,7 +2,7 @@ require 'erb'
|
|
|
2
2
|
require 'active_record'
|
|
3
3
|
require 'active_record/database_configurations'
|
|
4
4
|
|
|
5
|
-
require_relative '
|
|
5
|
+
require_relative 'fast_dumper'
|
|
6
6
|
|
|
7
7
|
module FastSchemaDumper
|
|
8
8
|
class CLI
|
|
@@ -11,8 +11,6 @@ module FastSchemaDumper
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def run(argv)
|
|
14
|
-
argv = argv.dup
|
|
15
|
-
|
|
16
14
|
env = ENV['RAILS_ENV'] || 'development'
|
|
17
15
|
|
|
18
16
|
database_yml_path = File.join(Dir.pwd, 'config', 'database.yml')
|
|
@@ -27,7 +25,7 @@ module FastSchemaDumper
|
|
|
27
25
|
|
|
28
26
|
SchemaDumper.dump
|
|
29
27
|
|
|
30
|
-
|
|
28
|
+
0
|
|
31
29
|
end
|
|
32
30
|
end
|
|
33
31
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'json'
|
|
2
|
+
require 'bigdecimal'
|
|
2
3
|
|
|
3
4
|
module FastSchemaDumper
|
|
4
5
|
class SchemaDumper
|
|
@@ -76,7 +77,7 @@ module FastSchemaDumper
|
|
|
76
77
|
# include
|
|
77
78
|
# nulls_not_distinct
|
|
78
79
|
# type
|
|
79
|
-
comment: idx['INDEX_COMMENT']
|
|
80
|
+
comment: idx['INDEX_COMMENT']
|
|
80
81
|
# enabled
|
|
81
82
|
}
|
|
82
83
|
hash[idx['TABLE_NAME']][idx['INDEX_NAME']][:columns] << idx['COLUMN_NAME']
|
|
@@ -98,7 +99,7 @@ module FastSchemaDumper
|
|
|
98
99
|
").each_with_object({}) do |row, hash|
|
|
99
100
|
hash[row['TABLE_NAME']] = {
|
|
100
101
|
collation: row['TABLE_COLLATION'],
|
|
101
|
-
comment: row['TABLE_COMMENT']
|
|
102
|
+
comment: row['TABLE_COMMENT']
|
|
102
103
|
}
|
|
103
104
|
end
|
|
104
105
|
|
|
@@ -186,7 +187,7 @@ module FastSchemaDumper
|
|
|
186
187
|
column: fk['COLUMN_NAME'],
|
|
187
188
|
referenced_table: fk['REFERENCED_TABLE_NAME'],
|
|
188
189
|
referenced_column: fk['REFERENCED_COLUMN_NAME'],
|
|
189
|
-
constraint_name: fk['CONSTRAINT_NAME']
|
|
190
|
+
constraint_name: fk['CONSTRAINT_NAME']
|
|
190
191
|
}
|
|
191
192
|
end
|
|
192
193
|
|
|
@@ -196,7 +197,7 @@ module FastSchemaDumper
|
|
|
196
197
|
all_foreign_keys << {
|
|
197
198
|
table_name: table_name,
|
|
198
199
|
constraint_name: constraint_name,
|
|
199
|
-
fk_data: fk_data
|
|
200
|
+
fk_data: fk_data
|
|
200
201
|
}
|
|
201
202
|
end
|
|
202
203
|
end
|
|
@@ -216,12 +217,10 @@ module FastSchemaDumper
|
|
|
216
217
|
if fk[:fk_data][:column] != inferred_column
|
|
217
218
|
# Column name is custom, need to specify it
|
|
218
219
|
fk_line += ", column: \"#{fk[:fk_data][:column]}\""
|
|
219
|
-
|
|
220
|
+
elsif !fk[:fk_data][:constraint_name].start_with?("fk_rails_")
|
|
220
221
|
# Column matches default, check if constraint name is custom
|
|
221
222
|
# Rails generates constraint names starting with "fk_rails_"
|
|
222
|
-
|
|
223
|
-
fk_line += ", name: \"#{fk[:fk_data][:constraint_name]}\""
|
|
224
|
-
end
|
|
223
|
+
fk_line += ", name: \"#{fk[:fk_data][:constraint_name]}\""
|
|
225
224
|
end
|
|
226
225
|
|
|
227
226
|
@output << fk_line
|
|
@@ -230,7 +229,7 @@ module FastSchemaDumper
|
|
|
230
229
|
stream.print @output.join("\n")
|
|
231
230
|
end
|
|
232
231
|
|
|
233
|
-
|
|
232
|
+
private
|
|
234
233
|
|
|
235
234
|
def escape_string(str)
|
|
236
235
|
str.gsub("\\", "\\\\\\\\").gsub('"', '\"').gsub("\n", "\\n").gsub("\r", "\\r").gsub("\t", "\\t")
|
|
@@ -316,7 +315,7 @@ module FastSchemaDumper
|
|
|
316
315
|
# Indexes
|
|
317
316
|
# Rails orders indexes lexicographically by their column arrays
|
|
318
317
|
# Example: ["a", "b"] < ["a"] < ["b", "c"] < ["b"] < ["d"]
|
|
319
|
-
sorted_indexes = indexes.
|
|
318
|
+
sorted_indexes = indexes.except('PRIMARY').sort_by do |index_name, index_data|
|
|
320
319
|
# Create an array padded with high values for comparison
|
|
321
320
|
# This ensures that missing columns sort after existing ones
|
|
322
321
|
max_cols = indexes.values.map { |data| data[:columns].size }.max || 1
|
|
@@ -348,7 +347,7 @@ module FastSchemaDumper
|
|
|
348
347
|
end
|
|
349
348
|
end
|
|
350
349
|
|
|
351
|
-
check_clause.gsub!(
|
|
350
|
+
check_clause.gsub!("\\'", "'") # don't escape single quotes for compatibility with the original dumper
|
|
352
351
|
|
|
353
352
|
ck_line = " t.check_constraint \"#{check_clause}\""
|
|
354
353
|
|
|
@@ -369,7 +368,7 @@ module FastSchemaDumper
|
|
|
369
368
|
|
|
370
369
|
# limit (varchar, char)
|
|
371
370
|
if ['varchar', 'char'].include?(column['DATA_TYPE']) && column['CHARACTER_MAXIMUM_LENGTH'] &&
|
|
372
|
-
|
|
371
|
+
column['CHARACTER_MAXIMUM_LENGTH'] != 255
|
|
373
372
|
col_def += ", limit: #{column['CHARACTER_MAXIMUM_LENGTH']}"
|
|
374
373
|
end
|
|
375
374
|
|
|
@@ -475,7 +474,7 @@ module FastSchemaDumper
|
|
|
475
474
|
|
|
476
475
|
# Special handling for boolean (tinyint(1))
|
|
477
476
|
if column_type == 'tinyint(1)'
|
|
478
|
-
return default == '1' ? 'true' : 'false'
|
|
477
|
+
return (default == '1') ? 'true' : 'false'
|
|
479
478
|
end
|
|
480
479
|
|
|
481
480
|
case data_type
|
|
@@ -486,20 +485,27 @@ module FastSchemaDumper
|
|
|
486
485
|
when 'datetime', 'timestamp'
|
|
487
486
|
return '-> { "CURRENT_TIMESTAMP" }' if default == 'CURRENT_TIMESTAMP'
|
|
488
487
|
"\"#{default}\""
|
|
488
|
+
when 'decimal'
|
|
489
|
+
# Same as Rails: activemodel/lib/active_model/type/decimal.rb#type_cast_for_schema
|
|
490
|
+
BigDecimal(default).to_s.inspect
|
|
491
|
+
when 'float', 'double'
|
|
492
|
+
# Same as Rails: activemodel/lib/active_model/type/float.rb#type_cast_for_schema
|
|
493
|
+
# MySQL double is mapped to Type::Float in Rails
|
|
494
|
+
default.to_f.inspect
|
|
489
495
|
when 'json'
|
|
490
|
-
default == "'[]'" ? '[]' : '{}'
|
|
496
|
+
(default == "'[]'") ? '[]' : '{}'
|
|
491
497
|
else
|
|
492
|
-
|
|
498
|
+
/^'.*'$/.match?(default) ? "\"#{default[1..-2]}\"" : default
|
|
493
499
|
end
|
|
494
500
|
end
|
|
495
501
|
|
|
496
502
|
def format_index(index_name, index_data)
|
|
497
503
|
idx_def = "t.index "
|
|
498
504
|
|
|
499
|
-
if index_data[:columns].size == 1
|
|
500
|
-
|
|
505
|
+
idx_def += if index_data[:columns].size == 1
|
|
506
|
+
"[\"#{index_data[:columns].first}\"]"
|
|
501
507
|
else
|
|
502
|
-
|
|
508
|
+
"[#{index_data[:columns].map { |c| "\"#{c}\"" }.join(', ')}]"
|
|
503
509
|
end
|
|
504
510
|
|
|
505
511
|
idx_def += ", name: \"#{index_name}\""
|
|
@@ -514,12 +520,12 @@ module FastSchemaDumper
|
|
|
514
520
|
end
|
|
515
521
|
|
|
516
522
|
unless order_hash.empty?
|
|
517
|
-
if index_data[:columns].size == 1
|
|
523
|
+
idx_def += if index_data[:columns].size == 1
|
|
518
524
|
# For single column index, use simplified syntax
|
|
519
|
-
|
|
525
|
+
", order: :#{order_hash.values.first}"
|
|
520
526
|
else
|
|
521
527
|
# For compound index, use hash syntax
|
|
522
|
-
|
|
528
|
+
", order: { #{order_hash.map { |k, v| "#{k}: :#{v}" }.join(', ')} }"
|
|
523
529
|
end
|
|
524
530
|
end
|
|
525
531
|
end
|
data/test/test_helper.rb
ADDED
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.
|
|
4
|
+
version: 0.4.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daisuke Aritomo
|
|
@@ -23,6 +23,20 @@ dependencies:
|
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: bigdecimal
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
26
40
|
email:
|
|
27
41
|
- osyoyu@osyoyu.com
|
|
28
42
|
- over.rye@gmail.com
|
|
@@ -32,6 +46,7 @@ executables:
|
|
|
32
46
|
extensions: []
|
|
33
47
|
extra_rdoc_files: []
|
|
34
48
|
files:
|
|
49
|
+
- ".standard.yml"
|
|
35
50
|
- CHANGELOG.md
|
|
36
51
|
- README.md
|
|
37
52
|
- Rakefile
|
|
@@ -41,6 +56,8 @@ files:
|
|
|
41
56
|
- lib/fast_schema_dumper/fast_dumper.rb
|
|
42
57
|
- lib/fast_schema_dumper/ridgepole.rb
|
|
43
58
|
- lib/fast_schema_dumper/version.rb
|
|
59
|
+
- test/fast_schema_dumper_test.rb
|
|
60
|
+
- test/test_helper.rb
|
|
44
61
|
homepage: https://github.com/osyoyu/fast_schema_dumper
|
|
45
62
|
licenses: []
|
|
46
63
|
metadata:
|