完善多赛道联调与全局产品架构
This commit is contained in:
@@ -6,13 +6,16 @@ import (
|
||||
)
|
||||
|
||||
type DemoBootstrapSummary struct {
|
||||
TenantCode string `json:"tenantCode"`
|
||||
ChannelCode string `json:"channelCode"`
|
||||
EventID string `json:"eventId"`
|
||||
ReleaseID string `json:"releaseId"`
|
||||
SourceID string `json:"sourceId"`
|
||||
BuildID string `json:"buildId"`
|
||||
CardID string `json:"cardId"`
|
||||
TenantCode string `json:"tenantCode"`
|
||||
ChannelCode string `json:"channelCode"`
|
||||
EventID string `json:"eventId"`
|
||||
ReleaseID string `json:"releaseId"`
|
||||
SourceID string `json:"sourceId"`
|
||||
BuildID string `json:"buildId"`
|
||||
CardID string `json:"cardId"`
|
||||
VariantManualEventID string `json:"variantManualEventId"`
|
||||
VariantManualRelease string `json:"variantManualReleaseId"`
|
||||
VariantManualCardID string `json:"variantManualCardId"`
|
||||
}
|
||||
|
||||
func (s *Store) EnsureDemoData(ctx context.Context) (*DemoBootstrapSummary, error) {
|
||||
@@ -88,7 +91,7 @@ func (s *Store) EnsureDemoData(ctx context.Context) (*DemoBootstrapSummary, erro
|
||||
$1,
|
||||
1,
|
||||
'Demo Config v1',
|
||||
'https://oss-mbh5.colormaprun.com/gotomars/event/classic-sequential.json',
|
||||
'https://oss-mbh5.colormaprun.com/gotomars/event/releases/evt_demo_001/rel_e7dd953743c5c0d2/manifest.json',
|
||||
'demo-checksum-001',
|
||||
'route-demo-001',
|
||||
'published'
|
||||
@@ -224,7 +227,7 @@ func (s *Store) EnsureDemoData(ctx context.Context) (*DemoBootstrapSummary, erro
|
||||
EventReleaseID: releaseRow.ID,
|
||||
AssetType: "manifest",
|
||||
AssetKey: "manifest",
|
||||
AssetURL: "https://oss-mbh5.colormaprun.com/gotomars/event/classic-sequential.json",
|
||||
AssetURL: "https://oss-mbh5.colormaprun.com/gotomars/event/releases/evt_demo_001/rel_e7dd953743c5c0d2/manifest.json",
|
||||
Checksum: &manifestChecksum,
|
||||
Meta: map[string]any{"source": "release-manifest"},
|
||||
},
|
||||
@@ -308,17 +311,149 @@ func (s *Store) EnsureDemoData(ctx context.Context) (*DemoBootstrapSummary, erro
|
||||
return nil, fmt.Errorf("ensure demo card: %w", err)
|
||||
}
|
||||
|
||||
var manualEventID string
|
||||
if err := tx.QueryRow(ctx, `
|
||||
INSERT INTO events (
|
||||
tenant_id, event_public_id, slug, display_name, summary, status
|
||||
)
|
||||
VALUES ($1, 'evt_demo_variant_manual_001', 'demo-variant-manual-run', 'Demo Variant Manual Run', 'Manual 多赛道联调活动', 'active')
|
||||
ON CONFLICT (event_public_id) DO UPDATE SET
|
||||
tenant_id = EXCLUDED.tenant_id,
|
||||
slug = EXCLUDED.slug,
|
||||
display_name = EXCLUDED.display_name,
|
||||
summary = EXCLUDED.summary,
|
||||
status = EXCLUDED.status
|
||||
RETURNING id
|
||||
`, tenantID).Scan(&manualEventID); err != nil {
|
||||
return nil, fmt.Errorf("ensure variant manual demo event: %w", err)
|
||||
}
|
||||
|
||||
var manualReleaseRow struct {
|
||||
ID string
|
||||
PublicID string
|
||||
}
|
||||
if err := tx.QueryRow(ctx, `
|
||||
INSERT INTO event_releases (
|
||||
release_public_id,
|
||||
event_id,
|
||||
release_no,
|
||||
config_label,
|
||||
manifest_url,
|
||||
manifest_checksum_sha256,
|
||||
route_code,
|
||||
status,
|
||||
payload_jsonb
|
||||
)
|
||||
VALUES (
|
||||
'rel_demo_variant_manual_001',
|
||||
$1,
|
||||
1,
|
||||
'Demo Variant Manual Config v1',
|
||||
'https://oss-mbh5.colormaprun.com/gotomars/event/releases/evt_demo_001/rel_e7dd953743c5c0d2/manifest.json',
|
||||
'demo-variant-checksum-001',
|
||||
'route-variant-a',
|
||||
'published',
|
||||
$2::jsonb
|
||||
)
|
||||
ON CONFLICT (release_public_id) DO UPDATE SET
|
||||
event_id = EXCLUDED.event_id,
|
||||
config_label = EXCLUDED.config_label,
|
||||
manifest_url = EXCLUDED.manifest_url,
|
||||
manifest_checksum_sha256 = EXCLUDED.manifest_checksum_sha256,
|
||||
route_code = EXCLUDED.route_code,
|
||||
status = EXCLUDED.status,
|
||||
payload_jsonb = EXCLUDED.payload_jsonb
|
||||
RETURNING id, release_public_id
|
||||
`, manualEventID, `{
|
||||
"play": {
|
||||
"assignmentMode": "manual",
|
||||
"courseVariants": [
|
||||
{
|
||||
"id": "variant_a",
|
||||
"name": "A 线",
|
||||
"description": "短线体验版",
|
||||
"routeCode": "route-variant-a",
|
||||
"selectable": true
|
||||
},
|
||||
{
|
||||
"id": "variant_b",
|
||||
"name": "B 线",
|
||||
"description": "长线挑战版",
|
||||
"routeCode": "route-variant-b",
|
||||
"selectable": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}`).Scan(&manualReleaseRow.ID, &manualReleaseRow.PublicID); err != nil {
|
||||
return nil, fmt.Errorf("ensure variant manual demo release: %w", err)
|
||||
}
|
||||
|
||||
if _, err := tx.Exec(ctx, `
|
||||
UPDATE events
|
||||
SET current_release_id = $2
|
||||
WHERE id = $1
|
||||
`, manualEventID, manualReleaseRow.ID); err != nil {
|
||||
return nil, fmt.Errorf("attach variant manual demo release: %w", err)
|
||||
}
|
||||
|
||||
var manualCardPublicID string
|
||||
if err := tx.QueryRow(ctx, `
|
||||
INSERT INTO cards (
|
||||
card_public_id,
|
||||
tenant_id,
|
||||
entry_channel_id,
|
||||
card_type,
|
||||
title,
|
||||
subtitle,
|
||||
cover_url,
|
||||
event_id,
|
||||
display_slot,
|
||||
display_priority,
|
||||
status
|
||||
)
|
||||
VALUES (
|
||||
'card_demo_variant_manual_001',
|
||||
$1,
|
||||
$2,
|
||||
'event',
|
||||
'Demo Variant Manual Run',
|
||||
'多赛道手动选择联调',
|
||||
'https://oss-mbh5.colormaprun.com/gotomars/assets/demo-cover.jpg',
|
||||
$3,
|
||||
'home_primary',
|
||||
95,
|
||||
'active'
|
||||
)
|
||||
ON CONFLICT (card_public_id) DO UPDATE SET
|
||||
tenant_id = EXCLUDED.tenant_id,
|
||||
entry_channel_id = EXCLUDED.entry_channel_id,
|
||||
card_type = EXCLUDED.card_type,
|
||||
title = EXCLUDED.title,
|
||||
subtitle = EXCLUDED.subtitle,
|
||||
cover_url = EXCLUDED.cover_url,
|
||||
event_id = EXCLUDED.event_id,
|
||||
display_slot = EXCLUDED.display_slot,
|
||||
display_priority = EXCLUDED.display_priority,
|
||||
status = EXCLUDED.status
|
||||
RETURNING card_public_id
|
||||
`, tenantID, channelID, manualEventID).Scan(&manualCardPublicID); err != nil {
|
||||
return nil, fmt.Errorf("ensure variant manual demo card: %w", err)
|
||||
}
|
||||
|
||||
if err := tx.Commit(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &DemoBootstrapSummary{
|
||||
TenantCode: "tenant_demo",
|
||||
ChannelCode: "mini-demo",
|
||||
EventID: "evt_demo_001",
|
||||
ReleaseID: releaseRow.PublicID,
|
||||
SourceID: source.ID,
|
||||
BuildID: build.ID,
|
||||
CardID: cardPublicID,
|
||||
TenantCode: "tenant_demo",
|
||||
ChannelCode: "mini-demo",
|
||||
EventID: "evt_demo_001",
|
||||
ReleaseID: releaseRow.PublicID,
|
||||
SourceID: source.ID,
|
||||
BuildID: build.ID,
|
||||
CardID: cardPublicID,
|
||||
VariantManualEventID: "evt_demo_variant_manual_001",
|
||||
VariantManualRelease: manualReleaseRow.PublicID,
|
||||
VariantManualCardID: manualCardPublicID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ type Event struct {
|
||||
ManifestURL *string
|
||||
ManifestChecksum *string
|
||||
RouteCode *string
|
||||
ReleasePayloadJSON *string
|
||||
}
|
||||
|
||||
type EventRelease struct {
|
||||
@@ -45,6 +46,9 @@ type CreateGameSessionParams struct {
|
||||
EventReleaseID string
|
||||
DeviceKey string
|
||||
ClientType string
|
||||
AssignmentMode *string
|
||||
VariantID *string
|
||||
VariantName *string
|
||||
RouteCode *string
|
||||
SessionTokenHash string
|
||||
SessionTokenExpiresAt time.Time
|
||||
@@ -58,6 +62,9 @@ type GameSession struct {
|
||||
EventReleaseID string
|
||||
DeviceKey string
|
||||
ClientType string
|
||||
AssignmentMode *string
|
||||
VariantID *string
|
||||
VariantName *string
|
||||
RouteCode *string
|
||||
Status string
|
||||
SessionTokenExpiresAt time.Time
|
||||
@@ -77,7 +84,8 @@ func (s *Store) GetEventByPublicID(ctx context.Context, eventPublicID string) (*
|
||||
er.config_label,
|
||||
er.manifest_url,
|
||||
er.manifest_checksum_sha256,
|
||||
er.route_code
|
||||
er.route_code,
|
||||
er.payload_jsonb::text
|
||||
FROM events e
|
||||
LEFT JOIN event_releases er ON er.id = e.current_release_id
|
||||
WHERE e.event_public_id = $1
|
||||
@@ -98,6 +106,7 @@ func (s *Store) GetEventByPublicID(ctx context.Context, eventPublicID string) (*
|
||||
&event.ManifestURL,
|
||||
&event.ManifestChecksum,
|
||||
&event.RouteCode,
|
||||
&event.ReleasePayloadJSON,
|
||||
)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, nil
|
||||
@@ -122,7 +131,8 @@ func (s *Store) GetEventByID(ctx context.Context, eventID string) (*Event, error
|
||||
er.config_label,
|
||||
er.manifest_url,
|
||||
er.manifest_checksum_sha256,
|
||||
er.route_code
|
||||
er.route_code,
|
||||
er.payload_jsonb::text
|
||||
FROM events e
|
||||
LEFT JOIN event_releases er ON er.id = e.current_release_id
|
||||
WHERE e.id = $1
|
||||
@@ -143,6 +153,7 @@ func (s *Store) GetEventByID(ctx context.Context, eventID string) (*Event, error
|
||||
&event.ManifestURL,
|
||||
&event.ManifestChecksum,
|
||||
&event.RouteCode,
|
||||
&event.ReleasePayloadJSON,
|
||||
)
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, nil
|
||||
@@ -235,13 +246,16 @@ func (s *Store) CreateGameSession(ctx context.Context, tx Tx, params CreateGameS
|
||||
event_release_id,
|
||||
device_key,
|
||||
client_type,
|
||||
assignment_mode,
|
||||
variant_id,
|
||||
variant_name,
|
||||
route_code,
|
||||
session_token_hash,
|
||||
session_token_expires_at
|
||||
)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
||||
RETURNING id, session_public_id, user_id, event_id, event_release_id, device_key, client_type, route_code, status, session_token_expires_at
|
||||
`, params.SessionPublicID, params.UserID, params.EventID, params.EventReleaseID, params.DeviceKey, params.ClientType, params.RouteCode, params.SessionTokenHash, params.SessionTokenExpiresAt)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
|
||||
RETURNING id, session_public_id, user_id, event_id, event_release_id, device_key, client_type, assignment_mode, variant_id, variant_name, route_code, status, session_token_expires_at
|
||||
`, params.SessionPublicID, params.UserID, params.EventID, params.EventReleaseID, params.DeviceKey, params.ClientType, params.AssignmentMode, params.VariantID, params.VariantName, params.RouteCode, params.SessionTokenHash, params.SessionTokenExpiresAt)
|
||||
|
||||
var session GameSession
|
||||
err := row.Scan(
|
||||
@@ -252,6 +266,9 @@ func (s *Store) CreateGameSession(ctx context.Context, tx Tx, params CreateGameS
|
||||
&session.EventReleaseID,
|
||||
&session.DeviceKey,
|
||||
&session.ClientType,
|
||||
&session.AssignmentMode,
|
||||
&session.VariantID,
|
||||
&session.VariantName,
|
||||
&session.RouteCode,
|
||||
&session.Status,
|
||||
&session.SessionTokenExpiresAt,
|
||||
|
||||
@@ -101,6 +101,9 @@ func (s *Store) GetSessionResultByPublicID(ctx context.Context, sessionPublicID
|
||||
er.manifest_checksum_sha256,
|
||||
gs.device_key,
|
||||
gs.client_type,
|
||||
gs.assignment_mode,
|
||||
gs.variant_id,
|
||||
gs.variant_name,
|
||||
gs.route_code,
|
||||
gs.status,
|
||||
gs.session_token_hash,
|
||||
@@ -149,6 +152,9 @@ func (s *Store) ListSessionResultsByUserID(ctx context.Context, userID string, l
|
||||
er.manifest_checksum_sha256,
|
||||
gs.device_key,
|
||||
gs.client_type,
|
||||
gs.assignment_mode,
|
||||
gs.variant_id,
|
||||
gs.variant_name,
|
||||
gs.route_code,
|
||||
gs.status,
|
||||
gs.session_token_hash,
|
||||
@@ -244,6 +250,9 @@ func scanSessionResultRecord(row pgx.Row) (*SessionResultRecord, error) {
|
||||
&record.ManifestChecksum,
|
||||
&record.DeviceKey,
|
||||
&record.ClientType,
|
||||
&record.AssignmentMode,
|
||||
&record.VariantID,
|
||||
&record.VariantName,
|
||||
&record.RouteCode,
|
||||
&record.Status,
|
||||
&record.SessionTokenHash,
|
||||
@@ -317,6 +326,9 @@ func scanSessionResultRecordFromRows(rows pgx.Rows) (*SessionResultRecord, error
|
||||
&record.ManifestChecksum,
|
||||
&record.DeviceKey,
|
||||
&record.ClientType,
|
||||
&record.AssignmentMode,
|
||||
&record.VariantID,
|
||||
&record.VariantName,
|
||||
&record.RouteCode,
|
||||
&record.Status,
|
||||
&record.SessionTokenHash,
|
||||
|
||||
@@ -21,6 +21,9 @@ type Session struct {
|
||||
ManifestChecksum *string
|
||||
DeviceKey string
|
||||
ClientType string
|
||||
AssignmentMode *string
|
||||
VariantID *string
|
||||
VariantName *string
|
||||
RouteCode *string
|
||||
Status string
|
||||
SessionTokenHash string
|
||||
@@ -51,6 +54,9 @@ func (s *Store) GetSessionByPublicID(ctx context.Context, sessionPublicID string
|
||||
er.manifest_checksum_sha256,
|
||||
gs.device_key,
|
||||
gs.client_type,
|
||||
gs.assignment_mode,
|
||||
gs.variant_id,
|
||||
gs.variant_name,
|
||||
gs.route_code,
|
||||
gs.status,
|
||||
gs.session_token_hash,
|
||||
@@ -83,6 +89,9 @@ func (s *Store) GetSessionByPublicIDForUpdate(ctx context.Context, tx Tx, sessio
|
||||
er.manifest_checksum_sha256,
|
||||
gs.device_key,
|
||||
gs.client_type,
|
||||
gs.assignment_mode,
|
||||
gs.variant_id,
|
||||
gs.variant_name,
|
||||
gs.route_code,
|
||||
gs.status,
|
||||
gs.session_token_hash,
|
||||
@@ -119,6 +128,9 @@ func (s *Store) ListSessionsByUserID(ctx context.Context, userID string, limit i
|
||||
er.manifest_checksum_sha256,
|
||||
gs.device_key,
|
||||
gs.client_type,
|
||||
gs.assignment_mode,
|
||||
gs.variant_id,
|
||||
gs.variant_name,
|
||||
gs.route_code,
|
||||
gs.status,
|
||||
gs.session_token_hash,
|
||||
@@ -172,6 +184,9 @@ func (s *Store) ListSessionsByUserAndEvent(ctx context.Context, userID, eventID
|
||||
er.manifest_checksum_sha256,
|
||||
gs.device_key,
|
||||
gs.client_type,
|
||||
gs.assignment_mode,
|
||||
gs.variant_id,
|
||||
gs.variant_name,
|
||||
gs.route_code,
|
||||
gs.status,
|
||||
gs.session_token_hash,
|
||||
@@ -249,6 +264,9 @@ func scanSession(row pgx.Row) (*Session, error) {
|
||||
&session.ManifestChecksum,
|
||||
&session.DeviceKey,
|
||||
&session.ClientType,
|
||||
&session.AssignmentMode,
|
||||
&session.VariantID,
|
||||
&session.VariantName,
|
||||
&session.RouteCode,
|
||||
&session.Status,
|
||||
&session.SessionTokenHash,
|
||||
@@ -282,6 +300,9 @@ func scanSessionFromRows(rows pgx.Rows) (*Session, error) {
|
||||
&session.ManifestChecksum,
|
||||
&session.DeviceKey,
|
||||
&session.ClientType,
|
||||
&session.AssignmentMode,
|
||||
&session.VariantID,
|
||||
&session.VariantName,
|
||||
&session.RouteCode,
|
||||
&session.Status,
|
||||
&session.SessionTokenHash,
|
||||
|
||||
Reference in New Issue
Block a user