ReloadConfigDatabases swaps to conf while rediscoving and rebuilding only the named database contexts. It is intended for service-owned config commits that have already proved the change is database-source scoped. Use Reload for global config, auth, relationship, resolver, API, filesystem, or workfl
(conf *Config, databases []string, opts ...Option)
| 1009 | // global config, auth, relationship, resolver, API, filesystem, or workflow |
| 1010 | // changes. |
| 1011 | func (g *GraphJin) ReloadConfigDatabases(conf *Config, databases []string, opts ...Option) error { |
| 1012 | if conf == nil { |
| 1013 | return fmt.Errorf("config is required") |
| 1014 | } |
| 1015 | reloadSet := make(map[string]struct{}, len(databases)) |
| 1016 | for _, name := range databases { |
| 1017 | name = strings.TrimSpace(name) |
| 1018 | if name != "" { |
| 1019 | reloadSet[name] = struct{}{} |
| 1020 | } |
| 1021 | } |
| 1022 | if len(reloadSet) == 0 { |
| 1023 | return fmt.Errorf("at least one database name is required") |
| 1024 | } |
| 1025 | |
| 1026 | g.reloadMu.Lock() |
| 1027 | defer g.reloadMu.Unlock() |
| 1028 | |
| 1029 | base, err := g.getEngine() |
| 1030 | if err != nil { |
| 1031 | return err |
| 1032 | } |
| 1033 | if len(opts) == 0 { |
| 1034 | opts = base.opts |
| 1035 | } |
| 1036 | if err := g.newGraphJinReloadingConfigDatabases(base, conf, reloadSet, opts...); err != nil { |
| 1037 | return err |
| 1038 | } |
| 1039 | next, err := g.getEngine() |
| 1040 | if err != nil { |
| 1041 | return err |
| 1042 | } |
| 1043 | names := make([]string, 0, len(reloadSet)) |
| 1044 | for name := range reloadSet { |
| 1045 | names = append(names, name) |
| 1046 | } |
| 1047 | sort.Strings(names) |
| 1048 | for _, name := range names { |
| 1049 | if ctx, ok := next.databases[name]; ok && ctx.dbinfo != nil { |
| 1050 | g.fireSchemaCallbacks(name, fmt.Sprintf("%x", ctx.dbinfo.Hash())) |
| 1051 | } |
| 1052 | } |
| 1053 | return nil |
| 1054 | } |
| 1055 | |
| 1056 | // ReloadWithDB redoes database discover with a new primary DB connection. |
| 1057 | func (g *GraphJin) ReloadWithDB(db *sql.DB) error { |
no test coverage detected