feat(model): 同步 vivid 最新变更 — 去模型开关,配价即上架
对齐 vivid a338edb / 7fb5c57 / 4f454b6: - model_configs.enabled 列删除:上架唯一门槛 = 绑定了启用渠道 + 全部档位 有价(视频另需时长有价)。/v1/models、/api/models、video-presets、 managed-models 全部改按 sellable 透出 - 保存渠道即全量同步上游模型(消失解绑/孤儿删除/失败告警不删库) - v1 job 持久化 upstream jobId,重启后维护循环按 jobId 续等不丢单 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -80,6 +80,15 @@ func (r *ChannelRepository) Unbind(ctx context.Context, channelID, modelID strin
|
||||
return r.db.WithContext(ctx).Delete(&model.ChannelModel{}, "channel_id = ? AND model_id = ?", channelID, modelID).Error
|
||||
}
|
||||
|
||||
// UnbindExcept removes every binding of a channel whose upstream model name is
|
||||
// NOT in the keep list (upstream_model, falling back to model_id for legacy
|
||||
// rows) — the "true sync" counterpart used after saving a channel.
|
||||
func (r *ChannelRepository) UnbindExcept(ctx context.Context, channelID string, upstreamIDs []string) error {
|
||||
return r.db.WithContext(ctx).
|
||||
Where("channel_id = ? AND NOT (COALESCE(NULLIF(upstream_model, ''), model_id) IN ?)", channelID, upstreamIDs).
|
||||
Delete(&model.ChannelModel{}).Error
|
||||
}
|
||||
|
||||
func (r *ChannelRepository) DeleteBindingsByChannel(ctx context.Context, channelID string) error {
|
||||
return r.db.WithContext(ctx).Delete(&model.ChannelModel{}, "channel_id = ?", channelID).Error
|
||||
}
|
||||
@@ -158,6 +167,22 @@ func (r *ChannelRepository) UpstreamModelMap(ctx context.Context, channelID stri
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// RoutableModelIDs returns the set of local model ids bound to at least one
|
||||
// ENABLED channel — the "can actually dispatch" set behind the sellable flag.
|
||||
func (r *ChannelRepository) RoutableModelIDs(ctx context.Context) (map[string]struct{}, error) {
|
||||
var ids []string
|
||||
err := r.db.WithContext(ctx).
|
||||
Table("channel_models").
|
||||
Select("DISTINCT channel_models.model_id").
|
||||
Joins("JOIN channels ON channels.id = channel_models.channel_id AND channels.enabled = ?", true).
|
||||
Scan(&ids).Error
|
||||
out := make(map[string]struct{}, len(ids))
|
||||
for _, id := range ids {
|
||||
out[id] = struct{}{}
|
||||
}
|
||||
return out, err
|
||||
}
|
||||
|
||||
// ChannelIDsByModel lists channel ids bound to a model (any enabled state).
|
||||
func (r *ChannelRepository) ChannelIDsByModel(ctx context.Context, modelID string) ([]string, error) {
|
||||
var ids []string
|
||||
|
||||
Reference in New Issue
Block a user