chore: add platform identity and platform_messages for multi-platform support (#23)
PR Checks / test-and-build (pull_request) Successful in 9m38s
PR Checks / test-and-build (pull_request) Successful in 9m38s
TDD cycle for issue #23: - RED: 7 migration smoke tests (file presence + schema expectations) - GREEN: V016 migration adding platform identity columns - GREEN: CreateSessionHandler updated with COALESCE fallbacks - GREEN: get_group_attendance_stats recreated for external_username - Bump version to 2.0.0 Changes: - V016__add_platform_identity.sql: - players: platform, external_user_id, external_username - game_groups: platform, external_group_id, external_channel_id - platform_messages table with cross-platform message tracking - Backfill all existing Telegram data into new columns - Recreate get_group_attendance_stats with COALESCE fallback - V012__add_attendance_stats.sql: use COALESCE(external_username, telegram_username) - CreateSessionHandler: dual-write to legacy and new identity columns - Add PlatformIdentityMigrationTests (7 smoke tests) - Version synced: Directory.Build.props, compose.yaml, deploy.yml, NavMenu.razor → 2.0.0 Legacy telegram_* columns preserved for backward compatibility. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -77,11 +77,14 @@ public sealed class CreateSessionHandler(
|
||||
{
|
||||
await connection.ExecuteAsync(
|
||||
"""
|
||||
INSERT INTO players (telegram_id, display_name, telegram_username)
|
||||
VALUES (@TgId, @Name, @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;
|
||||
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 { TgId = gmId, Name = gmName, Username = gmUsername },
|
||||
transaction);
|
||||
@@ -94,10 +97,10 @@ public sealed class CreateSessionHandler(
|
||||
FROM group_managers gm
|
||||
JOIN players p ON p.id = gm.player_id
|
||||
WHERE gm.group_id = g.id
|
||||
AND p.telegram_id = @GmId
|
||||
AND COALESCE(p.external_user_id, p.telegram_id::TEXT) = @GmId::TEXT
|
||||
) AS CanManage
|
||||
FROM game_groups g
|
||||
WHERE g.telegram_chat_id = @ChatId
|
||||
WHERE COALESCE(g.external_group_id, g.telegram_chat_id::TEXT) = @ChatId::TEXT
|
||||
""",
|
||||
new { ChatId = chatId, GmId = gmId },
|
||||
transaction);
|
||||
@@ -107,8 +110,8 @@ public sealed class CreateSessionHandler(
|
||||
{
|
||||
groupId = await connection.ExecuteScalarAsync<Guid>(
|
||||
"""
|
||||
INSERT INTO game_groups (telegram_chat_id, name, gm_telegram_id)
|
||||
VALUES (@ChatId, @ChatName, @GmId)
|
||||
INSERT INTO game_groups (telegram_chat_id, name, gm_telegram_id, platform, external_group_id)
|
||||
VALUES (@ChatId, @ChatName, @GmId, 'Telegram', @ChatId::TEXT)
|
||||
RETURNING id;
|
||||
""",
|
||||
new { ChatId = chatId, ChatName = chatTitle, GmId = gmId },
|
||||
@@ -119,7 +122,7 @@ public sealed class CreateSessionHandler(
|
||||
INSERT INTO group_managers (group_id, player_id, role)
|
||||
SELECT @GroupId, p.id, @OwnerRole
|
||||
FROM players p
|
||||
WHERE p.telegram_id = @GmId
|
||||
WHERE COALESCE(p.external_user_id, p.telegram_id::TEXT) = @GmId::TEXT
|
||||
ON CONFLICT (group_id, player_id) DO NOTHING
|
||||
""",
|
||||
new { GroupId = groupId, GmId = gmId, OwnerRole = GroupManagerRoleExtensions.OwnerValue },
|
||||
|
||||
Reference in New Issue
Block a user