Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrate synonyns to synonyms_new in animes and mangas (#1278)
- Loading branch information
Showing
3 changed files
with
29 additions
and
3 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
db/migrate/20170603150907_add_synonyms_new_to_animes_and_mangas.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddSynonymsNewToAnimesAndMangas < ActiveRecord::Migration[5.0] | ||
def change | ||
add_column :animes, :synonyms_new, :text, default: [], null: false, array: true | ||
add_column :mangas, :synonyms_new, :text, default: [], null: false, array: true | ||
end | ||
end |
18 changes: 18 additions & 0 deletions
18
db/migrate/20170603151425_migrate_synonyms_to_synonyms_new.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class MigrateSynonymsToSynonymsNew < ActiveRecord::Migration[5.0] | ||
def change | ||
migrate_type Anime | ||
migrate_type Manga | ||
end | ||
|
||
private | ||
|
||
def migrate_type klass | ||
count = klass.count | ||
|
||
klass.all.each_with_index do |entry, index| | ||
puts "#{klass.name} #{index} / #{count}" | ||
next if entry.synonyms.blank? | ||
entry.update synonyms_new: entry.synonyms | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters