Link Character and Weapon tables with granblue_id (#154)

* Add recruits column to weapons

* Populate recruits column with granblue_ids

* Remove recruits_id and index recruits
This commit is contained in:
Justin Edmund 2025-01-15 02:11:06 -08:00 committed by GitHub
parent 386515cd18
commit 0d46cb3833
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 50 additions and 4 deletions

View file

@ -0,0 +1,30 @@
# frozen_string_literal: true
class PopulateWeaponRecruits < ActiveRecord::Migration[7.0]
def up
# Get all character mappings and convert to hash properly
results = execute(<<-SQL)
SELECT id, granblue_id
FROM characters
WHERE granblue_id IS NOT NULL
SQL
character_mapping = {}
results.each do |row|
character_mapping[row['id']] = row['granblue_id']
end
# Update weapons table using the mapping
character_mapping.each do |char_id, granblue_id|
execute(<<-SQL)
UPDATE weapons
SET recruits = #{connection.quote(granblue_id)}
WHERE recruits_id = #{connection.quote(char_id)}
SQL
end
end
def down
execute("UPDATE weapons SET recruits = NULL")
end
end

View file

@ -1 +1 @@
DataMigrate::Data.define(version: 20231119051223)
DataMigrate::Data.define(version: 20250115094623)

View file

@ -0,0 +1,5 @@
class AddRecruitsToWeapons < ActiveRecord::Migration[7.0]
def change
add_column :weapons, :recruits, :string
end
end

View file

@ -0,0 +1,6 @@
class RemoveRecruitsIdFromWeapons < ActiveRecord::Migration[7.0]
def change
remove_column :weapons, :recruits_id, :uuid
remove_index :weapons, :recruits_id if index_exists?(:weapons, :recruits_id)
end
end

View file

@ -0,0 +1,5 @@
class AddIndexToWeaponRecruits < ActiveRecord::Migration[7.0]
def change
add_index :weapons, :recruits
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2025_01_10_070255) do
ActiveRecord::Schema[7.0].define(version: 2025_01_15_100356) do
# These are extensions that must be enabled in order to support this database
enable_extension "btree_gin"
enable_extension "pg_trgm"
@ -456,7 +456,6 @@ ActiveRecord::Schema[7.0].define(version: 2025_01_10_070255) do
t.integer "ax_type"
t.boolean "limit", default: false, null: false
t.boolean "ax", default: false, null: false
t.uuid "recruits_id"
t.integer "max_awakening_level"
t.date "release_date"
t.date "flb_date"
@ -469,8 +468,9 @@ ActiveRecord::Schema[7.0].define(version: 2025_01_10_070255) do
t.string "nicknames_jp", default: [], null: false, array: true
t.boolean "transcendence", default: false
t.date "transcendence_date"
t.string "recruits"
t.index ["name_en"], name: "index_weapons_on_name_en", opclass: :gin_trgm_ops, using: :gin
t.index ["recruits_id"], name: "index_weapons_on_recruits_id"
t.index ["recruits"], name: "index_weapons_on_recruits"
end
add_foreign_key "favorites", "parties"