Skip to content

Commit 04a6498

Browse files
committed
feat: implement internal messenger
1 parent 9c05564 commit 04a6498

2 files changed

Lines changed: 75 additions & 2 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
class RestoreMessagesRecipientId < ActiveRecord::Migration[7.2]
4+
def up
5+
# Restore recipient_id column if missing (DM feature requires it)
6+
unless column_exists?(:messages, :recipient_id)
7+
add_column :messages, :recipient_id, :uuid
8+
9+
add_foreign_key :messages, :users, column: :recipient_id
10+
end
11+
12+
# Restore DM indexes if missing
13+
unless index_exists?(:messages, %i[organization_id user_id recipient_id created_at],
14+
name: 'idx_messages_dm_created_at')
15+
add_index :messages, %i[organization_id user_id recipient_id created_at],
16+
name: 'idx_messages_dm_created_at'
17+
end
18+
19+
unless index_exists?(:messages, %i[organization_id recipient_id user_id created_at],
20+
name: 'idx_messages_dm_reverse')
21+
add_index :messages, %i[organization_id recipient_id user_id created_at],
22+
name: 'idx_messages_dm_reverse'
23+
end
24+
25+
unless index_exists?(:messages, %i[organization_id user_id recipient_id created_at],
26+
name: 'idx_messages_active_dm')
27+
add_index :messages, %i[organization_id user_id recipient_id created_at],
28+
where: 'deleted = false',
29+
name: 'idx_messages_active_dm'
30+
end
31+
32+
# Add recipient_id index for FK lookups
33+
unless index_exists?(:messages, :recipient_id)
34+
add_index :messages, :recipient_id
35+
end
36+
end
37+
38+
def down
39+
remove_index :messages, name: 'idx_messages_dm_created_at', if_exists: true
40+
remove_index :messages, name: 'idx_messages_dm_reverse', if_exists: true
41+
remove_index :messages, name: 'idx_messages_active_dm', if_exists: true
42+
remove_index :messages, :recipient_id, if_exists: true
43+
remove_foreign_key :messages, column: :recipient_id, if_exists: true
44+
remove_column :messages, :recipient_id, if_exists: true
45+
end
46+
end

db/schema.rb

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,24 @@
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_03_19_120001) do
13+
ActiveRecord::Schema[7.2].define(version: 2026_03_22_120000) do
14+
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"
23+
1424
# These are extensions that must be enabled in order to support this database
25+
enable_extension "pg_graphql"
26+
enable_extension "pg_stat_statements"
1527
enable_extension "pgcrypto"
1628
enable_extension "plpgsql"
29+
enable_extension "supabase_vault"
30+
enable_extension "uuid-ossp"
1731

1832
create_table "ai_champion_matrices", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
1933
t.string "champion_a", null: false
@@ -186,23 +200,28 @@
186200
t.index ["match_type"], name: "index_matches_on_match_type"
187201
t.index ["organization_id", "created_at"], name: "idx_matches_org_created"
188202
t.index ["organization_id", "game_start", "victory"], name: "idx_matches_org_game_start_victory", comment: "Otimiza queries de winrate por período"
203+
t.index ["organization_id", "game_start"], name: "idx_matches_org_game_start"
189204
t.index ["organization_id", "id"], name: "idx_matches_org_id"
190205
t.index ["organization_id", "match_type"], name: "idx_matches_org_match_type"
206+
t.index ["organization_id", "victory"], name: "idx_matches_org_victory"
191207
t.index ["organization_id"], name: "index_matches_on_organization_id"
192208
t.index ["riot_match_id"], name: "index_matches_on_riot_match_id", unique: true
193209
t.index ["victory"], name: "index_matches_on_victory"
194210
end
195211

196212
create_table "messages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
197213
t.uuid "user_id", null: false
198-
t.uuid "recipient_id"
199214
t.uuid "organization_id", null: false
200215
t.text "content", null: false
201216
t.boolean "deleted", default: false, null: false
202217
t.datetime "deleted_at"
203218
t.datetime "created_at", null: false
204219
t.datetime "updated_at", null: false
220+
t.uuid "recipient_id"
221+
t.index ["organization_id", "created_at"], name: "idx_messages_active_by_org", where: "(deleted = false)"
222+
t.index ["organization_id", "created_at"], name: "idx_messages_org_created_at"
205223
t.index ["organization_id", "recipient_id", "user_id", "created_at"], name: "idx_messages_dm_reverse"
224+
t.index ["organization_id", "user_id", "created_at"], name: "idx_messages_org_user_created_at"
206225
t.index ["organization_id", "user_id", "recipient_id", "created_at"], name: "idx_messages_active_dm", where: "(deleted = false)"
207226
t.index ["organization_id", "user_id", "recipient_id", "created_at"], name: "idx_messages_dm_created_at"
208227
t.index ["organization_id"], name: "index_messages_on_organization_id"
@@ -358,6 +377,7 @@
358377
t.index ["champion"], name: "index_player_match_stats_on_champion"
359378
t.index ["crowd_control_score"], name: "idx_pms_cc_score"
360379
t.index ["match_id", "player_id"], name: "idx_player_stats_match_player_agg", comment: "Otimiza agregações de estatísticas (SUM kills/deaths/assists)"
380+
t.index ["match_id"], name: "idx_player_stats_match"
361381
t.index ["objectives_stolen"], name: "idx_pms_objectives_stolen", where: "(objectives_stolen > 0)"
362382
t.index ["player_id", "champion"], name: "idx_pms_player_champion"
363383
t.index ["player_id", "cs_per_min"], name: "idx_pms_player_cs_per_min"
@@ -426,6 +446,7 @@
426446
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"
427447
t.index ["organization_id", "last_sync_at"], name: "idx_players_org_last_sync"
428448
t.index ["organization_id", "role"], name: "index_players_on_org_and_role"
449+
t.index ["organization_id", "status"], name: "idx_players_org_status"
429450
t.index ["organization_id", "sync_status"], name: "idx_players_org_sync_status"
430451
t.index ["organization_id"], name: "index_players_on_organization_id"
431452
t.index ["player_access_enabled"], name: "index_players_on_player_access_enabled", comment: "Quick lookup for players with access enabled"
@@ -499,12 +520,15 @@
499520
t.jsonb "metadata", default: {}
500521
t.datetime "created_at", null: false
501522
t.datetime "updated_at", null: false
523+
t.uuid "scrim_id"
502524
t.index ["created_by_id"], name: "index_schedules_on_created_by_id"
503525
t.index ["event_type"], name: "index_schedules_on_event_type"
504526
t.index ["match_id"], name: "index_schedules_on_match_id"
505527
t.index ["organization_id", "event_type"], name: "idx_schedules_org_event_type"
506528
t.index ["organization_id", "start_time", "event_type"], name: "idx_schedules_org_time_type", comment: "Otimiza queries de próximos eventos"
529+
t.index ["organization_id", "start_time"], name: "idx_schedules_org_time"
507530
t.index ["organization_id"], name: "index_schedules_on_organization_id"
531+
t.index ["scrim_id"], name: "index_schedules_on_scrim_id"
508532
t.index ["start_time"], name: "index_schedules_on_start_time"
509533
t.index ["status"], name: "index_schedules_on_status"
510534
end
@@ -730,9 +754,11 @@
730754
t.datetime "last_login_at", precision: nil
731755
t.datetime "created_at", null: false
732756
t.datetime "updated_at", null: false
757+
t.string "supabase_uid"
733758
t.index ["email"], name: "index_users_on_email", unique: true
734759
t.index ["organization_id"], name: "index_users_on_organization_id"
735760
t.index ["role"], name: "index_users_on_role"
761+
t.index ["supabase_uid"], name: "index_users_on_supabase_uid"
736762
end
737763

738764
create_table "vod_reviews", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
@@ -805,6 +831,7 @@
805831
add_foreign_key "saved_builds", "users", column: "created_by_id"
806832
add_foreign_key "schedules", "matches"
807833
add_foreign_key "schedules", "organizations"
834+
add_foreign_key "schedules", "scrims", on_delete: :cascade
808835
add_foreign_key "schedules", "users", column: "created_by_id"
809836
add_foreign_key "scouting_watchlists", "organizations"
810837
add_foreign_key "scouting_watchlists", "scouting_targets"

0 commit comments

Comments
 (0)