fast_schema_dumper 0.4.2 → 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 +2 -0
- data/Rakefile +10 -1
- data/lib/fast_schema_dumper/cli.rb +2 -4
- data/lib/fast_schema_dumper/fast_dumper.rb +19 -21
- data/lib/fast_schema_dumper/ridgepole.rb +1 -1
- data/lib/fast_schema_dumper/version.rb +1 -1
- data/test/fast_schema_dumper_test.rb +9 -0
- data/test/test_helper.rb +6 -0
- metadata +4 -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.
|
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
|
|
@@ -77,7 +77,7 @@ module FastSchemaDumper
|
|
|
77
77
|
# include
|
|
78
78
|
# nulls_not_distinct
|
|
79
79
|
# type
|
|
80
|
-
comment: idx['INDEX_COMMENT']
|
|
80
|
+
comment: idx['INDEX_COMMENT']
|
|
81
81
|
# enabled
|
|
82
82
|
}
|
|
83
83
|
hash[idx['TABLE_NAME']][idx['INDEX_NAME']][:columns] << idx['COLUMN_NAME']
|
|
@@ -99,7 +99,7 @@ module FastSchemaDumper
|
|
|
99
99
|
").each_with_object({}) do |row, hash|
|
|
100
100
|
hash[row['TABLE_NAME']] = {
|
|
101
101
|
collation: row['TABLE_COLLATION'],
|
|
102
|
-
comment: row['TABLE_COMMENT']
|
|
102
|
+
comment: row['TABLE_COMMENT']
|
|
103
103
|
}
|
|
104
104
|
end
|
|
105
105
|
|
|
@@ -187,7 +187,7 @@ module FastSchemaDumper
|
|
|
187
187
|
column: fk['COLUMN_NAME'],
|
|
188
188
|
referenced_table: fk['REFERENCED_TABLE_NAME'],
|
|
189
189
|
referenced_column: fk['REFERENCED_COLUMN_NAME'],
|
|
190
|
-
constraint_name: fk['CONSTRAINT_NAME']
|
|
190
|
+
constraint_name: fk['CONSTRAINT_NAME']
|
|
191
191
|
}
|
|
192
192
|
end
|
|
193
193
|
|
|
@@ -197,7 +197,7 @@ module FastSchemaDumper
|
|
|
197
197
|
all_foreign_keys << {
|
|
198
198
|
table_name: table_name,
|
|
199
199
|
constraint_name: constraint_name,
|
|
200
|
-
fk_data: fk_data
|
|
200
|
+
fk_data: fk_data
|
|
201
201
|
}
|
|
202
202
|
end
|
|
203
203
|
end
|
|
@@ -217,12 +217,10 @@ module FastSchemaDumper
|
|
|
217
217
|
if fk[:fk_data][:column] != inferred_column
|
|
218
218
|
# Column name is custom, need to specify it
|
|
219
219
|
fk_line += ", column: \"#{fk[:fk_data][:column]}\""
|
|
220
|
-
|
|
220
|
+
elsif !fk[:fk_data][:constraint_name].start_with?("fk_rails_")
|
|
221
221
|
# Column matches default, check if constraint name is custom
|
|
222
222
|
# Rails generates constraint names starting with "fk_rails_"
|
|
223
|
-
|
|
224
|
-
fk_line += ", name: \"#{fk[:fk_data][:constraint_name]}\""
|
|
225
|
-
end
|
|
223
|
+
fk_line += ", name: \"#{fk[:fk_data][:constraint_name]}\""
|
|
226
224
|
end
|
|
227
225
|
|
|
228
226
|
@output << fk_line
|
|
@@ -231,7 +229,7 @@ module FastSchemaDumper
|
|
|
231
229
|
stream.print @output.join("\n")
|
|
232
230
|
end
|
|
233
231
|
|
|
234
|
-
|
|
232
|
+
private
|
|
235
233
|
|
|
236
234
|
def escape_string(str)
|
|
237
235
|
str.gsub("\\", "\\\\\\\\").gsub('"', '\"').gsub("\n", "\\n").gsub("\r", "\\r").gsub("\t", "\\t")
|
|
@@ -317,7 +315,7 @@ module FastSchemaDumper
|
|
|
317
315
|
# Indexes
|
|
318
316
|
# Rails orders indexes lexicographically by their column arrays
|
|
319
317
|
# Example: ["a", "b"] < ["a"] < ["b", "c"] < ["b"] < ["d"]
|
|
320
|
-
sorted_indexes = indexes.
|
|
318
|
+
sorted_indexes = indexes.except('PRIMARY').sort_by do |index_name, index_data|
|
|
321
319
|
# Create an array padded with high values for comparison
|
|
322
320
|
# This ensures that missing columns sort after existing ones
|
|
323
321
|
max_cols = indexes.values.map { |data| data[:columns].size }.max || 1
|
|
@@ -349,7 +347,7 @@ module FastSchemaDumper
|
|
|
349
347
|
end
|
|
350
348
|
end
|
|
351
349
|
|
|
352
|
-
check_clause.gsub!(
|
|
350
|
+
check_clause.gsub!("\\'", "'") # don't escape single quotes for compatibility with the original dumper
|
|
353
351
|
|
|
354
352
|
ck_line = " t.check_constraint \"#{check_clause}\""
|
|
355
353
|
|
|
@@ -370,7 +368,7 @@ module FastSchemaDumper
|
|
|
370
368
|
|
|
371
369
|
# limit (varchar, char)
|
|
372
370
|
if ['varchar', 'char'].include?(column['DATA_TYPE']) && column['CHARACTER_MAXIMUM_LENGTH'] &&
|
|
373
|
-
|
|
371
|
+
column['CHARACTER_MAXIMUM_LENGTH'] != 255
|
|
374
372
|
col_def += ", limit: #{column['CHARACTER_MAXIMUM_LENGTH']}"
|
|
375
373
|
end
|
|
376
374
|
|
|
@@ -476,7 +474,7 @@ module FastSchemaDumper
|
|
|
476
474
|
|
|
477
475
|
# Special handling for boolean (tinyint(1))
|
|
478
476
|
if column_type == 'tinyint(1)'
|
|
479
|
-
return default == '1' ? 'true' : 'false'
|
|
477
|
+
return (default == '1') ? 'true' : 'false'
|
|
480
478
|
end
|
|
481
479
|
|
|
482
480
|
case data_type
|
|
@@ -495,19 +493,19 @@ module FastSchemaDumper
|
|
|
495
493
|
# MySQL double is mapped to Type::Float in Rails
|
|
496
494
|
default.to_f.inspect
|
|
497
495
|
when 'json'
|
|
498
|
-
default == "'[]'" ? '[]' : '{}'
|
|
496
|
+
(default == "'[]'") ? '[]' : '{}'
|
|
499
497
|
else
|
|
500
|
-
|
|
498
|
+
/^'.*'$/.match?(default) ? "\"#{default[1..-2]}\"" : default
|
|
501
499
|
end
|
|
502
500
|
end
|
|
503
501
|
|
|
504
502
|
def format_index(index_name, index_data)
|
|
505
503
|
idx_def = "t.index "
|
|
506
504
|
|
|
507
|
-
if index_data[:columns].size == 1
|
|
508
|
-
|
|
505
|
+
idx_def += if index_data[:columns].size == 1
|
|
506
|
+
"[\"#{index_data[:columns].first}\"]"
|
|
509
507
|
else
|
|
510
|
-
|
|
508
|
+
"[#{index_data[:columns].map { |c| "\"#{c}\"" }.join(', ')}]"
|
|
511
509
|
end
|
|
512
510
|
|
|
513
511
|
idx_def += ", name: \"#{index_name}\""
|
|
@@ -522,12 +520,12 @@ module FastSchemaDumper
|
|
|
522
520
|
end
|
|
523
521
|
|
|
524
522
|
unless order_hash.empty?
|
|
525
|
-
if index_data[:columns].size == 1
|
|
523
|
+
idx_def += if index_data[:columns].size == 1
|
|
526
524
|
# For single column index, use simplified syntax
|
|
527
|
-
|
|
525
|
+
", order: :#{order_hash.values.first}"
|
|
528
526
|
else
|
|
529
527
|
# For compound index, use hash syntax
|
|
530
|
-
|
|
528
|
+
", order: { #{order_hash.map { |k, v| "#{k}: :#{v}" }.join(', ')} }"
|
|
531
529
|
end
|
|
532
530
|
end
|
|
533
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
|
|
@@ -46,6 +46,7 @@ executables:
|
|
|
46
46
|
extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
|
48
48
|
files:
|
|
49
|
+
- ".standard.yml"
|
|
49
50
|
- CHANGELOG.md
|
|
50
51
|
- README.md
|
|
51
52
|
- Rakefile
|
|
@@ -55,6 +56,8 @@ files:
|
|
|
55
56
|
- lib/fast_schema_dumper/fast_dumper.rb
|
|
56
57
|
- lib/fast_schema_dumper/ridgepole.rb
|
|
57
58
|
- lib/fast_schema_dumper/version.rb
|
|
59
|
+
- test/fast_schema_dumper_test.rb
|
|
60
|
+
- test/test_helper.rb
|
|
58
61
|
homepage: https://github.com/osyoyu/fast_schema_dumper
|
|
59
62
|
licenses: []
|
|
60
63
|
metadata:
|