diff --git a/db/migrate/20181114180205_change_descendant_names_to_array_on_tag_implications.rb b/db/migrate/20181114180205_change_descendant_names_to_array_on_tag_implications.rb index a6016f065..71835b5fe 100644 --- a/db/migrate/20181114180205_change_descendant_names_to_array_on_tag_implications.rb +++ b/db/migrate/20181114180205_change_descendant_names_to_array_on_tag_implications.rb @@ -1,8 +1,10 @@ class ChangeDescendantNamesToArrayOnTagImplications < ActiveRecord::Migration[5.2] def up TagImplication.without_timeout do - change_column_default :tag_implications, :descendant_names, from: '', to: nil - change_column :tag_implications, :descendant_names, "text[]", using: "string_to_array(descendant_names, ' ')::text[]", default: "{}" + add_column :tag_implications, :descendant_names_array, "text[]", default: "{}" + execute "update tag_implications set descendant_names_array = string_to_array(descendant_names, ' ')::text[]" + remove_column :tag_implications, :descendant_names + rename_column :tag_implications, :descendant_names_array, :descendant_names end end diff --git a/db/migrate/20181114185032_change_strings_to_arrays_on_artist_versions.rb b/db/migrate/20181114185032_change_strings_to_arrays_on_artist_versions.rb index 2eebd2779..6d73b2f33 100644 --- a/db/migrate/20181114185032_change_strings_to_arrays_on_artist_versions.rb +++ b/db/migrate/20181114185032_change_strings_to_arrays_on_artist_versions.rb @@ -1,11 +1,14 @@ class ChangeStringsToArraysOnArtistVersions < ActiveRecord::Migration[5.2] def up ArtistVersion.without_timeout do - change_column_default :artist_versions, :other_names, from: '', to: nil - change_column :artist_versions, :other_names, "text[]", using: "array_remove(regexp_split_to_array(other_names, '\\s+'), '')", default: "{}" + add_column :artist_versions, :other_names_array, "text[]", default: "{}" + execute "update artist_versions set other_names_array = array_remove(regexp_split_to_array(other_names, '\\s+'), '')" + remove_column :artist_versions, :other_names + rename_column :artist_versions, :other_names_array, :other_names - change_column :artist_versions, :url_string, "text[]", using: "array_remove(regexp_split_to_array(url_string, '\\s+'), '')", default: "{}" - rename_column :artist_versions, :url_string, :urls + add_column :artist_versions, :urls, "text[]", default: "{}" + execute "update artist_versions set urls = array_remove(regexp_split_to_array(url_string, '\\s+'), '')" + remove_column :artist_versions, :url_string end end diff --git a/test/unit/artist_url_test.rb b/test/unit/artist_url_test.rb index 75b8c963f..feb6b31f8 100644 --- a/test/unit/artist_url_test.rb +++ b/test/unit/artist_url_test.rb @@ -65,7 +65,6 @@ class ArtistUrlTest < ActiveSupport::TestCase setup do @urls = [ FactoryBot.create(:artist_url, url: "https://www.artstation.com/koyorin"), - FactoryBot.create(:artist_url, url: "https://www.artstation.com/artist/koyorin"), FactoryBot.create(:artist_url, url: "https://koyorin.artstation.com"), FactoryBot.create(:artist_url, url: "https://www.artstation.com/artwork/04XA4") ] @@ -74,8 +73,7 @@ class ArtistUrlTest < ActiveSupport::TestCase should "normalize" do assert_equal("http://www.artstation.com/koyorin/", @urls[0].normalized_url) assert_equal("http://www.artstation.com/koyorin/", @urls[1].normalized_url) - assert_equal("http://www.artstation.com/koyorin/", @urls[2].normalized_url) - assert_equal("http://www.artstation.com/jeyrain/", @urls[3].normalized_url) + assert_equal("http://www.artstation.com/jeyrain/", @urls[2].normalized_url) end end