hensei-api/db/migrate
Justin Edmund 6cf11e6517
Jedmund/fix image embeds 4 (#177)
* Update gitignore

There is a mystery postgres folder and we are going to ignore it

* Add migrations

* Update preview state default to pending
* Adds indexes
* Adds PgHero and PgStatements

* Update .gitignore

* Update Gemfile

Production:
- `newrelic_rpm`

Development:
- `pg_query`
- `prosopite`

* Configure Sidekiq

Create job for cleaning up party previews

* Configure Prosopite and remove CacheFreeLogger

* Enable query logging

* Update api_controller.rb

Add N+1 detectioin via Prosopite in development/test environments

* Refactor canonical object blueprints

* Refactor grid object blueprints

* Remove N+1 from grid object models

Reimplementing `character` `summon` and `weapon` was making N+1s which made queries really slow

* Add counter caches to party

* Add preview generation helpers

The Party model can respond to queries about its preview state with the following models:
- `schedule_preview_generation`
- `preview_content_changed?`
- `preview_expired?`
- `should_generate_preview?`
- `ready_for_preview?`
- `needs_preview_generation?`
- `preview_relevant_attributes`

Removes the following methods:
- `schedule_preview_regeneration`
- `preview_relevant_changes?`

* Add cache to is_favorited(user)

* Refactored PartyBlueprint to minimize N+1s

* Remove preview expiry constants

These are defined in the Coordinator instead

* Add method comments

* Create parties_controller.rbs

* Update logic and logs

* Updates excluded methods and calculate_count

* Use `includes` instead of `joins`
* Use a less-insane way of counting

* Adds a helper method for party privacy

* Update filter condition helpers

Just minor refactoring

* Fix old view name in PartyBlueprint

* Refactor parties#create

* Remove redundant return

* Update parties_controller.rbs

* Update parties#index

* Update parties_controller.rb

Updates apply_includes and apply_excludes, along with modifying id_to_table and build_query

* Update parties_controller.rb

Adds the rest of the changes, too tired to write them all out. Some preview generation, some filtering

* Refactor parties#index and parties#favorites

These are mostly the same methods, so we remove common code into build_parties_query and render_paginated_parties

* Alias table name to object to maintain API consistency

* Maintain API consistency with raid blueprint

* Optimize party loading by adding eager loading to `set_from_slug`

- Refactored `set_from_slug` to use `includes` for eager loading associated models:
  - `user`, `job`, `raid` (with `group`)
  - `characters` (with `character` and `awakening`)
  - `weapons` (with `weapon`, `awakenings`, `weapon_key1`, `weapon_key2`, `weapon_key3`)
  - `summons` (with `summon`)
  - `guidebooks` (`guidebook1`, `guidebook2`, `guidebook3`)
  - `source_party`, `remixes`, `skills`, and `accessory`
- This change improves query efficiency by reducing N+1 queries and ensures all relevant associations are preloaded.
- Removed redundant favorite check as it was not necessary in this context.

* Refactor grid blueprints

- **GridCharacterBlueprint:**
  - Removed `:minimal` view restriction on `party` association.
  - Improved nil checks for `ring1`, `ring2`, and `earring` to prevent errors.
  - Converted string values in `awakening_level`, `over_mastery`, and `aetherial_mastery` fields to integers for consistency.
  - Ensured `over_mastery` and `aetherial_mastery` only include valid entries, filtering out blank or zero-modifier values.

- **GridWeaponBlueprint:**
  - Removed `:minimal` view restriction on `party` association.
  - Ensured `weapon` association exists before accessing `ax`, `series`, or `awakening`.
  - Improved conditional checks for `weapon_keys` to prevent errors when `weapon` or `series` is nil.
  - Converted `awakening_level` field to integer for consistency.

- **GridCharacterBlueprint:**
  - Removed `:minimal` view restriction on `party` association.

* Update raid blueprints

- Show flat representation of raid group in RaidBlueprint's nested view
- Show nested representation of raid in RaidGroupBlueprint's full view

* Move n+1 detection to around_action hook

* Improve handling mastery bonuses

- Improved handling of nested attributes:
  - Replaced old mastery structure with new `rings` and `awakening` assignments.
  - Added `new_rings` and `new_awakening` virtual attributes for easier updates.
  - Updated `assign_attributes` to exclude `rings` and `awakening` to prevent conflicts.

- Enhanced parameter transformation:
  - Introduced `transform_character_params` to process `rings`, `awakening`, and `earring` more reliably.
  - Ensured proper type conversion (`to_i`) for numeric values in `uncap_level`, `transcendence_step`, and `awakening_level`.
  - Improved error handling for missing values by setting defaults where needed.

- Optimized database queries:
  - Added `.includes(:awakening)` to `set` to prevent N+1 query issues.

- Updated strong parameters:
  - Changed `rings` from individual keys (`ring1`, `ring2`, etc.) to a structured array format.
  - Refactored permitted attributes to align with the new nested structure.

* Eager-load jobs when querying job skills

* Eager load raids/groups when querying

* Update users_controller.rb

More efficient way of denoting favorited parties.

* Update awakening.rb

- Removes explicitly defined associations and adds ActiveRecord associations instead

* Update party.rb

- Removes favorited accessor
- Renames derivative_parties to remixes and adds in-built sort

* Update weapon_awakening.rb

- Removes redefined explicit associations

* Update grid_character.rb

- Adds code transforming incoming ring and awakening values into something the db understands

* Update character.rb

Add explicit Awakenings enum

* Update coordinator.rb

Adds 'queued' as a state for generation
2025-02-09 22:50:18 -08:00
..
20230618051638_init_schema.rb (Hotfix) Fix stale migrations (#107) 2023-06-21 00:35:31 -07:00
20230619000621_squasher_clean.rb June 2023 Update (#102) 2023-06-19 03:53:48 -07:00
20230619003446_add_awakenings_table.rb June 2023 Update (#102) 2023-06-19 03:53:48 -07:00
20230619003480_create_weapon_awakenings_table.rb June 2023 Update (#102) 2023-06-19 03:53:48 -07:00
20230619003502_add_max_awakening_level_to_weapons.rb June 2023 Update (#102) 2023-06-19 03:53:48 -07:00
20230619005403_add_order_to_awakenings.rb June 2023 Update (#102) 2023-06-19 03:53:48 -07:00
20230619013722_rename_type_to_object_type_in_awakenings.rb June 2023 Update (#102) 2023-06-19 03:53:48 -07:00
20230619013850_remove_awakening_from_weapon.rb June 2023 Update (#102) 2023-06-19 03:53:48 -07:00
20230619015030_add_new_awakening_type_to_grid_weapons.rb June 2023 Update (#102) 2023-06-19 03:53:48 -07:00
20230619020744_remove_awakening_type_from_grid_weapon.rb June 2023 Update (#102) 2023-06-19 03:53:48 -07:00
20230619043556_add_new_awakening_id_to_grid_characters.rb June 2023 Update (#102) 2023-06-19 03:53:48 -07:00
20230619045651_remove_awakening_from_grid_characters.rb June 2023 Update (#102) 2023-06-19 03:53:48 -07:00
20230621073125_re_add_quick_summon_and_auto_summon_to_grid_summons_and_parties.rb (Hotfix) Fix stale migrations (#107) 2023-06-21 00:35:31 -07:00
20230702035508_add_remix_flag_to_parties.rb Deploy July Quality Update (#114) 2023-07-04 00:40:06 -07:00
20230705065015_create_pg_search_documents.rb July 2023 Feature Release: Tagging objects (#118) 2023-07-05 21:51:36 -07:00
20230716132629_add_gbf_wiki_to_character.rb Implement wiki parsers (#121) 2023-08-19 23:05:32 -07:00
20230717011150_add_columns_to_characters.rb Implement wiki parsers (#121) 2023-08-19 23:05:32 -07:00
20230816015828_add_columns_to_weapons.rb Implement wiki parsers (#121) 2023-08-19 23:05:32 -07:00
20230816015904_add_columns_to_summons.rb Implement wiki parsers (#121) 2023-08-19 23:05:32 -07:00
20230820045019_add_xlb_date_to_summons.rb Implement wiki parsers (#121) 2023-08-19 23:05:32 -07:00
20230820113800_add_nicknames_to_characters.rb Update item search with better fallbacks and nicknames (#122) 2023-08-20 00:46:25 -07:00
20230820113810_add_nicknames_to_summons.rb Update item search with better fallbacks and nicknames (#122) 2023-08-20 00:46:25 -07:00
20230820113900_add_nicknames_to_weapons.rb Update item search with better fallbacks and nicknames (#122) 2023-08-20 00:46:25 -07:00
20230824222028_add_role_to_users.rb Implement roles and visibility (#128) 2023-08-25 15:53:56 -07:00
20230824222107_add_visibility_to_parties.rb Implement roles and visibility (#128) 2023-08-25 15:53:56 -07:00
20231119051213_add_new_series_to_weapon_keys.rb API updates for Draconic Weapons Providence (#138) 2023-12-26 03:21:06 -08:00
20231119051231_rename_new_series_and_delete_series.rb API updates for Draconic Weapons Providence (#138) 2023-12-26 03:21:06 -08:00
20240113175218_add_transcendence_to_weapon.rb Add support for weapon transcendence (#142) 2024-01-15 14:05:17 -08:00
20240113175229_add_transcendence_level_to_grid_weapon.rb Add support for weapon transcendence (#142) 2024-01-15 14:05:17 -08:00
20240113180227_add_weapon_key_4_to_grid_weapon.rb Add support for weapon transcendence (#142) 2024-01-15 14:05:17 -08:00
20240113181526_rename_summon_xlb_to_transcendence.rb Add support for weapon transcendence (#142) 2024-01-15 14:05:17 -08:00
20240126032358_change_transcend_date_to_date.rb Fix transcendence date column type (#144) 2024-01-25 19:35:21 -08:00
20250110070255_create_data_versions.rb Create pipeline for importing data via PRs (#148) 2025-01-13 05:33:04 -08:00
20250115094528_add_recruits_to_weapons.rb Link Character and Weapon tables with granblue_id (#154) 2025-01-15 02:11:06 -08:00
20250115100327_remove_recruits_id_from_weapons.rb Link Character and Weapon tables with granblue_id (#154) 2025-01-15 02:11:06 -08:00
20250115100356_add_index_to_weapon_recruits.rb Link Character and Weapon tables with granblue_id (#154) 2025-01-15 02:11:06 -08:00
20250118135254_add_preview_columns_to_parties.rb Implement embed images (#173) 2025-01-18 09:08:15 -08:00
20250119062554_add_preview_s3_key_to_parties.rb More embed image bandaids (#175) 2025-01-18 22:32:13 -08:00
20250120214715_set_preview_state_default_to_pending.rb Jedmund/fix image embeds 4 (#177) 2025-02-09 22:50:18 -08:00
20250120224953_add_missing_indexes_to_parties.rb Jedmund/fix image embeds 4 (#177) 2025-02-09 22:50:18 -08:00
20250201030154_add_missing_indexes_to_grid_objects.rb Jedmund/fix image embeds 4 (#177) 2025-02-09 22:50:18 -08:00
20250201041406_create_pghero_query_stats.rb Jedmund/fix image embeds 4 (#177) 2025-02-09 22:50:18 -08:00
20250201120655_enable_pg_statements.rb Jedmund/fix image embeds 4 (#177) 2025-02-09 22:50:18 -08:00
20250201120842_remove_unused_index.rb Jedmund/fix image embeds 4 (#177) 2025-02-09 22:50:18 -08:00
20250201170037_add_optimized_indexes_to_parties.rb Jedmund/fix image embeds 4 (#177) 2025-02-09 22:50:18 -08:00