From dd67a5d38a3ce8361f80f47f248f3800eda73e5e Mon Sep 17 00:00:00 2001 From: abicky Date: Sun, 9 Aug 2020 23:49:28 +0900 Subject: [PATCH] Fix unexpected differences on text types and blob types on Rails 6 This commit resolves https://github.com/winebarrel/ridgepole/issues/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. --- lib/ridgepole/diff.rb | 12 ++++++++++++ spec/mysql/text_blob_types/text_blob_types_spec.rb | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/ridgepole/diff.rb b/lib/ridgepole/diff.rb index 1e1f879c..a68869e2 100644 --- a/lib/ridgepole/diff.rb +++ b/lib/ridgepole/diff.rb @@ -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 diff --git a/spec/mysql/text_blob_types/text_blob_types_spec.rb b/spec/mysql/text_blob_types/text_blob_types_spec.rb index 9a2a7ba0..a190640a 100644 --- a/spec/mysql/text_blob_types/text_blob_types_spec.rb +++ b/spec/mysql/text_blob_types/text_blob_types_spec.rb @@ -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 @@ -20,6 +20,7 @@ t.unsigned_integer :unsigned_integer end RUBY + delta = subject.diff(table_def) expect(delta.differ?).to be_truthy delta.migrate @@ -39,6 +40,8 @@ t.integer "unsigned_integer", unsigned: true end ERB + + expect(subject.diff(table_def).differ?).to be_falsey end end