Skip to content

Commit

Permalink
Fix unexpected differences on text types and blob types on Rails 6
Browse files Browse the repository at this point in the history
This commit resolves ridgepole#305.
The schema dumper on Rails 6 outputs text types and binary types
with the option "size", but ridgepole parses them with the
option "limit". That makes unexpected differences.
  • Loading branch information
abicky committed Aug 9, 2020
1 parent 8320f72 commit dd67a5d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/ridgepole/diff.rb
Expand Up @@ -386,6 +386,18 @@ def normalize_column_options!(attrs, primary_key = false)
attrs[:type] = :bigint
opts.delete(:limit)
end

if opts[:size] && (attrs[:type] == :text || attrs[:type] == :blob || attrs[:type] == :binary)
case opts.delete(:size)
when :tiny
attrs[:type] = :blob if attrs[:type] == :binary
opts[:limit] = 255
when :medium
opts[:limit] = 16_777_215
when :long
opts[:limit] = 4_294_967_295
end
end
end
end

Expand Down
5 changes: 4 additions & 1 deletion spec/mysql/text_blob_types/text_blob_types_spec.rb
Expand Up @@ -5,7 +5,7 @@
subject { client }

it do
delta = subject.diff(<<-RUBY)
table_def = <<-RUBY
create_table :foos, id: :unsigned_integer do |t|
t.blob :blob
t.tinyblob :tiny_blob
Expand All @@ -20,6 +20,7 @@
t.unsigned_integer :unsigned_integer
end
RUBY
delta = subject.diff(table_def)

expect(delta.differ?).to be_truthy
delta.migrate
Expand All @@ -39,6 +40,8 @@
t.integer "unsigned_integer", unsigned: true
end
ERB

expect(subject.diff(table_def).differ?).to be_falsey
end
end

Expand Down

0 comments on commit dd67a5d

Please sign in to comment.