Skip to content

Commit

Permalink
migrate synonyns to synonyms_new in animes and mangas (#1278)
Browse files Browse the repository at this point in the history
  • Loading branch information
morr committed Jun 3, 2017
1 parent 11956da commit 3ef3e57
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
@@ -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 db/migrate/20170603151425_migrate_synonyms_to_synonyms_new.rb
@@ -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
8 changes: 5 additions & 3 deletions db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170602114107) do
ActiveRecord::Schema.define(version: 20170603151425) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -105,7 +105,6 @@
t.string "kind", limit: 255
t.integer "episodes", default: 0, null: false
t.integer "duration"
t.text "synonyms"
t.decimal "score", default: "0.0", null: false
t.integer "ranked"
t.integer "popularity"
Expand Down Expand Up @@ -135,6 +134,8 @@
t.string "japanese"
t.integer "mal_id"
t.datetime "authorized_imported_at"
t.text "synonyms_new", default: [], null: false, array: true
t.text "synonyms"
t.index ["kind"], name: "index_animes_on_kind", using: :btree
t.index ["name"], name: "index_animes_on_name", using: :btree
t.index ["russian"], name: "index_animes_on_russian", using: :btree
Expand Down Expand Up @@ -574,7 +575,6 @@
t.integer "chapters", default: 0, null: false
t.integer "chapters_aired", default: 0, null: false
t.string "status", limit: 255
t.text "synonyms"
t.string "russian", limit: 255
t.decimal "score", default: "0.0", null: false
t.integer "ranked"
Expand All @@ -600,6 +600,8 @@
t.integer "mal_id"
t.string "type"
t.datetime "authorized_imported_at"
t.text "synonyms_new", default: [], null: false, array: true
t.text "synonyms"
t.index ["kind"], name: "index_mangas_on_kind", using: :btree
t.index ["name"], name: "index_mangas_on_name", using: :btree
t.index ["russian"], name: "index_mangas_on_russian", using: :btree
Expand Down

0 comments on commit 3ef3e57

Please sign in to comment.