Skip to content

Commit 31c6d20

Browse files
committed
fix: implement performance indexes
1 parent e893864 commit 31c6d20

3 files changed

Lines changed: 25 additions & 31 deletions

File tree

db/migrate/20241001000014_create_notifications.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def change
2828
t.timestamps null: false
2929
end
3030

31-
add_index :notifications, :user_id
31+
# Note: :user_id index is automatically created by t.references above
3232
add_index :notifications, :is_read
3333
add_index :notifications, :created_at, order: { created_at: :desc }
3434

db/migrate/20251016000001_add_performance_indexes.rb renamed to db/migrate/20251016000001_add_basic_performance_indexes.rb

File renamed without changes.

db/schema.rb

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,12 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.2].define(version: 2026_02_08_200854) do
13+
ActiveRecord::Schema[7.2].define(version: 2026_02_12_000000) do
1414
create_schema "auth"
15-
create_schema "extensions"
16-
create_schema "graphql"
17-
create_schema "graphql_public"
18-
create_schema "pgbouncer"
19-
create_schema "realtime"
20-
create_schema "storage"
21-
create_schema "supabase_migrations"
22-
create_schema "vault"
2315

2416
# These are extensions that must be enabled in order to support this database
25-
enable_extension "pg_graphql"
26-
enable_extension "pg_stat_statements"
2717
enable_extension "pgcrypto"
2818
enable_extension "plpgsql"
29-
enable_extension "supabase_vault"
30-
enable_extension "uuid-ossp"
3119

3220
create_table "audit_logs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
3321
t.uuid "organization_id", null: false
@@ -178,15 +166,33 @@
178166
t.index ["match_type"], name: "index_matches_on_match_type"
179167
t.index ["organization_id", "created_at"], name: "idx_matches_org_created"
180168
t.index ["organization_id", "game_start", "victory"], name: "idx_matches_org_game_start_victory", comment: "Otimiza queries de winrate por período"
181-
t.index ["organization_id", "game_start"], name: "idx_matches_org_game_start"
182-
t.index ["organization_id", "game_start"], name: "index_matches_on_org_and_game_start"
183-
t.index ["organization_id", "victory"], name: "idx_matches_org_victory"
184-
t.index ["organization_id", "victory"], name: "index_matches_on_org_and_victory"
185169
t.index ["organization_id"], name: "index_matches_on_organization_id"
186170
t.index ["riot_match_id"], name: "index_matches_on_riot_match_id", unique: true
187171
t.index ["victory"], name: "index_matches_on_victory"
188172
end
189173

174+
create_table "notifications", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
175+
t.uuid "user_id", null: false
176+
t.string "title", limit: 200, null: false
177+
t.text "message", null: false
178+
t.string "type", null: false
179+
t.text "link_url"
180+
t.string "link_type", limit: 20
181+
t.uuid "link_id"
182+
t.boolean "is_read", default: false
183+
t.datetime "read_at", precision: nil
184+
t.text "channels", default: ["in_app"], array: true
185+
t.boolean "email_sent", default: false
186+
t.boolean "discord_sent", default: false
187+
t.jsonb "metadata", default: {}
188+
t.datetime "created_at", null: false
189+
t.datetime "updated_at", null: false
190+
t.index ["created_at"], name: "index_notifications_on_created_at", order: :desc
191+
t.index ["is_read"], name: "index_notifications_on_is_read"
192+
t.index ["user_id"], name: "index_notifications_on_user_id"
193+
t.check_constraint "type::text = ANY (ARRAY['info'::character varying, 'success'::character varying, 'warning'::character varying, 'error'::character varying, 'match'::character varying, 'schedule'::character varying, 'system'::character varying]::text[])", name: "notifications_type_check"
194+
end
195+
190196
create_table "opponent_teams", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
191197
t.string "name", null: false
192198
t.string "tag"
@@ -296,9 +302,6 @@
296302
t.datetime "updated_at", null: false
297303
t.index ["champion"], name: "index_player_match_stats_on_champion"
298304
t.index ["match_id", "player_id"], name: "idx_player_stats_match_player_agg", comment: "Otimiza agregações de estatísticas (SUM kills/deaths/assists)"
299-
t.index ["match_id"], name: "idx_player_stats_match"
300-
t.index ["match_id"], name: "index_player_match_stats_on_match"
301-
t.index ["match_id"], name: "index_player_match_stats_on_match_id"
302305
t.index ["player_id", "match_id"], name: "index_player_match_stats_on_player_id_and_match_id", unique: true
303306
t.index ["player_id"], name: "index_player_match_stats_on_player_id"
304307
end
@@ -362,8 +365,6 @@
362365
t.index ["organization_id", "deleted_at"], name: "idx_players_org_deleted_active", where: "(deleted_at IS NULL)", comment: "Índice parcial para COUNT de players ativos"
363366
t.index ["organization_id", "last_sync_at"], name: "idx_players_org_last_sync"
364367
t.index ["organization_id", "role"], name: "index_players_on_org_and_role"
365-
t.index ["organization_id", "status"], name: "idx_players_org_status"
366-
t.index ["organization_id", "status"], name: "index_players_on_org_and_status"
367368
t.index ["organization_id", "sync_status"], name: "idx_players_org_sync_status"
368369
t.index ["organization_id"], name: "index_players_on_organization_id"
369370
t.index ["player_access_enabled"], name: "index_players_on_player_access_enabled", comment: "Quick lookup for players with access enabled"
@@ -402,16 +403,12 @@
402403
t.jsonb "metadata", default: {}
403404
t.datetime "created_at", null: false
404405
t.datetime "updated_at", null: false
405-
t.uuid "scrim_id"
406406
t.index ["created_by_id"], name: "index_schedules_on_created_by_id"
407407
t.index ["event_type"], name: "index_schedules_on_event_type"
408408
t.index ["match_id"], name: "index_schedules_on_match_id"
409409
t.index ["organization_id", "event_type"], name: "idx_schedules_org_event_type"
410410
t.index ["organization_id", "start_time", "event_type"], name: "idx_schedules_org_time_type", comment: "Otimiza queries de próximos eventos"
411-
t.index ["organization_id", "start_time", "event_type"], name: "index_schedules_on_org_time_type"
412-
t.index ["organization_id", "start_time"], name: "idx_schedules_org_time"
413411
t.index ["organization_id"], name: "index_schedules_on_organization_id"
414-
t.index ["scrim_id"], name: "index_schedules_on_scrim_id"
415412
t.index ["start_time"], name: "index_schedules_on_start_time"
416413
t.index ["status"], name: "index_schedules_on_status"
417414
end
@@ -609,7 +606,6 @@
609606
t.index ["category"], name: "index_team_goals_on_category"
610607
t.index ["created_by_id"], name: "index_team_goals_on_created_by_id"
611608
t.index ["organization_id", "status"], name: "idx_team_goals_org_status", comment: "Otimiza COUNT de goals por status"
612-
t.index ["organization_id", "status"], name: "index_team_goals_on_org_and_status"
613609
t.index ["organization_id"], name: "index_team_goals_on_organization_id"
614610
t.index ["player_id"], name: "index_team_goals_on_player_id"
615611
t.index ["status"], name: "index_team_goals_on_status"
@@ -638,11 +634,9 @@
638634
t.datetime "last_login_at", precision: nil
639635
t.datetime "created_at", null: false
640636
t.datetime "updated_at", null: false
641-
t.string "supabase_uid"
642637
t.index ["email"], name: "index_users_on_email", unique: true
643638
t.index ["organization_id"], name: "index_users_on_organization_id"
644639
t.index ["role"], name: "index_users_on_role"
645-
t.index ["supabase_uid"], name: "index_users_on_supabase_uid"
646640
end
647641

648642
create_table "vod_reviews", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
@@ -702,14 +696,14 @@
702696
add_foreign_key "draft_plans", "users", column: "created_by_id"
703697
add_foreign_key "draft_plans", "users", column: "updated_by_id"
704698
add_foreign_key "matches", "organizations"
699+
add_foreign_key "notifications", "users"
705700
add_foreign_key "password_reset_tokens", "users"
706701
add_foreign_key "player_match_stats", "matches"
707702
add_foreign_key "player_match_stats", "players"
708703
add_foreign_key "players", "organizations"
709704
add_foreign_key "players", "organizations", column: "previous_organization_id", on_delete: :nullify
710705
add_foreign_key "schedules", "matches"
711706
add_foreign_key "schedules", "organizations"
712-
add_foreign_key "schedules", "scrims", on_delete: :cascade
713707
add_foreign_key "schedules", "users", column: "created_by_id"
714708
add_foreign_key "scouting_watchlists", "organizations"
715709
add_foreign_key "scouting_watchlists", "scouting_targets"

0 commit comments

Comments
 (0)