完善活动运营域与联调标准化
This commit is contained in:
@@ -13,6 +13,13 @@ type DemoBootstrapSummary struct {
|
||||
SourceID string `json:"sourceId"`
|
||||
BuildID string `json:"buildId"`
|
||||
CardID string `json:"cardId"`
|
||||
PlaceID string `json:"placeId"`
|
||||
MapAssetID string `json:"mapAssetId"`
|
||||
TileReleaseID string `json:"tileReleaseId"`
|
||||
CourseSourceID string `json:"courseSourceId"`
|
||||
CourseSetID string `json:"courseSetId"`
|
||||
CourseVariantID string `json:"courseVariantId"`
|
||||
RuntimeBindingID string `json:"runtimeBindingId"`
|
||||
VariantManualEventID string `json:"variantManualEventId"`
|
||||
VariantManualRelease string `json:"variantManualReleaseId"`
|
||||
VariantManualCardID string `json:"variantManualCardId"`
|
||||
@@ -311,6 +318,156 @@ func (s *Store) EnsureDemoData(ctx context.Context) (*DemoBootstrapSummary, erro
|
||||
return nil, fmt.Errorf("ensure demo card: %w", err)
|
||||
}
|
||||
|
||||
var placeID, placePublicID string
|
||||
if err := tx.QueryRow(ctx, `
|
||||
INSERT INTO places (
|
||||
place_public_id, code, name, region, status
|
||||
)
|
||||
VALUES (
|
||||
'place_demo_001', 'place-demo-001', 'Demo Park', 'Shanghai', 'active'
|
||||
)
|
||||
ON CONFLICT (code) DO UPDATE SET
|
||||
name = EXCLUDED.name,
|
||||
region = EXCLUDED.region,
|
||||
status = EXCLUDED.status
|
||||
RETURNING id, place_public_id
|
||||
`).Scan(&placeID, &placePublicID); err != nil {
|
||||
return nil, fmt.Errorf("ensure demo place: %w", err)
|
||||
}
|
||||
|
||||
var mapAssetID, mapAssetPublicID string
|
||||
if err := tx.QueryRow(ctx, `
|
||||
INSERT INTO map_assets (
|
||||
map_asset_public_id, place_id, code, name, map_type, status
|
||||
)
|
||||
VALUES (
|
||||
'mapasset_demo_001', $1, 'mapasset-demo-001', 'Demo Asset Map', 'standard', 'active'
|
||||
)
|
||||
ON CONFLICT (code) DO UPDATE SET
|
||||
place_id = EXCLUDED.place_id,
|
||||
name = EXCLUDED.name,
|
||||
map_type = EXCLUDED.map_type,
|
||||
status = EXCLUDED.status
|
||||
RETURNING id, map_asset_public_id
|
||||
`, placeID).Scan(&mapAssetID, &mapAssetPublicID); err != nil {
|
||||
return nil, fmt.Errorf("ensure demo map asset: %w", err)
|
||||
}
|
||||
|
||||
var tileReleaseID, tileReleasePublicID string
|
||||
if err := tx.QueryRow(ctx, `
|
||||
INSERT INTO tile_releases (
|
||||
tile_release_public_id, map_asset_id, version_code, status, tile_base_url, meta_url, published_at
|
||||
)
|
||||
VALUES (
|
||||
'tile_demo_001', $1, 'v2026-04-03', 'published',
|
||||
'https://example.com/tiles/demo/', 'https://example.com/tiles/demo/meta.json', NOW()
|
||||
)
|
||||
ON CONFLICT (map_asset_id, version_code) DO UPDATE SET
|
||||
status = EXCLUDED.status,
|
||||
tile_base_url = EXCLUDED.tile_base_url,
|
||||
meta_url = EXCLUDED.meta_url,
|
||||
published_at = EXCLUDED.published_at
|
||||
RETURNING id, tile_release_public_id
|
||||
`, mapAssetID).Scan(&tileReleaseID, &tileReleasePublicID); err != nil {
|
||||
return nil, fmt.Errorf("ensure demo tile release: %w", err)
|
||||
}
|
||||
|
||||
if _, err := tx.Exec(ctx, `
|
||||
UPDATE map_assets
|
||||
SET current_tile_release_id = $2
|
||||
WHERE id = $1
|
||||
`, mapAssetID, tileReleaseID); err != nil {
|
||||
return nil, fmt.Errorf("attach demo tile release: %w", err)
|
||||
}
|
||||
|
||||
var courseSourceID, courseSourcePublicID string
|
||||
if err := tx.QueryRow(ctx, `
|
||||
INSERT INTO course_sources (
|
||||
course_source_public_id, source_type, file_url, import_status
|
||||
)
|
||||
VALUES (
|
||||
'csource_demo_001', 'kml', 'https://example.com/course/demo.kml', 'imported'
|
||||
)
|
||||
ON CONFLICT (course_source_public_id) DO UPDATE SET
|
||||
source_type = EXCLUDED.source_type,
|
||||
file_url = EXCLUDED.file_url,
|
||||
import_status = EXCLUDED.import_status
|
||||
RETURNING id, course_source_public_id
|
||||
`).Scan(&courseSourceID, &courseSourcePublicID); err != nil {
|
||||
return nil, fmt.Errorf("ensure demo course source: %w", err)
|
||||
}
|
||||
|
||||
var courseSetID, courseSetPublicID string
|
||||
if err := tx.QueryRow(ctx, `
|
||||
INSERT INTO course_sets (
|
||||
course_set_public_id, place_id, map_asset_id, code, mode, name, status
|
||||
)
|
||||
VALUES (
|
||||
'cset_demo_001', $1, $2, 'cset-demo-001', 'classic-sequential', 'Demo Course Set', 'active'
|
||||
)
|
||||
ON CONFLICT (code) DO UPDATE SET
|
||||
place_id = EXCLUDED.place_id,
|
||||
map_asset_id = EXCLUDED.map_asset_id,
|
||||
mode = EXCLUDED.mode,
|
||||
name = EXCLUDED.name,
|
||||
status = EXCLUDED.status
|
||||
RETURNING id, course_set_public_id
|
||||
`, placeID, mapAssetID).Scan(&courseSetID, &courseSetPublicID); err != nil {
|
||||
return nil, fmt.Errorf("ensure demo course set: %w", err)
|
||||
}
|
||||
|
||||
var courseVariantID, courseVariantPublicID string
|
||||
if err := tx.QueryRow(ctx, `
|
||||
INSERT INTO course_variants (
|
||||
course_variant_public_id, course_set_id, source_id, name, route_code, mode, control_count, status, is_default
|
||||
)
|
||||
VALUES (
|
||||
'cvariant_demo_001', $1, $2, 'Demo Variant A', 'route-demo-a', 'classic-sequential', 8, 'active', true
|
||||
)
|
||||
ON CONFLICT (course_variant_public_id) DO UPDATE SET
|
||||
course_set_id = EXCLUDED.course_set_id,
|
||||
source_id = EXCLUDED.source_id,
|
||||
name = EXCLUDED.name,
|
||||
route_code = EXCLUDED.route_code,
|
||||
mode = EXCLUDED.mode,
|
||||
control_count = EXCLUDED.control_count,
|
||||
status = EXCLUDED.status,
|
||||
is_default = EXCLUDED.is_default
|
||||
RETURNING id, course_variant_public_id
|
||||
`, courseSetID, courseSourceID).Scan(&courseVariantID, &courseVariantPublicID); err != nil {
|
||||
return nil, fmt.Errorf("ensure demo course variant: %w", err)
|
||||
}
|
||||
|
||||
if _, err := tx.Exec(ctx, `
|
||||
UPDATE course_sets
|
||||
SET current_variant_id = $2
|
||||
WHERE id = $1
|
||||
`, courseSetID, courseVariantID); err != nil {
|
||||
return nil, fmt.Errorf("attach demo course variant: %w", err)
|
||||
}
|
||||
|
||||
var runtimeBindingID, runtimeBindingPublicID string
|
||||
if err := tx.QueryRow(ctx, `
|
||||
INSERT INTO map_runtime_bindings (
|
||||
runtime_binding_public_id, event_id, place_id, map_asset_id, tile_release_id, course_set_id, course_variant_id, status, notes
|
||||
)
|
||||
VALUES (
|
||||
'runtime_demo_001', $1, $2, $3, $4, $5, $6, 'active', 'demo runtime binding'
|
||||
)
|
||||
ON CONFLICT (runtime_binding_public_id) DO UPDATE SET
|
||||
event_id = EXCLUDED.event_id,
|
||||
place_id = EXCLUDED.place_id,
|
||||
map_asset_id = EXCLUDED.map_asset_id,
|
||||
tile_release_id = EXCLUDED.tile_release_id,
|
||||
course_set_id = EXCLUDED.course_set_id,
|
||||
course_variant_id = EXCLUDED.course_variant_id,
|
||||
status = EXCLUDED.status,
|
||||
notes = EXCLUDED.notes
|
||||
RETURNING id, runtime_binding_public_id
|
||||
`, eventID, placeID, mapAssetID, tileReleaseID, courseSetID, courseVariantID).Scan(&runtimeBindingID, &runtimeBindingPublicID); err != nil {
|
||||
return nil, fmt.Errorf("ensure demo runtime binding: %w", err)
|
||||
}
|
||||
|
||||
var manualEventID string
|
||||
if err := tx.QueryRow(ctx, `
|
||||
INSERT INTO events (
|
||||
@@ -452,6 +609,13 @@ func (s *Store) EnsureDemoData(ctx context.Context) (*DemoBootstrapSummary, erro
|
||||
SourceID: source.ID,
|
||||
BuildID: build.ID,
|
||||
CardID: cardPublicID,
|
||||
PlaceID: placePublicID,
|
||||
MapAssetID: mapAssetPublicID,
|
||||
TileReleaseID: tileReleasePublicID,
|
||||
CourseSourceID: courseSourcePublicID,
|
||||
CourseSetID: courseSetPublicID,
|
||||
CourseVariantID: courseVariantPublicID,
|
||||
RuntimeBindingID: runtimeBindingPublicID,
|
||||
VariantManualEventID: "evt_demo_variant_manual_001",
|
||||
VariantManualRelease: manualReleaseRow.PublicID,
|
||||
VariantManualCardID: manualCardPublicID,
|
||||
|
||||
Reference in New Issue
Block a user