Add migrations

* Update preview state default to pending
* Adds indexes
* Adds PgHero and PgStatements
This commit is contained in:
Justin Edmund 2025-02-07 01:30:08 -08:00
parent 8409fcabcf
commit f914c1f16e
8 changed files with 91 additions and 4 deletions

View file

@ -0,0 +1,7 @@
class SetPreviewStateDefaultToPending < ActiveRecord::Migration[8.0]
def up
Party.where(preview_state: nil).find_each do |party|
party.update_column(:preview_state, :pending)
end
end
end

View file

@ -0,0 +1,12 @@
class AddMissingIndexesToParties < ActiveRecord::Migration[8.0]
def change
add_index :parties, :visibility
add_index :parties, :element
add_index :parties, :created_at
add_index :parties, [:weapons_count, :characters_count, :summons_count],
name: 'index_parties_on_counters'
add_index :parties, [:visibility, :created_at],
name: 'index_parties_on_visibility_created_at'
add_index :parties, :shortcode
end
end

View file

@ -0,0 +1,8 @@
class AddMissingIndexesToGridObjects < ActiveRecord::Migration[8.0]
def change
add_index :parties, :raid_id unless index_exists?(:parties, :raid_id)
add_index :characters, :granblue_id unless index_exists?(:characters, :granblue_id)
add_index :summons, :granblue_id unless index_exists?(:summons, :granblue_id)
add_index :weapons, :granblue_id unless index_exists?(:weapons, :granblue_id)
end
end

View file

@ -0,0 +1,15 @@
class CreatePgheroQueryStats < ActiveRecord::Migration[8.0]
def change
create_table :pghero_query_stats do |t|
t.text :database
t.text :user
t.text :query
t.integer :query_hash, limit: 8
t.float :total_time
t.integer :calls, limit: 8
t.timestamp :captured_at
end
add_index :pghero_query_stats, [:database, :captured_at]
end
end

View file

@ -0,0 +1,9 @@
class EnablePgStatements < ActiveRecord::Migration[8.0]
def up
execute 'CREATE EXTENSION IF NOT EXISTS pg_stat_statements;'
end
def down
execute 'DROP EXTENSION IF EXISTS pg_stat_statements;'
end
end

View file

@ -0,0 +1,5 @@
class RemoveUnusedIndex < ActiveRecord::Migration[8.0]
def change
remove_index :parties, :visibility
end
end

View file

@ -0,0 +1,8 @@
class AddOptimizedIndexesToParties < ActiveRecord::Migration[8.0]
def change
# Add composite index for grid positions since we order by these
add_index :grid_weapons, [:party_id, :position], name: 'index_grid_weapons_on_party_id_and_position'
add_index :grid_characters, [:party_id, :position], name: 'index_grid_characters_on_party_id_and_position'
add_index :grid_summons, [:party_id, :position], name: 'index_grid_summons_on_party_id_and_position'
end
end

View file

@ -10,13 +10,13 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.0].define(version: 2025_01_19_062554) do ActiveRecord::Schema[8.0].define(version: 2025_02_01_170037) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "btree_gin" enable_extension "btree_gin"
enable_extension "pg_catalog.plpgsql" enable_extension "pg_catalog.plpgsql"
enable_extension "pg_stat_statements"
enable_extension "pg_trgm" enable_extension "pg_trgm"
enable_extension "pgcrypto" enable_extension "pgcrypto"
enable_extension "uuid-ossp"
create_table "app_updates", primary_key: "updated_at", id: :datetime, force: :cascade do |t| create_table "app_updates", primary_key: "updated_at", id: :datetime, force: :cascade do |t|
t.string "update_type", null: false t.string "update_type", null: false
@ -67,6 +67,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_19_062554) do
t.string "kamigame", default: "" t.string "kamigame", default: ""
t.string "nicknames_en", default: [], null: false, array: true t.string "nicknames_en", default: [], null: false, array: true
t.string "nicknames_jp", default: [], null: false, array: true t.string "nicknames_jp", default: [], null: false, array: true
t.index ["granblue_id"], name: "index_characters_on_granblue_id"
t.index ["name_en"], name: "index_characters_on_name_en", opclass: :gin_trgm_ops, using: :gin t.index ["name_en"], name: "index_characters_on_name_en", opclass: :gin_trgm_ops, using: :gin
end end
@ -129,6 +130,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_19_062554) do
t.integer "awakening_level", default: 1 t.integer "awakening_level", default: 1
t.index ["awakening_id"], name: "index_grid_characters_on_awakening_id" t.index ["awakening_id"], name: "index_grid_characters_on_awakening_id"
t.index ["character_id"], name: "index_grid_characters_on_character_id" t.index ["character_id"], name: "index_grid_characters_on_character_id"
t.index ["party_id", "position"], name: "index_grid_characters_on_party_id_and_position"
t.index ["party_id"], name: "index_grid_characters_on_party_id" t.index ["party_id"], name: "index_grid_characters_on_party_id"
end end
@ -143,6 +145,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_19_062554) do
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "transcendence_step", default: 0, null: false t.integer "transcendence_step", default: 0, null: false
t.boolean "quick_summon", default: false t.boolean "quick_summon", default: false
t.index ["party_id", "position"], name: "index_grid_summons_on_party_id_and_position"
t.index ["party_id"], name: "index_grid_summons_on_party_id" t.index ["party_id"], name: "index_grid_summons_on_party_id"
t.index ["summon_id"], name: "index_grid_summons_on_summon_id" t.index ["summon_id"], name: "index_grid_summons_on_summon_id"
end end
@ -168,6 +171,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_19_062554) do
t.integer "transcendence_step", default: 0 t.integer "transcendence_step", default: 0
t.string "weapon_key4_id" t.string "weapon_key4_id"
t.index ["awakening_id"], name: "index_grid_weapons_on_awakening_id" t.index ["awakening_id"], name: "index_grid_weapons_on_awakening_id"
t.index ["party_id", "position"], name: "index_grid_weapons_on_party_id_and_position"
t.index ["party_id"], name: "index_grid_weapons_on_party_id" t.index ["party_id"], name: "index_grid_weapons_on_party_id"
t.index ["weapon_id"], name: "index_grid_weapons_on_weapon_id" t.index ["weapon_id"], name: "index_grid_weapons_on_weapon_id"
t.index ["weapon_key1_id"], name: "index_grid_weapons_on_weapon_key1_id" t.index ["weapon_key1_id"], name: "index_grid_weapons_on_weapon_key1_id"
@ -304,18 +308,24 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_19_062554) do
t.datetime "preview_generated_at" t.datetime "preview_generated_at"
t.string "preview_s3_key" t.string "preview_s3_key"
t.index ["accessory_id"], name: "index_parties_on_accessory_id" t.index ["accessory_id"], name: "index_parties_on_accessory_id"
t.index ["created_at"], name: "index_parties_on_created_at"
t.index ["element"], name: "index_parties_on_element"
t.index ["guidebook1_id"], name: "index_parties_on_guidebook1_id" t.index ["guidebook1_id"], name: "index_parties_on_guidebook1_id"
t.index ["guidebook2_id"], name: "index_parties_on_guidebook2_id" t.index ["guidebook2_id"], name: "index_parties_on_guidebook2_id"
t.index ["guidebook3_id"], name: "index_parties_on_guidebook3_id" t.index ["guidebook3_id"], name: "index_parties_on_guidebook3_id"
t.index ["job_id"], name: "index_parties_on_job_id" t.index ["job_id"], name: "index_parties_on_job_id"
t.index ["preview_generated_at"], name: "index_parties_on_preview_generated_at" t.index ["preview_generated_at"], name: "index_parties_on_preview_generated_at"
t.index ["preview_state"], name: "index_parties_on_preview_state" t.index ["preview_state"], name: "index_parties_on_preview_state"
t.index ["raid_id"], name: "index_parties_on_raid_id"
t.index ["shortcode"], name: "index_parties_on_shortcode"
t.index ["skill0_id"], name: "index_parties_on_skill0_id" t.index ["skill0_id"], name: "index_parties_on_skill0_id"
t.index ["skill1_id"], name: "index_parties_on_skill1_id" t.index ["skill1_id"], name: "index_parties_on_skill1_id"
t.index ["skill2_id"], name: "index_parties_on_skill2_id" t.index ["skill2_id"], name: "index_parties_on_skill2_id"
t.index ["skill3_id"], name: "index_parties_on_skill3_id" t.index ["skill3_id"], name: "index_parties_on_skill3_id"
t.index ["source_party_id"], name: "index_parties_on_source_party_id" t.index ["source_party_id"], name: "index_parties_on_source_party_id"
t.index ["user_id"], name: "index_parties_on_user_id" t.index ["user_id"], name: "index_parties_on_user_id"
t.index ["visibility", "created_at"], name: "index_parties_on_visibility_created_at"
t.index ["weapons_count", "characters_count", "summons_count"], name: "index_parties_on_counters"
end end
create_table "pg_search_documents", force: :cascade do |t| create_table "pg_search_documents", force: :cascade do |t|
@ -331,6 +341,17 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_19_062554) do
t.index ["searchable_type", "searchable_id"], name: "index_pg_search_documents_on_searchable" t.index ["searchable_type", "searchable_id"], name: "index_pg_search_documents_on_searchable"
end end
create_table "pghero_query_stats", force: :cascade do |t|
t.text "database"
t.text "user"
t.text "query"
t.bigint "query_hash"
t.float "total_time"
t.bigint "calls"
t.datetime "captured_at", precision: nil
t.index ["database", "captured_at"], name: "index_pghero_query_stats_on_database_and_captured_at"
end
create_table "raid_groups", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| create_table "raid_groups", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "name_en", null: false t.string "name_en", null: false
t.string "name_jp", null: false t.string "name_jp", null: false
@ -349,7 +370,6 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_19_062554) do
t.integer "element" t.integer "element"
t.string "slug" t.string "slug"
t.uuid "group_id" t.uuid "group_id"
t.index ["group_id"], name: "index_raids_on_group_id"
end end
create_table "sparks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| create_table "sparks", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
@ -400,6 +420,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_19_062554) do
t.date "transcendence_date" t.date "transcendence_date"
t.string "nicknames_en", default: [], null: false, array: true t.string "nicknames_en", default: [], null: false, array: true
t.string "nicknames_jp", default: [], null: false, array: true t.string "nicknames_jp", default: [], null: false, array: true
t.index ["granblue_id"], name: "index_summons_on_granblue_id"
t.index ["name_en"], name: "index_summons_on_name_en", opclass: :gin_trgm_ops, using: :gin t.index ["name_en"], name: "index_summons_on_name_en", opclass: :gin_trgm_ops, using: :gin
end end
@ -474,6 +495,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_19_062554) do
t.boolean "transcendence", default: false t.boolean "transcendence", default: false
t.date "transcendence_date" t.date "transcendence_date"
t.string "recruits" t.string "recruits"
t.index ["granblue_id"], name: "index_weapons_on_granblue_id"
t.index ["name_en"], name: "index_weapons_on_name_en", opclass: :gin_trgm_ops, using: :gin t.index ["name_en"], name: "index_weapons_on_name_en", opclass: :gin_trgm_ops, using: :gin
t.index ["recruits"], name: "index_weapons_on_recruits" t.index ["recruits"], name: "index_weapons_on_recruits"
end end
@ -501,9 +523,10 @@ ActiveRecord::Schema[8.0].define(version: 2025_01_19_062554) do
add_foreign_key "parties", "job_skills", column: "skill2_id" add_foreign_key "parties", "job_skills", column: "skill2_id"
add_foreign_key "parties", "job_skills", column: "skill3_id" add_foreign_key "parties", "job_skills", column: "skill3_id"
add_foreign_key "parties", "jobs" add_foreign_key "parties", "jobs"
add_foreign_key "parties", "parties", column: "source_party_id"
add_foreign_key "parties", "raids" add_foreign_key "parties", "raids"
add_foreign_key "parties", "users" add_foreign_key "parties", "users"
add_foreign_key "raids", "raid_groups", column: "group_id" add_foreign_key "raids", "raid_groups", column: "group_id", name: "raids_group_id_fkey"
add_foreign_key "weapon_awakenings", "awakenings" add_foreign_key "weapon_awakenings", "awakenings"
add_foreign_key "weapon_awakenings", "weapons" add_foreign_key "weapon_awakenings", "weapons"
end end