Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 11b145a967 |
@@ -35,9 +35,14 @@ public sealed class JoinSessionHandler(
|
||||
{
|
||||
// 1. Убеждаемся, что игрок есть в базе
|
||||
var playerId = await connection.ExecuteScalarAsync<Guid>(
|
||||
@"INSERT INTO players (telegram_id, display_name, telegram_username)
|
||||
VALUES (@TgId, @Name, @Username)
|
||||
ON CONFLICT (telegram_id) DO UPDATE SET display_name = EXCLUDED.display_name, telegram_username = EXCLUDED.telegram_username
|
||||
@"INSERT INTO players (telegram_id, display_name, telegram_username, platform, external_user_id, external_username)
|
||||
VALUES (@TgId, @Name, @Username, 'Telegram', @TgId::TEXT, @Username)
|
||||
ON CONFLICT (telegram_id) DO UPDATE
|
||||
SET display_name = EXCLUDED.display_name,
|
||||
telegram_username = EXCLUDED.telegram_username,
|
||||
platform = COALESCE(players.platform, 'Telegram'),
|
||||
external_user_id = COALESCE(players.external_user_id, EXCLUDED.telegram_id::TEXT),
|
||||
external_username = COALESCE(players.external_username, EXCLUDED.telegram_username)
|
||||
RETURNING id;",
|
||||
new { TgId = command.TelegramUserId, Name = command.DisplayName, Username = command.TelegramUsername },
|
||||
transaction);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
-- Legacy telegram_* columns are retained for backward compatibility.
|
||||
-- =============================================================
|
||||
|
||||
-- ── Players: platform-agnostic identity ─────────────────────────
|
||||
-- -- Players: platform-agnostic identity
|
||||
ALTER TABLE players
|
||||
ADD COLUMN platform VARCHAR(50),
|
||||
ADD COLUMN external_user_id VARCHAR(255),
|
||||
@@ -15,7 +15,7 @@ CREATE UNIQUE INDEX ix_players_platform_external_user_id
|
||||
ON players (platform, external_user_id)
|
||||
WHERE platform IS NOT NULL AND external_user_id IS NOT NULL;
|
||||
|
||||
-- ── Game groups: platform-agnostic identity ─────────────────────
|
||||
-- -- Game groups: platform-agnostic identity
|
||||
ALTER TABLE game_groups
|
||||
ADD COLUMN platform VARCHAR(50),
|
||||
ADD COLUMN external_group_id VARCHAR(255),
|
||||
@@ -25,7 +25,7 @@ CREATE UNIQUE INDEX ix_game_groups_platform_external_group_id
|
||||
ON game_groups (platform, external_group_id)
|
||||
WHERE platform IS NOT NULL AND external_group_id IS NOT NULL;
|
||||
|
||||
-- ── Backfill existing Telegram data ─────────────────────────────
|
||||
-- -- Backfill existing Telegram data
|
||||
UPDATE players
|
||||
SET platform = 'Telegram',
|
||||
external_user_id = telegram_id::TEXT,
|
||||
@@ -37,7 +37,7 @@ UPDATE game_groups
|
||||
external_group_id = telegram_chat_id::TEXT
|
||||
WHERE platform IS NULL;
|
||||
|
||||
-- ── Platform messages: store per-platform message references ────
|
||||
-- -- Platform messages: store per-platform message references
|
||||
CREATE TABLE platform_messages (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
platform VARCHAR(50) NOT NULL,
|
||||
@@ -57,7 +57,7 @@ CREATE INDEX ix_platform_messages_session_id ON platform_messages(session_id);
|
||||
CREATE INDEX ix_platform_messages_platform_message
|
||||
ON platform_messages (platform, external_message_id);
|
||||
|
||||
-- ── Recreate attendance stats function for new columns (prod back-compat) ──
|
||||
-- -- Recreate attendance stats function for new columns (prod back-compat)
|
||||
CREATE OR REPLACE FUNCTION get_group_attendance_stats(p_group_id UUID)
|
||||
RETURNS TABLE (
|
||||
player_id UUID,
|
||||
|
||||
@@ -242,11 +242,14 @@ public sealed class SessionService(
|
||||
|
||||
await conn.ExecuteAsync(
|
||||
"""
|
||||
INSERT INTO players (telegram_id, display_name, telegram_username)
|
||||
VALUES (@TelegramId, @DisplayName, @TelegramUsername)
|
||||
INSERT INTO players (telegram_id, display_name, telegram_username, platform, external_user_id, external_username)
|
||||
VALUES (@TelegramId, @DisplayName, @TelegramUsername, 'Telegram', @TelegramId::TEXT, @TelegramUsername)
|
||||
ON CONFLICT (telegram_id) DO UPDATE
|
||||
SET display_name = EXCLUDED.display_name,
|
||||
telegram_username = EXCLUDED.telegram_username
|
||||
telegram_username = EXCLUDED.telegram_username,
|
||||
platform = COALESCE(players.platform, 'Telegram'),
|
||||
external_user_id = COALESCE(players.external_user_id, EXCLUDED.telegram_id::TEXT),
|
||||
external_username = COALESCE(players.external_username, EXCLUDED.telegram_username)
|
||||
""",
|
||||
new
|
||||
{
|
||||
|
||||
@@ -71,6 +71,26 @@ public sealed class PlatformIdentityMigrationTests
|
||||
Assert.Contains("external_group_id", createHandler, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task JoinSessionHandler_ShouldDualWritePlatformIdentity()
|
||||
{
|
||||
var handler = await ReadRepositoryFileAsync("src/GmRelay.Bot/Features/Sessions/CreateSession/JoinSessionHandler.cs");
|
||||
|
||||
Assert.Contains("external_user_id", handler, StringComparison.Ordinal);
|
||||
Assert.Contains("external_username", handler, StringComparison.Ordinal);
|
||||
Assert.Contains("platform", handler, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WebSessionService_ShouldDualWritePlatformIdentity()
|
||||
{
|
||||
var service = await ReadRepositoryFileAsync("src/GmRelay.Web/Services/SessionService.cs");
|
||||
|
||||
Assert.Contains("external_user_id", service, StringComparison.Ordinal);
|
||||
Assert.Contains("external_username", service, StringComparison.Ordinal);
|
||||
Assert.Contains("platform", service, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AttendanceStatsFunction_ShouldReferenceExternalUsername()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user